Complexity Analysis

In this lesson, we'll see the run-time analysis for Sieve.

We'll cover the following...

The outer loop

for (int i = 2; i * i <= N; i++)

Runs for N\sqrt{N} values but the number of iterations of the inner loop is dependent on ii.

for (int j = i + i; j <= N; j += i)

Also, note that the inner loop only runs for values when ii is prime.

ii Inner loop iterations
2 N2\frac{N}{2}
3 N3
...