complexity analysis for double loops -


if have following code in . net:

for i=0 n     j=0 n         m=i*j     next j next 

so have done following complexity analysis:

enter image description here

is correct? in case double loop give o(n) complexity?

in simplest case, complexity of 2 nested loops equal complexity of 1 loop multiplied complexity of other. demonstration identical posted.

therefore, if want complexity of 2 nested loops o(n), make 1 of loops execute in constant time:

for i=0 10   j=0 n     m = i*j   next j next 

or have each of them execute in o(n^1/2):

for i=0 sqrt(n)   j=0 sqrt(n)     m = i*j   next j next 

or other variations of sort.

a particularly interesting solution when number of iterations in inner loop depends on counter outer loop, don't have example you.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -