Consider the following segment of C-code:
int j, n;
j = 1;
while (j <= n)
j = j*2;
The number of comparisons made in the execution of the loop for any n > 0 is: Base of Log is 2 in all options.
CEIL(logn) + 2
n
CEIL(logn)
FLOOR(logn) + 2
This question is part of this quiz :
Top MCQs on Complexity Analysis of Algorithms with Answers,GATE-CS-2007,Loops & Conditionals GATE CS PYQ Quiz