Binary vs Linear searches for unsorted N elements

前端 未结 5 869
予麋鹿
予麋鹿 2021-01-19 00:44

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 sho

5条回答
  •  星月不相逢
    2021-01-19 00:57

    You should plot the complexities of both operations.

    Linear search: O(n)

    Sort and binary search: O(nlogn + logn)

    In the plot, you will see for which values of n it makes sense to choose the one approach over the other.

提交回复
热议问题