04 Time Complexity of Sieve of Eratosthenes
Each prime number p will have to mark N/p numbers as prime. So total markings are:
2N+3N+5N+7N+⋯+PN where P is the largest prime smaller than N.
Taking N common
N(21+31+51+71+⋯+P1) We know
(21+31+51+71+⋯+P1)=HP of Primes=loglogP Assuming worst case where P = N
The time compelxity of Sieve of Eratosthenes is
O(NloglogN)