I have been told that the runtime complexity of the binary search algorithm is log2 n. But I have seen on google and some other sites that it is log n. Can someone please explain why is that. And just what does that "2" in the base do?
Asked
Active
Viewed 25 times
0
-
O(logn) and O(log2n) are the same big O order. The reason for the base 2 in the log is because thats actually how long an average find takes, since we chop in half each time, the time taken depends on how many times its needs to be halved – pm100 Mar 06 '22 at 19:47