performance - Time complexity of the following function -


please me giving time complexity analysis of following function.

function (n) {     for( = 1 ; <= n ; + + )        {             for( j = 1 ; j <= n ; j+ = )                 {                    print( “*” ) ;                 }        } } 

i feel should n + n*log(n).

  1. one cycle it's o(n);
  2. cycle inside cycle it's o(n^2);
  3. this case should be: n*log(n) - (n/1 + n/2 + n/3 + … + n/n) each iteration number reducing (in n division n), plus n, first iteration cycle;

so, final answer is: n + n*log(n).

checked assumption simple test , numbers, looks good.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -