|
|||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||
In mathematics, the Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to a specified integer1. It works efficiently for the smaller primes (below 10 million) 2. It was created by Eratosthenes, an ancient Greek mathematician. When the Sieve of Eratosthenes is used in computer programming, wheel factorization is often applied before the sieve to increase the speed.
The algorithm
Algorithm details and complexityThe crossing-off of multiples of each found prime number can be started at the square of the number, as lower multiples have already been crossed out during the previous steps. The complexity of the algorithm is O(nloglogn) with a memory requirement of O(n)3. The segmented version of the sieve of Eratosthenes, with basic optimizations such as wheel factorization, uses O(n) operations and O(n1 / 2loglogn / logn) bits of memory4. David Turner 5 suggested in 1975 that the sieve of Eratosthenes could be represented in a strikingly simple and elegant way in purely functional programming languages. Turner's sieve, rendered in Haskell, is: primes = sieve [2..] sieve (p : xs) = p : sieve [x | x <− xs, x ‘mod‘ p > 0] However, Melissa O'Neill 6 showed that the complexity of Turner's algorithm is significantly worse than the complexity of the classical imperative renditions of the sieve. O'Neill demonstrated simple renditions of the sieve of Eratosthenes in Haskell with complexities similar to those of the classical algorithms. MnemonicA poem, replicating the essence of the algorithm, is as follows:7 Sift the Two's and sift the Three's, See alsoReferences
External links
|
|||||||||||||||||||||||||||||||||
| All Right Reserved © 2007, Designed by Stylish Blog. |