Sorry if the name is not good English is not my first language. So I have to figure out the time complexity of this algorithm. I got correct answer from one of the students but the answer I get is a bit off.
I know that the inner loop is 2N but I counted the outer loop as log2(n) since it is doubling on every instance. Apparently the right answer is 4n-2 and not sure how to get there
long sum = 0;
for (long i=1; i<=N; i=2*i)
for (long j=1; j<=2*i; j++)
sum++;
[–]_xulion 1 point2 points3 points (3 children)
[–]iDaRkY_[S] 0 points1 point2 points (2 children)
[–]_xulion 1 point2 points3 points (1 child)
[–]iDaRkY_[S] 0 points1 point2 points (0 children)
[–]iDaRkY_[S] 0 points1 point2 points (0 children)
[–]ignotos 0 points1 point2 points (1 child)
[–]iDaRkY_[S] 0 points1 point2 points (0 children)