This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Added Sieve of Eratosthenes Algorithm#37
Closed
Pradyuman7 wants to merge 66 commits into
Closed
Conversation
Update README.md
Create insertionSort.cpp
Linear Search Added
Added quick_sort.cpp
CPP implementation of Depth First Search in a graph
DFS added under Graphs
Interpolation Search Added
Added Dp Programs
Added Bellman Ford & BFS under Graphs
Euclids GCD Algorithm added
Added Coin Change under Dynamic Programming
Adding 9 strings related algorithms
Added selection_sort.cpp and count_disconnected_components.cpp
Create prims_adjacency_list.cpp
Unify code style and resolve numerous compile errors in sorting folder
Add factorial with docs
Add collatz sequence
Adding data structures
Added HeapSort algorithm
Sorting on vector
…tion Fix Lucky Numbers Implementation
Create modular_exponentiation.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
// Often there is need for getting prime numbers, and when the number is large enough, there are time-outs.
// One of the most efficient and easy way of getting Prime numbers is using Sieve's Algorithm for Prime numbers.
// I have used it infinitely many times and it is one of the most handy algorithm that you MUST have up your sleeve.
// It is simple yet an elegant method of thinking, just based on logical math.
// We know Primes are those numbers who don't have any factor except 1 and the number itself.
// This is the point we use in this algorithm. Pseudocode follows below:
// boolean array[10000000];
// set all of the values in array[] as true
// loop from i=2 to less than squareRoot of the number(n) you want
// check if array[i] is true, and if it is loop from j=i2 to j=j(i+n) and put all array[j] to false
// all done, now when you loop through the array, only primes are marked with true, all others are labeled as false
//Code for this
// this code labels all the prime numbers in your array as true and other as false, now you can use your list of primes
// after this you can get prime in O(n) time (worst case)