why binary search needs log n steps
Binary search steps
Hey @manish.bharadwajsbh
In Binary Search we first find mid and then after comparison we either discard first half or second half of array
So lets assume we start from array of size n
then
n -> n/2 -> n/4 -> … ->1
Now assume it took k steps to reach 1 i.e worst case
then
n/2^k == 1
=> n== 2^k
=> logn=k
hence Binary search take logn time in worst case
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.