Algorithms Collection Python
Whenever I face an interesting problem I document the algorithm that I learned to solve it. The goals of this repository is to have clean, efficient and most importantly correct code.
β
: If the algorithm is tested
πΊ: If the algorithm is untested
Dynamic Programming
- β Knapsack 0/1 - O(nC) Bottom-Up implementation (Loops)
- β π₯Sequence Alignment - O(nm)
- β π₯Weighted Interval Scheduling - O(nlog(n))
Graph theory
- β Kahns Topological Sort - O(n + m)
- β Bellman-Ford Shortest Path - O(mn)
- πΊ Floyd-Warshall Shortest Path - O(n3)
- β Dijkstra Shortest Path - Naive implementation
- β Dijkstra Shortest Path - O(mlog(n)) - Heap implementation
- πΊ Karger's Minimum cut
- πΊ Prim's Algorithm - O(mn) Naive implementation
- β Prim's Algorithm - O(mlog(n)) Heap implementation
- πΊ Kruskal's Algorithm - O(mn) implementation
- β Kruskal's Algorithm - O(mlog(n))
- β Breadth First Search - O(n + m) - Queue Implementation
- β Depth First Search - O(n + m) - Stack Implementation
- β Depth First Search - O(n + m) - Recursive Implementation
Mathematics
Algebra
- πΊ Karatsuba Multiplication - O(n1.585)
- β Intersection of two sets - O(nlog(n)) + O(mlog(m))
- β Union of two sets - O(nlog(n)) + O(mlog(m))
Number Theory
- πΊ Pollard p-1 factorization
- πΊ Euclidean Algorithm - O(log(n))
- πΊ Extended Euclidean Algorithm - O(log(n))
- πΊ Sieve of Eratosthenes - O(nlog(log(n)))
- πΊ Prime factorization - O(sqrt(n))
Cryptography
- β Ceasar Cipher
- πΊ Hill Cipher
- πΊ Vigenere Cipher*
- πΊ One time pad
- πΊ RSA-Algorithm
Numerical Methods
- πΊ Bisection Method
- πΊ (simple) Fixpoint iteration
Other
- β Maintaining Median - O(nlog(n))
- πΊ Huffman Algorithm
- β π₯Interval Scheduling - O(nlog(n))
- β Binary Search - O(log(n))
Sorting algorithms
- β Bubble sort - O(n2)
- πΊ Hope sort - O(1), hopefully
- β Insertion sort - O(n2)
- β Selection sort - O(n2)
- β Merge sort - O(nlog(n))
- β Randomized Quick sort - Average O(nlogn) (Input independent!)
- β Quick sort - Average O(nlog(n))
Contributing
I appreciate feedback on potential improvements and/or if you see an error that I've made! Also if you would like to contribute then do a pull request with algorithm & tests! :)