I am trying to figure out the complexity of a for loop using Big O notation. I have done this before in my other classes, but this one is more rigorous than the others becau
To formally solve the your algorithm's time complexity, you may use the following steps with Sigma notation:
Also, take a look a the last slide of this very interesting document by Dr. Jauhar.
The overall number of iterations of inner loop is n + n/2 + n/4 + ... + 1 which is approximately 2n. So the complexity is O(n).
Complexity should be O(n)
. It forms a geometric series (not exactly but approximately).
The loop runs for n+ n/2 + n/4 + .... +1
which is approx 2n
.
And O(2n) = O(n)
.