0 0 votes main() { for(i=1;i<=n;i++) { for(i=1;i<=n*n;i++) { for(i=1;i<=n*n*n;i++) { x=y+z; } } } } Algorithms time-complexity + – Nishikant kumar 1.1k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 1 1 vote 0(n^3) because the internal loop runs n^3 times and now it does not satisfy the condition of 1st and 2nd loop so it comes out of the loop Saurav answered Sep 29, 2015 • selected Dec 29, 2015 by Pooja Palod Saurav comment Share Follow See all 2 Comments 2 2 Comments reply Nishikant kumar commented Sep 29, 2015 reply Follow flag how n6 please explain? 0 0 replyShare Hira Thakur commented Jan 10, 2024 reply Follow flag in the inner for loop when a condition is false then in the second for loop when we check $i\leq n^2$; so value of $i$ is taken from where the inner loop or second loop?? 0 0 replyShare Please log in or register to add a comment.
0 0 votes answer is n^3 since for first loop i =1 second loop i=1 third will run i=n^3 now when it goes back to second it compares & fails since i has changed to n^3 so it will be transfer to first loop again fail coz i = n^3 so only one time loop will execute so O(n^3) Umang Raman answered Sep 29, 2015 Umang Raman comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes First of all the variable ' i ' is not initialised. If ' i ' is declared outside all the for loops then the time complexity will be O(n3). But instead if you are declaring i each time inside a loop then time complexity will be O(n6). So basically the complexity depends on the scope of the variable i. Bipin answered Sep 29, 2015 Bipin comment Share Follow 0 reply Please log in or register to add a comment.