Code:
for (i=1; i<=n; i*=2)
Is this really a loop of order n, and not perhaps of log(n)?