Fiveable

🔢Analytic Number Theory Unit 5 Review

QR code for Analytic Number Theory practice questions

5.2 Sieve of Eratosthenes and its analysis

5.2 Sieve of Eratosthenes and its analysis

Written by the Fiveable Content Team • Last updated August 2025
Written by the Fiveable Content Team • Last updated August 2025
🔢Analytic Number Theory
Unit & Topic Study Guides

The Sieve of Eratosthenes is a powerful tool for finding prime numbers. It works by systematically eliminating composite numbers, leaving only primes. This method is efficient and forms the basis for more advanced sieving techniques.

Analyzing the sieve's complexity reveals its efficiency, with a time complexity of O(n log log n). Various optimizations, like segmentation and wheel factorization, improve its practical performance while maintaining its fundamental approach to prime generation.

Sieve of Eratosthenes and Variants

Classic Sieve and Segmented Approach

  • Sieve of Eratosthenes systematically eliminates composite numbers to find primes up to a given limit
  • Algorithm starts by marking all multiples of 2 as composite, then proceeds with odd numbers
  • Optimization involves only checking up to the square root of the maximum number
  • Segmented sieve divides the range into smaller intervals to improve cache efficiency
  • Segmented approach reduces memory usage allows sieving of larger ranges
Classic Sieve and Segmented Approach, Sieve of Eratosthenes - Simple English Wikipedia, the free encyclopedia

Advanced Sieving Techniques

  • Wheel factorization extends the concept of skipping even numbers to larger prime wheels
  • Wheels based on products of small primes (2, 3, 5, 7) eliminate more composites in initial stages
  • Sieve of Sundaram uses a different approach generating odd primes through index manipulation
  • Sundaram's method marks indices representing sums of the form i+j+2iji + j + 2ij
  • Sieve of Atkin improves efficiency by using quadratic forms to generate prime candidates
  • Atkin's sieve reduces the number of operations needed for large prime generation
Classic Sieve and Segmented Approach, The Hubris of Impatient Sieves of Eratosthenes

Complexity Analysis

Time Complexity Evaluation

  • Basic Sieve of Eratosthenes has a time complexity of O(nloglogn)O(n \log \log n)
  • Derivation of time complexity involves summing harmonic series of prime reciprocals
  • Segmented sieve maintains the same asymptotic complexity but improves practical runtime
  • Wheel factorization reduces the constant factor in time complexity
  • Sieve of Atkin achieves theoretical time complexity of O(n)O(n) but with larger constant factors

Space Efficiency Considerations

  • Standard Sieve of Eratosthenes requires O(n)O(n) space to store boolean array
  • Bit manipulation techniques reduce space usage to O(n/8)O(n/8) bytes
  • Segmented sieve limits space complexity to O(n)O(\sqrt{n}) by processing intervals
  • Sieve of Sundaram uses O(n)O(n) space but generates primes up to 2n+22n+2
  • Space-time tradeoffs exist between different sieve variants depending on implementation details
Pep mascot
Upgrade your Fiveable account to print any study guide

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Click below to go to billing portal → update your plan → choose Yearly → and select "Fiveable Share Plan". Only pay the difference

Plan is open to all students, teachers, parents, etc
Pep mascot
Upgrade your Fiveable account to export vocabulary

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Plan is open to all students, teachers, parents, etc
report an error
description

screenshots help us find and fix the issue faster (optional)

add screenshot

2,589 studying →