Algorithms_for_Competitive_Programming_in_Python
The Algorithms crossed in the list below are not in this repo yet. Hopefully one day, nothing will be crossed anymore:)
Graphs
- Breadth First Search (BFS)
- Depth First Search (DFS)
DFS Tree: (https://codeforces.com/blog/entry/68138)- Count number of connected components
- Shortest Path from source to all vertices Dijkstra
Shortest Path from every vertex to every other vertex Floyd WarshallMinimum Spanning tree Prim- Minimum Spanning tree Kruskal
Topological Sort- Color a graph with 2 colors ( = make it bipartite)
Johnson’s algorithmArticulation Points (or Cut Vertices) in a GraphBridges in a graph
Dynamic Programming
Longest Common SubsequenceLongest Increasing SubsequenceEdit DistanceMinimum PartitionWays to Cover a DistanceLongest Path In MatrixSubset Sum Problem - POptimal Strategy for a Game0-1 Knapsack ProblemAssembly Line Scheduling
Searching And Sorting
- Binary Search
- Check if number x is present or not in a given sorted list
- Insertion Sort
Quick Sort- Merge Sort
- Count number of inversions
- Next Greater Element
Order StatisticsKMP algorithmRabin karp- Z’s algorithm
Aho Corasick String Matching- Counting Sort
Manacher’s algorithm: Part 1, Part 2 and Part 3- Query duplicates in a range
Rolling Hash
Number theory and Other Mathematical
Prime Numbers and Prime Factorization
- Gcd (Euclid algorithm)
- Lcm
Primality TestSet 1 (Introduction and School Method)Set 2 (Fermat Method)Set 3 (Miller–Rabin)- Sieve of Eratosthenes (and other similar precomputations)
Segmented SieveWilson’s Theorem - P- Prime Factorisation
Pollard’s rho algorithm
Modulo Arithmetic Algorithms
Basic and Extended Euclidean algorithms- Euler’s Phi Function (Totient Function)
- Modular Exponentiation
Modular Multiplicative InverseChinese remainder theorem and Modulo Inverse Implementation- Binomial coeficients, modulo calculation
Miscellaneous Algorithms
- Counting Inversions
Counting Inversions using BITlogarithmic exponentiationSquare root of an integerHeavy light Decomposition and thisMatrix RankHungarian algorithmLink cutMo’s algorithm and thisRussian Peasant MultiplicationCatalan Number
Geometrical and Network Flow Algorithms
Convex HullGraham ScanLine IntersectionInterval TreeMatrix ExponentiationMaxflow Ford Furkerson Algo and Edmond Karp Implementation- Bipartite matching
Min cutStable Marriage ProblemHopcroft–Karp Algorithm for Maximum MatchingDinic’s algo
Data Structures
- Heap
- Union Find
- BST
- Binary Indexed Tree or Fenwick tree
Segment Tree (RMQ, Range Sum and Lazy Propagation)- SortedList(can replace C++ set)
K-D tree (See insert, minimum and delete)Union Find Disjoint Set (Cycle Detection and By Rank and Path Compression)TriesSuffix array (this, this and this)Sparse tableSuffix automataSuffix automata IILCA and RMQ
Approximate sequence matching
Bitap algorithmPhonetic algorithmsDaitch–Mokotoff SoundexString metricsDamerau–Levenshtein distanceTrigram search
Function Optimization and Root Finding
- Root search (bisection, secant, Newton)
- Newton method for minimum finding
- Ternary search (for unimodal function)
- Golden section (for unimodal function)
- Multivariate
Source @ http://www.geeksforgeeks.org/top-algorithms-and-data-structures-for-competitive-programming/
Idea from https://github.com/haikentcode/top10algoritms
This github repo is amazing: https://github.com/cheran-senthil/PyRival
should also have a look at David Eppstein, who has very elegant and very readable python code on algorithms. (go to Google and search: Eppstein PADS)
if you want to implement Travelling salesman problem, you should probably have a look at this nice implementation from Google: https://developers.google.com/optimization/routing/tsp