while (n >= 1)
n /= 2;
I am unable to get the Big-O notation for this
while (n >= 1)
n /= 2;
I am unable to get the Big-O notation for this
Any algorithm which cuts the problem in half each time is O(log(n)).
I'll just follow Pointy's advice for the sake of exposition.
Try 8.
4 2 1 0: 4 iterations.
Try 32.
16 8 4 2 1 0: 6 iterations.
Try 66.
33 16 8 4 2 1 0: 7 iterations.
So… how are the initial numbers changing, and how are the numbers of iterations changing?