What is the time complexity of this code? [closed]?

O(n): outer loop runs logn times, in each iteration: i=1,2,4,8,...n/4 (entrance values) inner loops runs 2*i times (entrance values) so at overall you get: 2+4+8+...+n/2 = n-2 = O(n).

I think this is correct assuming that n is a power of 2 in the first place. If n m^2 then its a little more messy – Jon Egerton Jun 1 at 10:42 3 @Jon: actually there is no mess, in any case, the algorithm will finish iterating when I = n/4 (entrance to last iteration) (and not n/2 as I previously wrote... edited). And is still O(n) – amit Jun 1 at 10:45.

The inner loop executes twice on the first iteration, then four times, then eight times, etc. So you need to figure out where the sum terminates: 2 + 4 + 8 + ... and then work out how to evaluate it (clue: geometric series).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions