简体   繁体   English

这是否意味着二进制搜索算法?

[英]Does this mean binary search algorithm?

I have to write a small Java program to find out how long does it take for performing a search algorithm. 我必须编写一个小型Java程序来找出执行搜索算法所需的时间。

The algorithm reads as: 该算法的内容为:

Assume you have a search algorithm which, at each level of recursion, excludes half of the data from consideration when searching for a specific data item. 假设您有一个搜索算法,该算法在每个递归级别上都在搜索特定数据项时不考虑一半的数据。 Search stops only when one data item is left. 仅当剩下一个数据项时搜索才会停止。

I would like to know your opinion about which search algorithm it is. 我想知道您对哪种搜索算法的看法。

sounds like a binary search or half-interval search provided that your collection or data is sorted, worst and everage case in O(log n) 听起来像是二进制搜索或半间隔搜索,但前提是您的集合或数据在O(log n)处于排序,最差和平均的情况

if you have to sort first, then the best algorithm will give you O(n log n), then plus O(log n) of binary search , overall it becomes O(n log n) 如果必须先进行排序,那么最佳算法将为您提供O(n log n),然后再加上O(log n)的二分查找,总的来说它将变为O(n log n)

If your data is sorted, then yes this is binary search algorithm. 如果您的数据已排序,则是的,这是二进制搜索算法。 This algorithm comes under "Divide and Conquer" strategy. 该算法属于“分而治之”策略。 In this, each time algorithm goes on dividing the data and half of the data is eliminated. 在这种情况下,每次算法都继续对数据进行分割,并且消除了一半的数据。 The basic assumption is data is sorted before applying the algorithm. 基本假设是在应用算法之前对数据进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM