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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -