0 votes 0 votes i=n; while(i>0) { j=1; while(j<=n) { j=2*j; } i=i/2; } Algorithms algorithms time-complexity + – Umar Hayat asked Sep 21, 2018 • edited Jun 18, 2022 by makhdoom ghaya Umar Hayat 209 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Mayankprakash commented Sep 21, 2018 i moved by Mayankprakash Sep 21, 2018 reply Follow Share Is it loglogn? 0 votes 0 votes Shaik Masthan commented Sep 21, 2018 reply Follow Share @Mayankprakash it is (log n) * (log n) but not log(log n) why? outer loop executes log n times inner loop executes log n times for every outer loop ===> (log n) * ( log n) it is asymptotically equivalent to for( i=n; i>0 ; i=i/2 ) { for ( j=1,j ≤ n; j=j*2) { } } Moreover, if you not giving explanation, add it as comment, not as answer. 3 votes 3 votes Please log in or register to add a comment.
0 votes 0 votes The first while loop runs O(logn) times. for each outer loop inner runs O(logn) times.So.the time complexity is O(logn)*O(logn)=O((logn)^2) phaneendrababu answered Sep 21, 2018 phaneendrababu comment Share Follow See all 0 reply Please log in or register to add a comment.