1 votes 1 votes sum = 0; for( i = 0; i < n; i++) for( j = 0; j < i*i; j++) for( k = 0; k < j; k++) sum++; its time complexity should be o(n^3) 1^2 + 2^2 + ------------------------------+ n^2 = n(n+1)(2n+1)/6 = o(n^3) but answer given is o(n^5) why ? Algorithms algorithms time-complexity + – anonymous asked Jun 15, 2017 • retagged Jun 24, 2022 by makhdoom ghaya anonymous 522 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes Answer Arnab Bhadra answered Jun 16, 2017 Arnab Bhadra comment Share Follow See all 3 Comments See all 3 3 Comments reply anonymous commented Jun 16, 2017 reply Follow Share bhai thanks for replying and taking time to solve it thanku , i have question , when i = 0 , j = 0 , k = 0 it will execute 0 times how 1 time , loop will never exexute because condition fail hogai ?? how u took it one time 0 votes 0 votes Arnab Bhadra commented Jun 16, 2017 reply Follow Share Yes u r right I made mistake. I interpreted k less than or equal to j. I shall correct it as soon as possible 0 votes 0 votes anonymous commented Jun 16, 2017 reply Follow Share thanku bhai answer is o(n^5) iam waiting hope u will post soon :) 0 votes 0 votes Please log in or register to add a comment.
–1 votes –1 votes Morning only I updated my answer but it is not reflected.Sorry for that. https://stackoverflow.com/questions/7708137/running-time-of-for-loop-part-2 Niharika 1 answered Jun 15, 2017 • edited Jun 16, 2017 by Niharika 1 Niharika 1 comment Share Follow See all 3 Comments See all 3 3 Comments reply anonymous commented Jun 15, 2017 reply Follow Share thanks mam , but i have done many questions , how we can directly multiply , because j loop depends on i and k loop depends j , so we have to unroll the loop isn't it 0 votes 0 votes anonymous commented Jun 15, 2017 reply Follow Share bro correct answer is o(N^5) iam not able to generate correct series :( 0 votes 0 votes anonymous commented Jun 16, 2017 reply Follow Share thanku very much its helpful thanku for replying :) 0 votes 0 votes Please log in or register to add a comment.