Sieve Of Eratosthenes ( O(n) vs O(n log log n) )

Revision en2, by katana_handler, 2018-09-07 12:30:11

Hello Everyone!

I recently found an algorithm for finding the primes in O(n) in GeeksforGeeks and it was convincing also and then there is always the Sieve of Eratosthenes running in O(n log log n). The O(n) sieve is however a modification of the normal Sieve of Eratosthenes. But now what happened was that when I implemented the O(n) Sieve it should have run faster than the normal one(at least by a small margin) but it was always slower than the normal Sieve! Can someone please tell me why is it so?

But there a small catch also when we run both the programs for N up to 10^8 the normal sieve is faster by around 0.5 — 0.7 seconds but where as when we give N=10^9 though both takes more memory and time but the O(n) sieve works 0.5 3.0-5.0 seconds faster! so the second question that comes it that, Is the O(n) sieve better for larger numbers only??

PS: The codes I used is the same as shown in the GeeksforGeeks site!

EDIT: we just implemented it on our own and the result for N<=10^8 is the same but the for 10^9 O(n) runs in 12 sec and the normal one runs in 16 sec!!

Tags #sieve, #algorithms


  Rev. Lang. By When Δ Comment
en2 English katana_handler 2018-09-07 12:30:11 172 Tiny change: 'eve works ~~0.5~~ 3.0-5.0 s' -> 'eve works <s>0.5<s> 3.0-5.0 s'
en1 English katana_handler 2018-09-07 11:33:23 1110 Initial revision (published)