二进制和线性搜索未排序的N个元素

编程入门 行业动态 更新时间:2024-10-15 12:31:52
本文介绍了二进制和线性搜索未排序的N个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我们应该使用快速排序时,我试图理解一个公式。例如,我们有一个包含 N = 1_000_000 元素的数组。如果只搜索一次 ,则应该使用简单的线性搜索,但是如果要搜索10次,则应该使用排序数组 O(n log n)。我该如何检测阈值以及何时应该使用输入数组大小以及之后使用二进制搜索的阈值?

I try to understand a formula when we should use quicksort. For instance, we have an array with N = 1_000_000 elements. If we will search only once, we should use a simple linear search, but if we'll do it 10 times we should use sort array O(n log n). How can I detect threshold when and for which size of input array should I use sorting and after that use binary search?

推荐答案

您想要解决可能被形容为粗糙的不平等现象

You want to solve inequality that rougly might be described as

t * n > C * n * log(n) + t * log(n)

其中 t 是检查次数,而 C 是用于排序实现的常数(应通过实验确定)。评估此常数时,可以用数值方法解决不等式(当然有不确定性)

where t is number of checks and C is some constant for sort implementation (should be determined experimentally). When you evaluate this constant, you can solve inequality numerically (with uncertainty, of course)

更多推荐

二进制和线性搜索未排序的N个元素

本文发布于:2023-11-29 11:16:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646245.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线性   元素

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!