Hacker News new | ask | show | jobs
by wky 26 days ago
Only half of the remaining boxes need to be moved, not half of the total.
2 comments

Actually,

  sum_{i=1}^{log_2(n)} (n/2^i) = n - 1
So it's O(n).

A simple example: start at n = 2^m = 10000... (n in binary)

move 2^m/2, and keep adding halves:

  0100...
  0010...
  0001...
  ...
Sum:

  0111...11 = 2^m - 1 = n - 1
n-1 moves are O(n). So you were right.
You move n/2, then n/4,...n/2^-i

n. Sum(2^-i)=n

So its o(n. Log(n))