retagged by
522 views
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 ?
retagged by

2 Answers

0 votes
0 votes

Answer

–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

edited by

Related questions

0 votes
0 votes
0 answers
3
0 votes
0 votes
0 answers
4
Sajal Mallick asked Nov 27, 2023
189 views
As we have to select maximal set of “non overlapping” activities. So like job scheduling algo of greedy we can solve it. So according to that complexity must be O(n l...