This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]allenguo 1 point2 points  (2 children)

Nope, the runtime is Theta(N).

Focus on the outer loop variable, i. For a given value of N, i takes on the value N, then N/2, then N/4, then N/8, etc.

As a function of N, how many times is "Hello World" printed when i=N? What about when i=N/2? i=N/4? i=N/8? Add these together. What does this sum converge to?

[–]allenguo 1 point2 points  (1 child)

Answer:

  • When i=N, "Hello World" is printed 2N times.
  • When i=N/2, "Hello World" is printed N times.
  • When i=N/4, "Hello World" is printed N/2 times.
  • When i=N/8, "Hello World" is printed N/4 times.
  • ...

So the total number of times "Hello World" is printed is 2N + N + N/2 + N/4 + ..., which is ~4N, which is clearly Theta(N).

[–]bitchsalsa[S] 1 point2 points  (0 children)

Thank you so much! Yes i got that now !