##### Find value of q for given pseudo code segment.

GATE algorithm question

main() { p=0;

for(i=1;i<=n;i=2*i)

p++;

for(i=1;i<=p;i=2*i)

q++ ;

return (q)

}

find value of q

GATE algorithm question

main() { p=0;

for(i=1;i<=n;i=2*i)

p++;

for(i=1;i<=p;i=2*i)

q++ ;

return (q)

}

find value of q

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

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

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)