recategorized by
873 views

1 Answer

Best answer
5 votes
5 votes
I assume 2^2^k is evaluated as 2^(2^k)
In each iteration of while loop j is becomeing 2^2^l (where l is the loop iteration count) and loop terminates when j = 2^2^k. So, l must be equal to k when loop terminates. So, complexity of while loop is $\Theta(k)$. Now, the outher for loop runs for $n$ iterations and hence the complexity of the entire code is
$$\Theta(nk)\\
=\Theta(n\log \log n)$$
selected by

Related questions

0 votes
0 votes
2 answers
1
radha gogia asked Jul 7, 2018
1,572 views
foo(int n) { for(int i=0 ; i<n ;i++) for(int j=i ; j<=i*i ;j++) if(j%i==0) { for(int k=0;k<j;k++) printf("hii"); } } How to proceed here for analyzing the time complexity...
3 votes
3 votes
1 answer
3
Sanjay Sharma asked Feb 20, 2018
1,106 views
An array A is of length n has log( n) distinct numbers.What is the time complexity of sorting A by best comparison based algorithm ?