is Sieve of erathosthens the best algorithm to generate prime numbers from 1 to N? -


I was asked this question in an interview. I have implemented an algorithm using the Arithothian concept and an array of sieve.

There is a better way to know about this question, people who do not know the sieve of sieve, here is the link:

Edit: Time and The complexity of space is the best of both. I have told them that the loopholes of SOE are complexity of space, so they asked me if I can do something about it. Here's information about the interview: 1) Apply an algorithm which prints the numbers from 1 to N. Ans: I am using SEO 2) Is this the best way to go about it? : ???

OK, it depends on what your "best" means. The sieve of Eratosthenes is very easy to implement, but will give you quite a better performance.

So, if "best" means easy to implement and understand, Eratosthenes is the way to go. If "best" means to show off your skills as a mathematician or to make algorithms very fast, then atkin is the way to go.

Comments