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:

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
Post a Comment