1 for(i=1; i<=n; i++){
2 for(j=1; j<=n; j*=2){
3 a[i][j]=b[i][j-1]+1;
4 }
5 }
line 1 : n+1 times
lnie 2 : n/2+1 times
line 3 : constant time c
so, I computed $(n+1)(n/2+1)c=(n^2+2n+2)/2+c=\theta(n^2)$
Is it right computation?
1 for(i=1; i<=n; i++){
2 for(j=1; j<=n; j*=2){
3 a[i][j]=b[i][j-1]+1;
4 }
5 }
line 1 : n+1 times
lnie 2 : n/2+1 times
line 3 : constant time c
so, I computed $(n+1)(n/2+1)c=(n^2+2n+2)/2+c=\theta(n^2)$
Is it right computation?
j*=2
rather thanj+=2
. – Yuval Filmus Apr 15 '18 at 09:31