0 0 votes closed with the note: got the answer. What is the time complexity of the following piece of code in the terms of n? $Main()$ { $n=2^{2^k};$ $for(i=1; i<=n; i++)$ { $j=2;$ $while(j<=n)$ { $j=j^2;$ } } } Algorithms algorithms time-complexity + – pbhati 728 views comment Share Follow Print See all 4 Comments 4 4 Comments reply pbhati commented Jun 12, 2018 reply Follow flag Loop will run for $n*(k+1)$ time and $k=loglogn$ hence overall TC will be $O(nloglogn)$. 0 0 replyShare Anand. commented Jun 12, 2018 reply Follow flag i dont think you are correct 0 0 replyShare Anand. commented Jun 12, 2018 i edited by Anand. Jun 13, 2018 reply Follow flag Inner loop while(j<=n) will run $k+1$ times for every itteration of outer loop explanation-: sequence of inner loop will be $2^{1},2^{2},2^{4}....2^{2^{k}}$ hence it is running for $k+1$ times. Outer loop will run $n=2^{2^{k}}$ times. Hence total time complexity=$n=2^{2^{k}} \times k+1 \approx O(2^{2^{k}})$ 1 1 replyShare HIMANSHU KUMAR 3 commented Jun 12, 2018 reply Follow flag Take the value of K =2. So n=16. Outer loop will run 16 times. Inner loop will run for value J=2,4 and 16(3 times). So overall time=n*[loglog(n)+1]=n(K+1) 0 0 replyShare Please log in or register to add a comment.