big o - What's the Complexity of this Algorithm? BigO -
i have following algorithm:
for (i=0; i<=n-1; i++) { (j=i; j<=n-1; j++) { sum = 0; (k=i; k<=j; k++) { sum = sum + v[k]; if (sum > max) max = sum; } } }
the complexity of first o(n), second n-i, third j-i+1.
i know o(n^3) upper bound. what's true thing can assume complexity of algorithm? o(n^3)?
thank you.
it's o(n^3)
in worst case (when i
, j
, k
of similar value). it's o(n)
in best case, when j
, k
0 or 1:)
since have prepared worst case data (and main reason of examining complexity) should assume o(n^3)
Comments
Post a Comment