Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Sieve of Eratosthenes Lab
Math
Problem shape
Beginner
4
8
15
16
23
42
Core idea
Mark multiples of each prime as composite.
Step 1 / 5
Problem shape
Math Beginner
Sieve of Eratosthenes
Welcome to the Sieve of Eratosthenes algorithm lab. Mark multiples of each prime as composite. Use it when: Use to generate all primes up to a limit. The time complexity is O(n log log n), and the space complexity is O(n). The pseudocode is: isPrime[0] = isPrime[1] = false for p from 2 while p * p <= n if isPrime[p] mark multiples of p composite As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(n log log n)
Space
O(n)
Pseudocode
isPrime[0] = isPrime[1] = false
for p from 2 while p * p <= n
if isPrime[p]
mark multiples of p composite 1.0x