0 0 votes main() { int i,count; for (i=1; i<=n; i++) { for(i=1; i<=(n*n); i++) { for(i=1; i<=(n*n*n); i++) { count++; } } } } What will be the time complexity of the given program? Algorithms time-complexity algorithms + – Bhunesh_Singh 680 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
3 3 votes its O(n3) as the program reaches first time in the third loop it runs for i = n3. and when it comes back to loop2 it finds out that i>n2 now when it comes back to loop 1 it gets i>n so it terminates out making time complexity to be O(n3). arvin answered Jul 31, 2018 arvin comment Share Follow See all 2 Comments 2 2 Comments reply Bhunesh_Singh commented Jul 31, 2018 reply Follow flag Thank You 1 1 replyShare arvin commented Jul 31, 2018 reply Follow flag bdw its a good question :) 0 0 replyShare Please log in or register to add a comment.
0 0 votes O(n^3) because i is common for all three loops . so first loop first iteration i=1 second loop first iteration i=1; third loop i=1 1<n^3 i=2 ......................................................... i=n^3+1<=n^3 false(exit from 3rd loop) till now n^3 times loop is run. n^3+2<n^2 false(exit from second loop) n^3+3<n false(exit from first loop) soO(n^3) Nitesh Choudhary answered Jul 31, 2018 Nitesh Choudhary comment Share Follow 0 reply Please log in or register to add a comment.