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 values but the number of iterations of the inner loop is dependent on .
for (int j = i + i; j <= N; j += i)
Also, note that the inner loop only runs for values when is prime.
Inner loop iterations | |
---|---|
2 | |
3 |