I'm getting answer floor $(log_ 2 n) +2$ ? I m wrong or what is right answer. This is GATE exam question.
What is number of comparision here?
0
$\begingroup$
asymptotics
1 Answers
0
You seem to be correct. There is an error in the question. If $2^k \leq n < 2^{k+1}$, then the loop is executed precisely $k + 1$ times, which gives $k + 2$ comparisons -- one for each execution and then once when the program exits the loop.
