Skip to content

Commit 1c0ce91

Browse files
committed
Some more tests added for Heap and Main README file updated
1 parent e3a4cd3 commit 1c0ce91

File tree

2 files changed

+131
-129
lines changed

2 files changed

+131
-129
lines changed

Data Structure/Heap/test_heap.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@
44
class MaxHeapTestCase(unittest.TestCase):
55
""" Test for Heap.py"""
66
def test(self):
7-
# test data
7+
# test data
88
ob = MaxHeap()
99
ob.insert(10)
10+
self.assertEqual(ob.peek(), 10, msg="Max Element is not matched")
1011
ob.insert(5)
12+
self.assertEqual(ob.peek(), 10, msg="Max Element is not matched")
1113
ob.insert(6)
14+
self.assertEqual(ob.peek(), 10, msg="Max Element is not matched")
1215
ob.insert(3)
16+
self.assertEqual(ob.peek(), 10, msg="Max Element is not matched")
1317
ob.insert(8)
18+
self.assertEqual(ob.peek(), 10, msg="Max Element is not matched")
1419
ob.insert(20)
1520
self.assertEqual(ob.peek(), 20, msg="Max Element is not matched")
1621
ob.pop()
22+
self.assertEqual(ob.peek(), 10, msg="Max Element is not matched")
1723
ob.pop()
1824
self.assertEqual(ob.peek(), 8, msg="Max Element is not matched")
1925
ob.pop()
2026
self.assertEqual(ob.peek(), 6, msg="Max Element is not matched")
2127
ob.pop()
28+
self.assertEqual(ob.peek(), 5, msg="Max Element is not matched")
2229
ob.pop()
30+
self.assertEqual(ob.peek(), 3, msg="Max Element is not matched")
2331
ob.pop()
2432
self.assertEqual(ob.peek(), None, msg="Max Element is not matched")
2533

2634
if __name__ == '__main__':
2735
unittest.main()
28-
29-

README.md

Lines changed: 122 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,142 @@
11
# Learn Data Structure and Algorithms by Python
22

33
> You need to have basic understanding of the Python programming language to proceed with the codes from this repository.
4-
Python 3 is used for the implementation of the data structures and Algorithms
5-
6-
4+
> Python 3 is used for the implementation of the data structures and Algorithms
75
86
## Table of Contents
9-
- [Introduction to Python](#introduction)
10-
- [Data Structure](./Data%20Structure/)
11-
- [Linked List](./Data%20Structure/Linked%20List/)
12-
- [Stack](./Data%20Structure/Stack/)
13-
- [Queue](./Data%20Structure/Queue/)
14-
- Binary Search Tree (BST)
15-
- Heap
16-
- Hash Table
17-
- Disjoint Set Union (Union Find)
18-
- Trie
19-
- Suffix Array
20-
- Segment Tree
21-
- Binary Indexed Tree (BIT)
22-
- Heavy Light Decomposition
237

8+
* [Introduction to Python](#introduction)
9+
* [Data Structure](./Data%20Structure/)
10+
* [Linked List](./Data%20Structure/Linked%20List/)
11+
* [Stack](./Data%20Structure/Stack/)
12+
* [Queue](./Data%20Structure/Queue/)
13+
* Binary Search Tree (BST)
14+
* [Heap](./Data%20Structure/Heap/)
15+
* Hash Table
16+
* Disjoint Set Union (Union Find)
17+
* Trie
18+
* Suffix Array
19+
* Segment Tree
20+
* Binary Indexed Tree (BIT)
21+
* Heavy Light Decomposition
2422

2523
- [Searching](./Searching/)
26-
- [Linear Search](./Searching/Linear%20Search/)
27-
- [Binary Search](./Searching/Binary%20Search/)
28-
- [Ternary Search](./Searching/Ternary%20Search/)
29-
30-
31-
- [Sorting](./Sorting/)
32-
- Selection Sort
33-
- [Bubble Sort](./Sorting/Bubble%20Sort/)
34-
- Insertion Sort
35-
- Merge Sort
36-
- Quick Sort
37-
- Bucket Sort
38-
- Counting Sort
39-
- Heap Sort
40-
- Radix Sort
41-
24+
* [Linear Search](./Searching/Linear%20Search/)
25+
* [Binary Search](./Searching/Binary%20Search/)
26+
* [Ternary Search](./Searching/Ternary%20Search/)
27+
28+
* [Sorting](./Sorting/)
29+
* Selection Sort
30+
* [Bubble Sort](./Sorting/Bubble%20Sort/)
31+
* Insertion Sort
32+
* Merge Sort
33+
* Quick Sort
34+
* Bucket Sort
35+
* Counting Sort
36+
* Heap Sort
37+
* Radix Sort
4238

4339
- Graph Algorithms
44-
- Graph Representation
45-
- Breadth First Search (BFS)
46-
- Depth First Search (DFS)
47-
- Topological Sort
48-
- Strongly Connected Components (SCC)
49-
- Minimum Spanning Tree (MST)
50-
- All Pairs Shortest Path (Floyd Warshall's Algorithm)
51-
- Single Source Shortest Path Algorithm
52-
- Djkastra's Algorithm
53-
- Bellman Ford Algorithm
54-
- Directed Acyclic Graph
55-
- Bipartite Matching
56-
- Articulation Point, Bridge
57-
- Euler Tour/Path
58-
- Hamiltonian Cycle
59-
- Stable Marriage Problem
60-
- Chinese Postman Problem
61-
- 2-satisfiability
62-
- Flow Algorithms
63-
- Maximum Flow
64-
- Minimum Cut
65-
- Min-Cost Max Flow
66-
- Maximum Bipartite Matching
67-
- Vertex Cover
68-
69-
- Dynamic Programming
70-
- Rod Cutting
71-
- Maximum Sum (1D, 2D)
72-
- Coin Change
73-
- Longest Common Subsequence
74-
- Longest Increasing Subsequence
75-
- Matrix Multiplication
76-
- Edit Distance (Levenshtein distance)
77-
- 0/1 Knapsack
78-
- Travelling Salesman Problem
79-
- Optimal Binary Search Tree
80-
8140

82-
- Greedy Algorithms
83-
- Activity Selection/Task Scheduling
84-
- Huffman Coding
85-
- Knapsack Problem (Fractional Knapsack)
41+
* Graph Representation
42+
* Breadth First Search (BFS)
43+
* Depth First Search (DFS)
44+
* Topological Sort
45+
* Strongly Connected Components (SCC)
46+
* Minimum Spanning Tree (MST)
47+
* All Pairs Shortest Path (Floyd Warshall's Algorithm)
48+
* Single Source Shortest Path Algorithm
49+
* Djkastra's Algorithm
50+
* Bellman Ford Algorithm
51+
* Directed Acyclic Graph
52+
* Bipartite Matching
53+
* Articulation Point, Bridge
54+
* Euler Tour/Path
55+
* Hamiltonian Cycle
56+
* Stable Marriage Problem
57+
* Chinese Postman Problem
58+
* 2-satisfiability
59+
* Flow Algorithms
60+
* Maximum Flow
61+
* Minimum Cut
62+
* Min-Cost Max Flow
63+
* Maximum Bipartite Matching
64+
* Vertex Cover
8665

66+
- Dynamic Programming
67+
* Rod Cutting
68+
* Maximum Sum (1D, 2D)
69+
* Coin Change
70+
* Longest Common Subsequence
71+
* Longest Increasing Subsequence
72+
* Matrix Multiplication
73+
* Edit Distance (Levenshtein distance)
74+
* 0/1 Knapsack
75+
* Travelling Salesman Problem
76+
* Optimal Binary Search Tree
77+
78+
* Greedy Algorithms
79+
* Activity Selection/Task Scheduling
80+
* Huffman Coding
81+
* Knapsack Problem (Fractional Knapsack)
8782

8883
- String Algorithms
89-
- Rabin-Karp Algorithm
90-
- Knuth-Morris-Pratt Algorithm
91-
- Z Algorithm
92-
- Aho-Korasick Algorithm
93-
- Manachers Algorithm
94-
- Boyr-Moore Algorithm
95-
96-
97-
- Number Theory
98-
- Greatest Common Divisor (GCD)
99-
- Longest Common Multiplier (LCM)
100-
- Euler Totient (Phi)
101-
- Primality Testing
102-
- Prime finding(Sieve of Eratosthenes)
103-
- Prime factorization
104-
- Factorial
105-
- Fibonacci
106-
- Counting, Permutation, combination
107-
- Exponentiation
108-
- Big Mod
109-
- Euclid, Extended euclid
110-
- Josephus Problem
111-
- Farey Sequence
112-
- Catalan numbers
113-
- Burnside's lemma/circular permutation
114-
- Modular inverse
115-
- Probability
116-
- Chinese Remainder Theorem
117-
- Gaussian Elimination method
118-
- Dilworth's Theorem
119-
- Matrix Exponentiation
120-
84+
* Rabin-Karp Algorithm
85+
* Knuth-Morris-Pratt Algorithm
86+
* Z Algorithm
87+
* Aho-Korasick Algorithm
88+
* Manachers Algorithm
89+
* Boyr-Moore Algorithm
90+
91+
* Number Theory
92+
* Greatest Common Divisor (GCD)
93+
* Longest Common Multiplier (LCM)
94+
* Euler Totient (Phi)
95+
* Primality Testing
96+
* Prime finding(Sieve of Eratosthenes)
97+
* Prime factorization
98+
* Factorial
99+
* Fibonacci
100+
* Counting, Permutation, combination
101+
* Exponentiation
102+
* Big Mod
103+
* Euclid, Extended euclid
104+
* Josephus Problem
105+
* Farey Sequence
106+
* Catalan numbers
107+
* Burnside's lemma/circular permutation
108+
* Modular inverse
109+
* Probability
110+
* Chinese Remainder Theorem
111+
* Gaussian Elimination method
112+
* Dilworth's Theorem
113+
* Matrix Exponentiation
121114

122115
- Computational Geometry
123-
- Pick's Theorem
124-
- Convex hull
125-
- Line Intersection
126-
- Point in a polygon
127-
- Area of a polygon
128-
- Line Sweeping
129-
- Polygon intersection
130-
- Closest Pair
131-
132-
133-
- Game Theory
134-
- Take Away Game
135-
- Nim's Game
136-
- Sprague-grundy Number
137-
138-
- Others
139-
- BackTracking
140-
- N-Queen's Problem
141-
- [Tower of Hanoi Problem](./Others/Tower%20of%20Hanoi/)
116+
* Pick's Theorem
117+
* Convex hull
118+
* Line Intersection
119+
* Point in a polygon
120+
* Area of a polygon
121+
* Line Sweeping
122+
* Polygon intersection
123+
* Closest Pair
124+
125+
* Game Theory
126+
127+
* Take Away Game
128+
* Nim's Game
129+
* Sprague-grundy Number
130+
131+
* Others
132+
* BackTracking
133+
* N-Queen's Problem
134+
* [Tower of Hanoi Problem](./Others/Tower%20of%20Hanoi/)
142135

143136
---
144137

145138
## Introduction
146139

147-
148140
### Big-O Notation and Time Complexity Analysis
149141

150142
[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
156148
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.
157149

158150
Then you can run a Python file like this:
151+
159152
```python
160153
python file.py
161154
```
155+
162156
or
157+
163158
```python
164159
python3 file.py
165160
```
166161

167162
### Useful Links:
163+
168164
* [Algorithms, 4th Edition (book by: Robert Sedgewick and Kevin Wayne)](http://algs4.cs.princeton.edu/home/)
169165
* [Khan Academy tutorial on Algorithms](https://www.khanacademy.org/computing/computer-science/algorithms)
170166
* [Topcoder Tutorials](https://www.topcoder.com/community/data-science/data-science-tutorials/)

0 commit comments

Comments
 (0)