Can someone explain to me when it comes to the “Binary” search, we say that the runtime complexity is O (log n)? I searched it on google and got below
"The number of times you can halve your search space is the same as log 2 n ".
I know that we occupy half until we find the search key in the data structure, but why should we treat it as a log 2n? I understand that e x is exponential growth, so log 2n is binary decay. But I cannot interpret binary search in terms of understanding the definition of a logarithm.
thank
:
- m (.. m), ?
, 2 m right?
, n = 2 m , , m, m n :
n = 2 m
log 2 (n) = log 2 (2 m)
log 2 (n) = m: n = 2 m , m, , , log 2 (n).
: -
.
, "n" , . , "1".
n : a a a a.... ( n)
: a a a..a( n/2)
: a a a.. a ( n/(2 ^ 2));
onn.............. , k 1i.e n/(2 ^ k) 1 atlast
/(2 ^ ) = 1; 2 ^ = ; log 2
k = log n;
-, n n/2 n/4 n/8 , - log n