algorithm - Program complexity classes -


basically struggling come grips operation counting , big-o notation. understand possibly 1 of harder parts of computer science understand , have admit struggling it. give me these examples, , possibly further help/links big-o?

for (i = 0; < n; i++)      { (j = i; j < n; j++)           { sequence of statements }      } 

here complexity o(n²) - quadratic

int m = -9 (j = 0; j < n; j+=5)      {      if (j<m)           {           (k = 1; k <n; k*=3)                {some code}                }      } 

here o(n²). first loop takes n , second loop takes n answer o(n*n) equal o(n²).

any , advice further understanding great!!

the first indeed o(n^2), suspected, assuming 'sequence of statements' o(1).

however, second part of code o(n), since condition j < m never met - , thus, outer loop iterates without doing nothing. inner loop not reachable.

as side note, compilers may optimize second part of code run in o(1) setting end values of variables, not point of question.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -