Tag Archives: sieve

Sieve of Atkin

Given a limit, print all primes smaller than or equal to the given limit. Examples: Input: limit = 10 Output: 2, 3, 5, 7 Input: limit = 20 Output: 2, 3, 5, 7, 11, 13, 17, 19 We have discussed below algorithms for the above task. Sieve of Eratosthenes Sieve of Sundaram The sieve of… Read More »

Top 10 Algorithms and Data Structures for Competitive Programming

In this post “Important top 10 algorithms and data structures for competitive coding “. Topics : Graph algorithms Dynamic programming Searching and Sorting: Number theory and Other Mathematical Geometrical and Network Flow Algorithms Data Structures The below links cover all most  important algorithms and data structure topics: Graph Algorithms Breadth First Search (BFS) Depth First… Read More »

Segmented Sieve

Given a number n, print all primes smaller than n. For example, if the given number is 10, output 2, 3, 5, 7. A Naive approach is to run a loop from 0 to n-1 and check each number for primeness. A Better Approach is use Simple Sieve of Eratosthenes. Problems with Simple Sieve: The… Read More »

Sieve of Eratosthenes

Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. For example, if n is 10, the output should be “2, 3, 5, 7”. If n is 20, the output should be “2, 3, 5, 7, 11, 13, 17, 19”.