I\'m studying for a test and found this question:
I can\'t really determine the complexity, I figured it\'s either O(n2) or O(n3) and I\'m lea
Code:
for (int i=0; i
Asymptotic Analysis on Big-O:
Loop A: Time = 1 + 1 + 1 + .. 1 (n times) = n Loop B+C: Time = 1 + 2 + 3 + .. + m = m(m+1)/2 Time = SUM { m(m+1)/2 | m in (n,0] } Time < n * (n(n+1)/2) = 1/2 n^2 * (n+1) = 1/2 n^3 + 1/2 n^2 Time ~ O(n^3)