为什么要使用二进制搜索,如果有三元搜索?要使

2023-09-10 23:26:54 作者:凡尘落素

我最近听说三元的搜索中,我们把数组分为3份,并进行比较。这里将有两个比较,但它减少了阵列到n / 3。为什么没有人用这个钱?

I recently heard about ternary search in which we divide an array into 3 parts and compare. Here there will be two comparisons but it reduces the array to n/3. Why don't people use this much?

推荐答案

其实,人们用k元树任意ķ。

Actually, people do use k-ary trees for arbitrary k.

这是,然而,一个折衷。

This is, however, a tradeoff.

要找到一个k元树中的元素,你周围的K * LN需要(N)/ LN(k)的操作(请记住变化基的配方)。你的K是较大的,则需要更多的整体运营。

To find an element in a k-ary tree, you need around k*ln(N)/ln(k) operations (remember the change-of-base formula). The larger your k is, the more overall operations you need.

对你说的话的合乎逻辑的延伸就是为什么没有人用N叉树N个数据元素?。其中,当然,将是一个数组。

The logical extension of what you are saying is "why don't people use an N-ary tree for N data elements?". Which, of course, would be an array.