Logarithmic Runtime
Explore the concept of logarithmic runtime and its impact on algorithm complexity. Understand how loops that multiply or divide by 2 run in O(log N) time. Analyze the harmonic series to grasp O(N log N) complexity, building a foundation for optimizing algorithms in competitive programming.
We'll cover the following...
We'll cover the following...
Iterating powers of a number
Let’s analyze the loop below where we iterate over all powers of
for (int i = 1; i <= N; i *= 2)
x++;
- Iteration :
- Iteration :
- Iteration :
- …
- Iteration :
Let’s say the loop terminates after the iteration, i.e.,
Hence, the loop runs times.
In Big-O notation, the time complexity is ...