Time complexity for dependant nested for loop?

前端 未结 3 1975
庸人自扰
庸人自扰 2021-01-13 04:43

Can you explain me how to find time complexity for this?

sum=0;
for(k=1;k<=n;k*=2)
  for(j=1;j<=k;j++)
     sum++;

So, i know the out

3条回答
  •  时光说笑
    2021-01-13 05:23

    I believe you should proceed like the following to formally obtain your algorithm's order of growth complexity, using Mathematics (Sigma Notation):

    enter image description here

提交回复
热议问题