1- [ ![ Build Status] ( https://travis-ci.com/AladdinPersson/Algorithms-Collection-Python.svg?branch=master )] ( https://travis-ci.com/AladdinPersson/Algorithms-Collection-Python ) [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT ) [ ![ codecov] ( https://codecov.io/gh/AladdinPerzon /Algorithms-Collection-Python/branch/master/graph/badge.svg )] ( https://codecov.io/gh/AladdinPerzon /Algorithms-Collection-Python )
1+ [ ![ Build Status] ( https://travis-ci.com/AladdinPersson/Algorithms-Collection-Python.svg?branch=master )] ( https://travis-ci.com/AladdinPersson/Algorithms-Collection-Python ) [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT ) [ ![ codecov] ( https://codecov.io/gh/aladdinpersson /Algorithms-Collection-Python/branch/master/graph/badge.svg )] ( https://codecov.io/gh/aladdinpersson /Algorithms-Collection-Python )
22
33# Algorithms Collection Python
44Whenever 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.
@@ -7,64 +7,64 @@ Whenever I face an interesting problem I document the algorithm that I learned t
77:small_red_triangle : : If the algorithm is untested
88
99# Dynamic Programming
10- * :white_check_mark : [ Knapsack 0/1] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/dynamic_programming/knapsack/knapsack_bottomup.py ) ** - O(nC) Bottom-Up implementation (Loops)**
11- * :white_check_mark : [ :movie_camera : ] ( https://youtu.be/XmyxiSc3LKg ) [ Sequence Alignment] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/dynamic_programming/sequence_alignment.py ) ** - O(nm)**
12- * :white_check_mark : [ :movie_camera : ] ( https://youtu.be/dU-coYsd7zw ) [ Weighted Interval Scheduling] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/dynamic_programming/weighted_interval_scheduling.py ) ** - O(nlog(n))**
10+ * :white_check_mark : [ Knapsack 0/1] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/dynamic_programming/knapsack/knapsack_bottomup.py ) ** - O(nC) Bottom-Up implementation (Loops)**
11+ * :white_check_mark : [ :movie_camera : ] ( https://youtu.be/XmyxiSc3LKg ) [ Sequence Alignment] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/dynamic_programming/sequence_alignment.py ) ** - O(nm)**
12+ * :white_check_mark : [ :movie_camera : ] ( https://youtu.be/dU-coYsd7zw ) [ Weighted Interval Scheduling] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/dynamic_programming/weighted_interval_scheduling.py ) ** - O(nlog(n))**
1313
1414# Graph theory
15- * :white_check_mark : [ Kahns Topological Sort] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kahns-toposort/kahn_topological_ordering.py ) ** - O(n + m)**
16- * :white_check_mark : [ Bellman-Ford Shortest Path] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/bellman-ford/bellman_ford.py ) ** - O(mn)**
17- * :small_red_triangle : [ Floyd-Warshall Shortest Path] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/floyd-warshall/floyd-warshall.py ) ** - O(n<sup >3</sup >)**
18- * :white_check_mark : [ Dijkstra Shortest Path] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/dijkstra/dijkstra.py ) ** - Naive implementation**
19- * :white_check_mark : [ Dijkstra Shortest Path] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/dijkstra/heapdijkstra.py ) ** - O(mlog(n)) - Heap implementation**
20- * :small_red_triangle : [ Karger's Minimum cut] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kargers/kargermincut.py )
21- * :small_red_triangle : [ Prim's Algorithm] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/prims/prim_naive.py ) ** - O(mn) Naive implementation**
22- * :white_check_mark : [ Prim's Algorithm] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/prims/prim_heap.py ) ** - O(mlog(n)) Heap implementation**
23- * :small_red_triangle : [ Kruskal's Algorithm] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kruskal/kruskal.py ) ** - O(mn) implementation**
24- * :white_check_mark : [ Kruskal's Algorithm] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kruskal/kruskal_unionfind.py ) ** - O(mlog(n))**
25- * :white_check_mark : [ Breadth First Search] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/breadth-first-search/BFS_queue_iterative.py ) ** - O(n + m) - Queue Implementation**
26- * :white_check_mark : [ Depth First Search] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/depth-first-search/DFS_stack_iterative.py ) ** - O(n + m) - Stack Implementation**
27- * :white_check_mark : [ Depth First Search] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/depth-first-search/DFS_recursive.py ) ** - O(n + m) - Recursive Implementation**
15+ * :white_check_mark : [ Kahns Topological Sort] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kahns-toposort/kahn_topological_ordering.py ) ** - O(n + m)**
16+ * :white_check_mark : [ Bellman-Ford Shortest Path] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/bellman-ford/bellman_ford.py ) ** - O(mn)**
17+ * :small_red_triangle : [ Floyd-Warshall Shortest Path] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/floyd-warshall/floyd-warshall.py ) ** - O(n<sup >3</sup >)**
18+ * :white_check_mark : [ Dijkstra Shortest Path] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/dijkstra/dijkstra.py ) ** - Naive implementation**
19+ * :white_check_mark : [ Dijkstra Shortest Path] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/dijkstra/heapdijkstra.py ) ** - O(mlog(n)) - Heap implementation**
20+ * :small_red_triangle : [ Karger's Minimum cut] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kargers/kargermincut.py )
21+ * :small_red_triangle : [ Prim's Algorithm] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/prims/prim_naive.py ) ** - O(mn) Naive implementation**
22+ * :white_check_mark : [ Prim's Algorithm] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/prims/prim_heap.py ) ** - O(mlog(n)) Heap implementation**
23+ * :small_red_triangle : [ Kruskal's Algorithm] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kruskal/kruskal.py ) ** - O(mn) implementation**
24+ * :white_check_mark : [ Kruskal's Algorithm] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kruskal/kruskal_unionfind.py ) ** - O(mlog(n))**
25+ * :white_check_mark : [ Breadth First Search] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/breadth-first-search/BFS_queue_iterative.py ) ** - O(n + m) - Queue Implementation**
26+ * :white_check_mark : [ Depth First Search] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/depth-first-search/DFS_stack_iterative.py ) ** - O(n + m) - Stack Implementation**
27+ * :white_check_mark : [ Depth First Search] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/depth-first-search/DFS_recursive.py ) ** - O(n + m) - Recursive Implementation**
2828
2929# Mathematics
3030### Algebra
31- * :small_red_triangle : [ Karatsuba Multiplication] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/math/karatsuba/karatsuba.py ) ** - O(n<sup >1.585</sup >)**
32- * :white_check_mark : [ Intersection of two sets] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/math/intersection_of_two_sets/intersection_of_two_sets.py ) ** - O(nlog(n)) + O(mlog(m))**
33- * :white_check_mark : [ Union of two sets] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/math/union_of_two_sets/union_of_two_sets.py ) ** - O(nlog(n)) + O(mlog(m))**
31+ * :small_red_triangle : [ Karatsuba Multiplication] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/math/karatsuba/karatsuba.py ) ** - O(n<sup >1.585</sup >)**
32+ * :white_check_mark : [ Intersection of two sets] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/math/intersection_of_two_sets/intersection_of_two_sets.py ) ** - O(nlog(n)) + O(mlog(m))**
33+ * :white_check_mark : [ Union of two sets] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/math/union_of_two_sets/union_of_two_sets.py ) ** - O(nlog(n)) + O(mlog(m))**
3434
3535### Number Theory
36- * :small_red_triangle : [ Pollard p-1 factorization] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/math/pollard_p1/pollard_p1.py )
37- * :small_red_triangle : [ Euclidean Algorithm] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/math/euclid_gcd/euclid_gcd.py ) ** - O(log(n))**
38- * :small_red_triangle : [ Extended Euclidean Algorithm] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/math/extended_euclidean_algorithm/euclid_gcd.py ) ** - O(log(n))**
39- * :small_red_triangle : [ Sieve of Eratosthenes] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/math/sieve_of_eratosthenes/sieve_eratosthenes.py ) ** - O(nlog(log(n)))**
40- * :small_red_triangle : [ Prime factorization] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/math/prime_factorization/primefactorization.py ) ** - O(sqrt(n))**
36+ * :small_red_triangle : [ Pollard p-1 factorization] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/math/pollard_p1/pollard_p1.py )
37+ * :small_red_triangle : [ Euclidean Algorithm] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/math/euclid_gcd/euclid_gcd.py ) ** - O(log(n))**
38+ * :small_red_triangle : [ Extended Euclidean Algorithm] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/math/extended_euclidean_algorithm/euclid_gcd.py ) ** - O(log(n))**
39+ * :small_red_triangle : [ Sieve of Eratosthenes] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/math/sieve_of_eratosthenes/sieve_eratosthenes.py ) ** - O(nlog(log(n)))**
40+ * :small_red_triangle : [ Prime factorization] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/math/prime_factorization/primefactorization.py ) ** - O(sqrt(n))**
4141
4242### Cryptography
43- * :white_check_mark : [ Ceasar Cipher] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/ceasar_shifting_cipher/ceasar_shift_cipher.py )
44- * :small_red_triangle : [ Hill Cipher] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/hill_cipher/hill_cipher.py )
45- * :small_red_triangle : [ Vigenere Cipher] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/vigenere_cipher/vigenere.py ) *
46- * :small_red_triangle : [ One time pad] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/one_time_pad/one_time_pad.py )
47- * :small_red_triangle : [ RSA-Algorithm] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/RSA_algorithm/RSA.py )
43+ * :white_check_mark : [ Ceasar Cipher] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/ceasar_shifting_cipher/ceasar_shift_cipher.py )
44+ * :small_red_triangle : [ Hill Cipher] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/hill_cipher/hill_cipher.py )
45+ * :small_red_triangle : [ Vigenere Cipher] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/vigenere_cipher/vigenere.py ) *
46+ * :small_red_triangle : [ One time pad] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/one_time_pad/one_time_pad.py )
47+ * :small_red_triangle : [ RSA-Algorithm] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/cryptology/RSA_algorithm/RSA.py )
4848
4949
5050### Numerical Methods
51- * :small_red_triangle : [ Bisection Method] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/numerical_methods/bisection.py )
52- * :small_red_triangle : [ (simple) Fixpoint iteration] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/numerical_methods/fixpoint.py )
51+ * :small_red_triangle : [ Bisection Method] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/numerical_methods/bisection.py )
52+ * :small_red_triangle : [ (simple) Fixpoint iteration] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/numerical_methods/fixpoint.py )
5353
5454# Other
55- * :white_check_mark : [ Maintaining Median] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/other/median_maintenance.py ) ** - O(nlog(n))**
56- * :small_red_triangle : [ Huffman Algorithm] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/other/Huffman/Huffman.py )
57- * :white_check_mark : [ :movie_camera : ] ( https://youtu.be/SmPxC8m0yIY ) [ Interval Scheduling] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/other/interval_scheduling.py ) ** - O(nlog(n))**
58- * :white_check_mark : [ Binary Search] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/other/binarysearch.py ) ** - O(log(n))**
55+ * :white_check_mark : [ Maintaining Median] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/other/median_maintenance.py ) ** - O(nlog(n))**
56+ * :small_red_triangle : [ Huffman Algorithm] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/other/Huffman/Huffman.py )
57+ * :white_check_mark : [ :movie_camera : ] ( https://youtu.be/SmPxC8m0yIY ) [ Interval Scheduling] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/other/interval_scheduling.py ) ** - O(nlog(n))**
58+ * :white_check_mark : [ Binary Search] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/other/binarysearch.py ) ** - O(log(n))**
5959
6060# Sorting algorithms
61- * :white_check_mark : [ Bubble sort] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/sorting/bubblesort.py ) ** - O(n<sup >2</sup >)**
62- * :small_red_triangle : [ Hope sort] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/sorting/hopesort.py ) ** - O(1), hopefully**
63- * :white_check_mark : [ Insertion sort] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/sorting/insertionsort.py ) ** - O(n<sup >2</sup >)**
64- * :white_check_mark : [ Selection sort] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/sorting/selectionsort.py ) ** - O(n<sup >2</sup >)**
65- * :white_check_mark : [ Merge sort] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/sorting/mergesort.py ) ** - O(nlog(n))**
66- * :white_check_mark : [ Randomized Quick sort] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/sorting/randomized_quicksort.py ) ** - Average O(nlogn) (Input independent!)**
67- * :white_check_mark : [ Quick sort] ( https://github.com/AladdinPerzon /Algorithms-Collection-Python/blob/master/Algorithms/sorting/quicksort.py ) ** - Average O(nlog(n))**
61+ * :white_check_mark : [ Bubble sort] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/sorting/bubblesort.py ) ** - O(n<sup >2</sup >)**
62+ * :small_red_triangle : [ Hope sort] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/sorting/hopesort.py ) ** - O(1), hopefully**
63+ * :white_check_mark : [ Insertion sort] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/sorting/insertionsort.py ) ** - O(n<sup >2</sup >)**
64+ * :white_check_mark : [ Selection sort] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/sorting/selectionsort.py ) ** - O(n<sup >2</sup >)**
65+ * :white_check_mark : [ Merge sort] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/sorting/mergesort.py ) ** - O(nlog(n))**
66+ * :white_check_mark : [ Randomized Quick sort] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/sorting/randomized_quicksort.py ) ** - Average O(nlogn) (Input independent!)**
67+ * :white_check_mark : [ Quick sort] ( https://github.com/aladdinpersson /Algorithms-Collection-Python/blob/master/Algorithms/sorting/quicksort.py ) ** - Average O(nlog(n))**
6868
6969# Contributing
7070I 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! :)
0 commit comments