The binary search complexity for 10 elements is 0 (log 10) = 1, but 4 is required for comparison

The following set contains 10 items

{10, 20, 21, 22, 23, 40, 50, 56, 90, 100}

N = 10 O (log 10) = 1

if element 20 is to perform a search, it is necessary to perform 4 comparison operations (That is)

1-comparision  10
2-comparision 23 (since mid value of 10 elements)
3-comparision 21 (mid)
4-comparision 20

How does binary search have O (log N) complexity ?.

+4
source share
2 answers

The Big-oh designation does not care about constants. In fact, it does not care about anything other than the dominant term in the expression.

, 4 * log n , O (log n). f(n), O(f(n)).

, . :

log_a(x) = log_b(x) / log_b(a)
         = [1 / log_b(a)] * log_b(x)
           \____________/
          this is constant

.

: , 100 , <= 8 , 4 * log_10(100).

+5

. , log_2 , .

, , . , , , , , .

+1

All Articles