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).
- one cycle it's o(n);
- cycle inside cycle it's o(n^2);
- 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
Post a Comment