Find value of q for given pseudo code segment.

GATE algorithm question 

main() { p=0; 




q++ ;

 return (q)

find value of q

Akshay Saxena @akshay0612
9 Aug 2017 04:50 pm

If q=0 which is not mentioned , then I think it would be floor(logn).

Vivek Jain @vivekjain
9 Aug 2017 07:50 pm

If we assume q to be initially 0, it would be ceil(log n).

shivani @shivani1234
11 Aug 2017 12:04 pm

main() { p=0; 

for(i=1;i<=n;i=2*i) // time complexity O(lg n)

p++; //lg n

for(i=1;i<=p;i=2*i) // time complexity O(lg lg n)

q++ ; //lglg n

 return (q)

so, q returns ceil of lg(lg n)