From ca8067abe7715355a34410778a809685aa70e06a Mon Sep 17 00:00:00 2001 From: gilip Date: Fri, 28 Aug 2020 00:43:06 +0300 Subject: [PATCH 1/4] Heuristic solver for tsp --- Algorithm_tests/graphtheory_tests/test_NN.py | 69 ++++++++++ .../NearestNeighborTSP.py | 126 ++++++++++++++++++ .../nearest-neighbor-tsp/graph.txt | 9 ++ 3 files changed, 204 insertions(+) create mode 100644 Algorithm_tests/graphtheory_tests/test_NN.py create mode 100644 Algorithms/graphtheory/nearest-neighbor-tsp/NearestNeighborTSP.py create mode 100644 Algorithms/graphtheory/nearest-neighbor-tsp/graph.txt diff --git a/Algorithm_tests/graphtheory_tests/test_NN.py b/Algorithm_tests/graphtheory_tests/test_NN.py new file mode 100644 index 0000000..ad8322f --- /dev/null +++ b/Algorithm_tests/graphtheory_tests/test_NN.py @@ -0,0 +1,69 @@ +import unittest +import sys + +# Import from different folder +sys.path.append("Algorithms/graphtheory/nearest-neighbor-tsp/") + +import NearestNeighborTSP + + +class TestNN(unittest.TestCase): + def setUp(self): + self.G1 = [[0,3,-1],[3,0,1],[-1,1,0]] + self.correct_path1 = [0,1,2,0] + + # No possible solution for this one so its a dead end + self.G2 = [[0, 2, -1,-1,-1], [2, 0,5,1,-1], [-1, 5, 0, -1, -1],[-1, 1, -1, 0, 3], [-1, -1, -1, 3, 0]] + self.correct_path2 = [0,1,3,4] + + # No possible solution for this one so its a dead end + self.G3 = [[0, 2, -1,-1,-1], [2, 0,5,1,-1], [-1, 5, 0, -1, -1],[-1, 1, -1, 0, -1], [-1, -1, -1, -1, 0]] + self.correct_path3 = [0, 1, 3] + + # Multiple possible solutions + self.G4 = [[0,1,1,1],[1,0,1,1],[1,1,0,1],[1,1,1,0]] + self.correct_path4 = [0, 1, 2, 3, 0] + + + # adjacency matrix of a graph for testing + adjMatrix = [[0,2,5,-1,3],[2,0,2,4,-1],[5,2,0,5,5],[-1,4,5,0,2],[3,-1,5,2,0]] + # correct rank of each node's neighbors + correctNeighbors = [[1,4,2],[0,2,3],[1,0,3,4],[4,1,2],[3,0,2]] + + + def test_0_rankNeighbors(self): + for i in range(0,4): + self.assertEqual(NearestNeighborTSP.rankNeighbors(i, self.adjMatrix), self.correctNeighbors[i], "Check if order is different.") + + + def test_1_nnTSP(self): + path=NearestNeighborTSP.nnTSP(self.adjMatrix) + # Test if path is null + self.assertIsNotNone(path,"Output is empty") + # Test if path is not complete + self.assertEqual(len(path),len(self.adjMatrix)+1,"Path in incomplete") + + + def test_linear_graph(self): + #print(NearestNeighbor.nnTSP(self.G2)) + path = NearestNeighborTSP.nnTSP(self.G1) + self.assertEqual(path,self.correct_path1) + + + def test_simple_graph(self): + path = NearestNeighborTSP.nnTSP(self.G2) + self.assertEqual(path,self.correct_path2) + + + def test_disconnected_graph(self): + path = NearestNeighborTSP.nnTSP(self.G3) + self.assertEqual(path, self.correct_path3) + + + def test_complete_graph(self): + path = NearestNeighborTSP.nnTSP(self.G4) + self.assertEqual(path, self.correct_path4) + +if __name__ == '__main__': + print("Running Nearest Neighbor TSP solver tests:") + unittest.main() \ No newline at end of file diff --git a/Algorithms/graphtheory/nearest-neighbor-tsp/NearestNeighborTSP.py b/Algorithms/graphtheory/nearest-neighbor-tsp/NearestNeighborTSP.py new file mode 100644 index 0000000..fc6b658 --- /dev/null +++ b/Algorithms/graphtheory/nearest-neighbor-tsp/NearestNeighborTSP.py @@ -0,0 +1,126 @@ +""" +Author: Philip Andreadis +e-mail: philip_andreadis@hotmail.com + + This script implements a simple heuristic solver for the Traveling Salesman Problem. + It is not guaranteed that an optimal solution will be found. + + Format of input text file must be as follows: + 1st line - number of nodes + each next line is an edge and its respective weight + + The program is executed via command line with the graph in the txt format as input. + +""" + +import time +import sys + + + +""" +This function reads the text file and returns a 2d list which represents +the adjacency matrix of the given graph +""" +def parseGraph(path): + # Read number of vertices and create adjacency matrix + f = open(path, "r") + n = int(f.readline()) + adjMatrix = [[-1 for i in range(n)] for j in range(n)] + #Fill adjacency matrix with the correct edges + for line in f: + edge = line.split(" ") + edge = list(map(int, edge)) + adjMatrix[edge[0]][edge[1]] = edge[2] + adjMatrix[edge[1]][edge[0]] = edge[2] + for i in range(len(adjMatrix)): + adjMatrix[i][i] = 0 + return adjMatrix + + + +""" +Returns all the neighboring nodes of a node sorted based on the distance between them. +""" +def rankNeighbors(node,adj): + sortednn = {} + nList = [] + for i in range(len(adj[node])): + if adj[node][i]>0: + sortednn[i] = adj[node][i] + sortednn = {k: v for k, v in sorted(sortednn.items(), key=lambda item: item[1])} + nList = list(sortednn.keys()) + return nList + + +""" +Function implementing the logic of nearest neighbor TSP. +Generate two lists a and b, placing the starting node in list a and the rest in list b. +While b is not empty append to a the closest neighboring node of the last node in a and remove it from b. +Repeat until a full path has been added to a and b is empty. +Returns list a representing the shortest path of the graph. +""" +def nnTSP(adj): + nodes = list(range(0, len(adj))) + #print(nodes) + weight = 0 + global length + # Starting node is 0 + a = [] + a.append(nodes[0]) + b = nodes[1:] + while b: + # Take last placed node in a + last = a[-1] + # Find its nearest neighbor + sortedNeighbors = rankNeighbors(last,adj) + # If node being checked has no valid neighbors and the path is not complete a dead end is reached + if (not sortedNeighbors) and len(a) Date: Sat, 30 Jan 2021 21:53:34 +0100 Subject: [PATCH 2/4] changed setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 331b2bb..4369946 100644 --- a/setup.py +++ b/setup.py @@ -5,5 +5,5 @@ packages=["Algorithm_test"], version="0.0.7", description="Testing Algorithm Collection", - url="https://github.com/AladdinPerzon/Algorithms-Collection-Python", + url="https://github.com/aladdinpersson/Algorithms-Collection-Python", ) From 74006c85daf4c213b65a801c3b8b4175673a8c4e Mon Sep 17 00:00:00 2001 From: Aladdin Persson Date: Sat, 30 Jan 2021 22:01:28 +0100 Subject: [PATCH 3/4] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ed6c6b..597b286 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/AladdinPerzon/Algorithms-Collection-Python.svg?branch=master)](https://travis-ci.com/AladdinPerzon/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) +[![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) # 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. From 266e5608b0c3558c3738ab749e27329010cd9fd6 Mon Sep 17 00:00:00 2001 From: Aladdin Persson Date: Sat, 30 Jan 2021 22:02:13 +0100 Subject: [PATCH 4/4] updated readme --- README.md | 86 +++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 597b286..115182e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![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) +[![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) # 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. @@ -7,64 +7,64 @@ Whenever I face an interesting problem I document the algorithm that I learned t :small_red_triangle:: If the algorithm is untested # Dynamic Programming -* :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)** -* :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)** -* :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))** +* :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)** +* :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)** +* :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))** # Graph theory -* :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)** -* :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)** -* :small_red_triangle: [Floyd-Warshall Shortest Path](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/floyd-warshall/floyd-warshall.py) **- O(n3)** -* :white_check_mark: [Dijkstra Shortest Path](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/dijkstra/dijkstra.py) **- Naive implementation** -* :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** -* :small_red_triangle: [Karger's Minimum cut](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kargers/kargermincut.py) -* :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** -* :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** -* :small_red_triangle: [Kruskal's Algorithm](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kruskal/kruskal.py) **- O(mn) implementation** -* :white_check_mark: [Kruskal's Algorithm](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kruskal/kruskal_unionfind.py) **- O(mlog(n))** -* :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** -* :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** -* :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** +* :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)** +* :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)** +* :small_red_triangle: [Floyd-Warshall Shortest Path](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/floyd-warshall/floyd-warshall.py) **- O(n3)** +* :white_check_mark: [Dijkstra Shortest Path](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/dijkstra/dijkstra.py) **- Naive implementation** +* :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** +* :small_red_triangle: [Karger's Minimum cut](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kargers/kargermincut.py) +* :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** +* :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** +* :small_red_triangle: [Kruskal's Algorithm](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kruskal/kruskal.py) **- O(mn) implementation** +* :white_check_mark: [Kruskal's Algorithm](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/graphtheory/kruskal/kruskal_unionfind.py) **- O(mlog(n))** +* :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** +* :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** +* :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** # Mathematics ### Algebra -* :small_red_triangle: [Karatsuba Multiplication](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/math/karatsuba/karatsuba.py) **- O(n1.585)** -* :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))** -* :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))** +* :small_red_triangle: [Karatsuba Multiplication](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/math/karatsuba/karatsuba.py) **- O(n1.585)** +* :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))** +* :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))** ### Number Theory -* :small_red_triangle: [Pollard p-1 factorization](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/math/pollard_p1/pollard_p1.py) -* :small_red_triangle: [Euclidean Algorithm](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/math/euclid_gcd/euclid_gcd.py) **- O(log(n))** -* :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))** -* :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)))** -* :small_red_triangle: [Prime factorization](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/math/prime_factorization/primefactorization.py) **- O(sqrt(n))** +* :small_red_triangle: [Pollard p-1 factorization](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/math/pollard_p1/pollard_p1.py) +* :small_red_triangle: [Euclidean Algorithm](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/math/euclid_gcd/euclid_gcd.py) **- O(log(n))** +* :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))** +* :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)))** +* :small_red_triangle: [Prime factorization](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/math/prime_factorization/primefactorization.py) **- O(sqrt(n))** ### Cryptography -* :white_check_mark: [Ceasar Cipher](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/ceasar_shifting_cipher/ceasar_shift_cipher.py) -* :small_red_triangle: [Hill Cipher](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/hill_cipher/hill_cipher.py) -* :small_red_triangle: [Vigenere Cipher](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/vigenere_cipher/vigenere.py)* -* :small_red_triangle: [One time pad](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/one_time_pad/one_time_pad.py) -* :small_red_triangle: [RSA-Algorithm](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/RSA_algorithm/RSA.py) +* :white_check_mark: [Ceasar Cipher](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/ceasar_shifting_cipher/ceasar_shift_cipher.py) +* :small_red_triangle: [Hill Cipher](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/hill_cipher/hill_cipher.py) +* :small_red_triangle: [Vigenere Cipher](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/vigenere_cipher/vigenere.py)* +* :small_red_triangle: [One time pad](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/one_time_pad/one_time_pad.py) +* :small_red_triangle: [RSA-Algorithm](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/cryptology/RSA_algorithm/RSA.py) ### Numerical Methods -* :small_red_triangle: [Bisection Method](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/numerical_methods/bisection.py) -* :small_red_triangle: [(simple) Fixpoint iteration](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/numerical_methods/fixpoint.py) +* :small_red_triangle: [Bisection Method](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/numerical_methods/bisection.py) +* :small_red_triangle: [(simple) Fixpoint iteration](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/numerical_methods/fixpoint.py) # Other -* :white_check_mark: [Maintaining Median](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/other/median_maintenance.py) **- O(nlog(n))** -* :small_red_triangle: [Huffman Algorithm](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/other/Huffman/Huffman.py) -* :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))** -* :white_check_mark: [Binary Search](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/other/binarysearch.py) **- O(log(n))** +* :white_check_mark: [Maintaining Median](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/other/median_maintenance.py) **- O(nlog(n))** +* :small_red_triangle: [Huffman Algorithm](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/other/Huffman/Huffman.py) +* :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))** +* :white_check_mark: [Binary Search](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/other/binarysearch.py) **- O(log(n))** # Sorting algorithms -* :white_check_mark: [Bubble sort](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/sorting/bubblesort.py) **- O(n2)** -* :small_red_triangle: [Hope sort](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/sorting/hopesort.py) **- O(1), hopefully** -* :white_check_mark: [Insertion sort](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/sorting/insertionsort.py) **- O(n2)** -* :white_check_mark: [Selection sort](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/sorting/selectionsort.py) **- O(n2)** -* :white_check_mark: [Merge sort](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/sorting/mergesort.py) **- O(nlog(n))** -* :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!)** -* :white_check_mark: [Quick sort](https://github.com/AladdinPerzon/Algorithms-Collection-Python/blob/master/Algorithms/sorting/quicksort.py) **- Average O(nlog(n))** +* :white_check_mark: [Bubble sort](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/sorting/bubblesort.py) **- O(n2)** +* :small_red_triangle: [Hope sort](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/sorting/hopesort.py) **- O(1), hopefully** +* :white_check_mark: [Insertion sort](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/sorting/insertionsort.py) **- O(n2)** +* :white_check_mark: [Selection sort](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/sorting/selectionsort.py) **- O(n2)** +* :white_check_mark: [Merge sort](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/sorting/mergesort.py) **- O(nlog(n))** +* :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!)** +* :white_check_mark: [Quick sort](https://github.com/aladdinpersson/Algorithms-Collection-Python/blob/master/Algorithms/sorting/quicksort.py) **- 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! :)