why n/2^k is equated to 1 ???
i.e. why n/2^k =1 ???
Binary search implementation and complexity
@visheshg2k As you know that in binary search the search interval is repeatedly divided into half. The lower limit of the search interval can be one (when we will have one element)
Considering there are k steps/iteration. So for the 1st step we say n/2, 2nd step n/4…and so on…This way for the Kth step it is n/2^k
So we equate this n/2^k to 1 and get the time complexity as O(log n)
Hope this helps
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.