为什么要使用二进制搜索,如果有三元搜索? [英] Why use binary search if there's ternary search?

查看:148
本文介绍了为什么要使用二进制搜索,如果有三元搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近听说三元的搜索中,我们把数组分为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.

这篇关于为什么要使用二进制搜索,如果有三元搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆