0
$\begingroup$

enter image description here

I'm getting answer floor $(log_ 2 n) +2$ ? I m wrong or what is right answer. This is GATE exam question.

1 Answers 1

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.