Fastest way to search for an element in unsorted array

后端 未结 10 1797
北恋
北恋 2020-12-14 08:13

I just bumped on to this question today and was trying for a solution that is better than O(N) but could not come up with one.

Searched through SO but couldn\'t find

10条回答
  •  我在风中等你
    2020-12-14 09:15

    It is possible to make your program run faster than O(n).

    You start off by sorting the array using the merge sort algorithm, then you use binary search to find the element. Both algoro have a running time of O(log_2(n)). Adding these two complexities together, you get 2*log_2(n), which is O(log_2(n)) with the witness C = 2.

提交回复
热议问题