data structures - time-complexity of nested loop -


why time-complexity of

function (n) {     //this loop executes n times      for( = 1 ; <= n ; + + )     //this loop executes j times j increase rate of     for( j = 1 ; j <= n ; j+ = )     print( “*” ) ;  } 

its running time n*(n^1/2)=n^3/2

so, o(n^3/2)

please explain mathematical steps.

thank in advance.

the running time bounded o(n^{3/2}), that's not tight!

notice inner loop makes o(n/i) iterations each i=1,2,...n), time complexity o(n * (1 + 1/2 + 1/3 + ... + 1/n)) = o(n log n).

this because 1+1/2+1/3+...+1/n=o(log n) well-known harmonic series.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -