From 37dbd7b931dc371480c9d3a96035cdbfcf58b09a Mon Sep 17 00:00:00 2001 From: s1s1ty Date: Tue, 27 Mar 2018 16:06:52 +0600 Subject: [PATCH] Some more tests added for Heap and Main README file updated --- Data Structure/Heap/test_heap.py | 12 +- README.md | 248 +++++++++++++++---------------- 2 files changed, 131 insertions(+), 129 deletions(-) diff --git a/Data Structure/Heap/test_heap.py b/Data Structure/Heap/test_heap.py index 30ba788..8777558 100644 --- a/Data Structure/Heap/test_heap.py +++ b/Data Structure/Heap/test_heap.py @@ -4,26 +4,32 @@ class MaxHeapTestCase(unittest.TestCase): """ Test for Heap.py""" def test(self): - # test data + # test data ob = MaxHeap() ob.insert(10) + self.assertEqual(ob.peek(), 10, msg="Max Element is not matched") ob.insert(5) + self.assertEqual(ob.peek(), 10, msg="Max Element is not matched") ob.insert(6) + self.assertEqual(ob.peek(), 10, msg="Max Element is not matched") ob.insert(3) + self.assertEqual(ob.peek(), 10, msg="Max Element is not matched") ob.insert(8) + self.assertEqual(ob.peek(), 10, msg="Max Element is not matched") ob.insert(20) self.assertEqual(ob.peek(), 20, msg="Max Element is not matched") ob.pop() + self.assertEqual(ob.peek(), 10, msg="Max Element is not matched") ob.pop() self.assertEqual(ob.peek(), 8, msg="Max Element is not matched") ob.pop() self.assertEqual(ob.peek(), 6, msg="Max Element is not matched") ob.pop() + self.assertEqual(ob.peek(), 5, msg="Max Element is not matched") ob.pop() + self.assertEqual(ob.peek(), 3, msg="Max Element is not matched") ob.pop() self.assertEqual(ob.peek(), None, msg="Max Element is not matched") if __name__ == '__main__': unittest.main() - - diff --git a/README.md b/README.md index 464b41d..7b773c6 100644 --- a/README.md +++ b/README.md @@ -1,150 +1,142 @@ # Learn Data Structure and Algorithms by Python > You need to have basic understanding of the Python programming language to proceed with the codes from this repository. -Python 3 is used for the implementation of the data structures and Algorithms - - +> Python 3 is used for the implementation of the data structures and Algorithms ## Table of Contents -- [Introduction to Python](#introduction) -- [Data Structure](./Data%20Structure/) - - [Linked List](./Data%20Structure/Linked%20List/) - - [Stack](./Data%20Structure/Stack/) - - [Queue](./Data%20Structure/Queue/) - - Binary Search Tree (BST) - - Heap - - Hash Table - - Disjoint Set Union (Union Find) - - Trie - - Suffix Array - - Segment Tree - - Binary Indexed Tree (BIT) - - Heavy Light Decomposition +* [Introduction to Python](#introduction) +* [Data Structure](./Data%20Structure/) + * [Linked List](./Data%20Structure/Linked%20List/) + * [Stack](./Data%20Structure/Stack/) + * [Queue](./Data%20Structure/Queue/) + * Binary Search Tree (BST) + * [Heap](./Data%20Structure/Heap/) + * Hash Table + * Disjoint Set Union (Union Find) + * Trie + * Suffix Array + * Segment Tree + * Binary Indexed Tree (BIT) + * Heavy Light Decomposition - [Searching](./Searching/) - - [Linear Search](./Searching/Linear%20Search/) - - [Binary Search](./Searching/Binary%20Search/) - - [Ternary Search](./Searching/Ternary%20Search/) - - -- [Sorting](./Sorting/) - - Selection Sort - - [Bubble Sort](./Sorting/Bubble%20Sort/) - - Insertion Sort - - Merge Sort - - Quick Sort - - Bucket Sort - - Counting Sort - - Heap Sort - - Radix Sort - + * [Linear Search](./Searching/Linear%20Search/) + * [Binary Search](./Searching/Binary%20Search/) + * [Ternary Search](./Searching/Ternary%20Search/) + +* [Sorting](./Sorting/) + * Selection Sort + * [Bubble Sort](./Sorting/Bubble%20Sort/) + * Insertion Sort + * Merge Sort + * Quick Sort + * Bucket Sort + * Counting Sort + * Heap Sort + * Radix Sort - Graph Algorithms - - Graph Representation - - Breadth First Search (BFS) - - Depth First Search (DFS) - - Topological Sort - - Strongly Connected Components (SCC) - - Minimum Spanning Tree (MST) - - All Pairs Shortest Path (Floyd Warshall's Algorithm) - - Single Source Shortest Path Algorithm - - Djkastra's Algorithm - - Bellman Ford Algorithm - - Directed Acyclic Graph - - Bipartite Matching - - Articulation Point, Bridge - - Euler Tour/Path - - Hamiltonian Cycle - - Stable Marriage Problem - - Chinese Postman Problem - - 2-satisfiability - - Flow Algorithms - - Maximum Flow - - Minimum Cut - - Min-Cost Max Flow - - Maximum Bipartite Matching - - Vertex Cover - -- Dynamic Programming - - Rod Cutting - - Maximum Sum (1D, 2D) - - Coin Change - - Longest Common Subsequence - - Longest Increasing Subsequence - - Matrix Multiplication - - Edit Distance (Levenshtein distance) - - 0/1 Knapsack - - Travelling Salesman Problem - - Optimal Binary Search Tree - -- Greedy Algorithms - - Activity Selection/Task Scheduling - - Huffman Coding - - Knapsack Problem (Fractional Knapsack) + * Graph Representation + * Breadth First Search (BFS) + * Depth First Search (DFS) + * Topological Sort + * Strongly Connected Components (SCC) + * Minimum Spanning Tree (MST) + * All Pairs Shortest Path (Floyd Warshall's Algorithm) + * Single Source Shortest Path Algorithm + * Djkastra's Algorithm + * Bellman Ford Algorithm + * Directed Acyclic Graph + * Bipartite Matching + * Articulation Point, Bridge + * Euler Tour/Path + * Hamiltonian Cycle + * Stable Marriage Problem + * Chinese Postman Problem + * 2-satisfiability + * Flow Algorithms + * Maximum Flow + * Minimum Cut + * Min-Cost Max Flow + * Maximum Bipartite Matching + * Vertex Cover +- Dynamic Programming + * Rod Cutting + * Maximum Sum (1D, 2D) + * Coin Change + * Longest Common Subsequence + * Longest Increasing Subsequence + * Matrix Multiplication + * Edit Distance (Levenshtein distance) + * 0/1 Knapsack + * Travelling Salesman Problem + * Optimal Binary Search Tree + +* Greedy Algorithms + * Activity Selection/Task Scheduling + * Huffman Coding + * Knapsack Problem (Fractional Knapsack) - String Algorithms - - Rabin-Karp Algorithm - - Knuth-Morris-Pratt Algorithm - - Z Algorithm - - Aho-Korasick Algorithm - - Manachers Algorithm - - Boyr-Moore Algorithm - - -- Number Theory - - Greatest Common Divisor (GCD) - - Longest Common Multiplier (LCM) - - Euler Totient (Phi) - - Primality Testing - - Prime finding(Sieve of Eratosthenes) - - Prime factorization - - Factorial - - Fibonacci - - Counting, Permutation, combination - - Exponentiation - - Big Mod - - Euclid, Extended euclid - - Josephus Problem - - Farey Sequence - - Catalan numbers - - Burnside's lemma/circular permutation - - Modular inverse - - Probability - - Chinese Remainder Theorem - - Gaussian Elimination method - - Dilworth's Theorem - - Matrix Exponentiation - + * Rabin-Karp Algorithm + * Knuth-Morris-Pratt Algorithm + * Z Algorithm + * Aho-Korasick Algorithm + * Manachers Algorithm + * Boyr-Moore Algorithm + +* Number Theory + * Greatest Common Divisor (GCD) + * Longest Common Multiplier (LCM) + * Euler Totient (Phi) + * Primality Testing + * Prime finding(Sieve of Eratosthenes) + * Prime factorization + * Factorial + * Fibonacci + * Counting, Permutation, combination + * Exponentiation + * Big Mod + * Euclid, Extended euclid + * Josephus Problem + * Farey Sequence + * Catalan numbers + * Burnside's lemma/circular permutation + * Modular inverse + * Probability + * Chinese Remainder Theorem + * Gaussian Elimination method + * Dilworth's Theorem + * Matrix Exponentiation - Computational Geometry - - Pick's Theorem - - Convex hull - - Line Intersection - - Point in a polygon - - Area of a polygon - - Line Sweeping - - Polygon intersection - - Closest Pair - - -- Game Theory - - Take Away Game - - Nim's Game - - Sprague-grundy Number - - - Others - - BackTracking - - N-Queen's Problem - - [Tower of Hanoi Problem](./Others/Tower%20of%20Hanoi/) + * Pick's Theorem + * Convex hull + * Line Intersection + * Point in a polygon + * Area of a polygon + * Line Sweeping + * Polygon intersection + * Closest Pair + +* Game Theory + + * Take Away Game + * Nim's Game + * Sprague-grundy Number + +* Others + * BackTracking + * N-Queen's Problem + * [Tower of Hanoi Problem](./Others/Tower%20of%20Hanoi/) --- ## Introduction - ### Big-O Notation and Time Complexity Analysis [Algorithms in plain English: time complexity and Big-O notation](https://medium.freecodecamp.com/time-is-complex-but-priceless-f0abd015063c) @@ -156,15 +148,19 @@ Python 3 is used for the implementation of the data structures and Algorithms Install Python 3.x in your machine [from here](https://www.python.org/downloads/release/python-343/) (if it's already not installed) and add it to your environment path so that it is accessible in terminal commands. Then you can run a Python file like this: + ```python python file.py ``` + or + ```python python3 file.py ``` ### Useful Links: + * [Algorithms, 4th Edition (book by: Robert Sedgewick and Kevin Wayne)](http://algs4.cs.princeton.edu/home/) * [Khan Academy tutorial on Algorithms](https://www.khanacademy.org/computing/computer-science/algorithms) * [Topcoder Tutorials](https://www.topcoder.com/community/data-science/data-science-tutorials/)