Skip to content

Commit 9b6b252

Browse files
Updated binary_heap (keon#785)
* Corrected spelling anf grammar errors in docstring for heap. * Fixed method signature for remove_min by removing unused parameter i. * Fixed grammar in min_child docstring.
1 parent 0d3e4c1 commit 9b6b252

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

algorithms/heap/binary_heap.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def perc_down(self,i):
4848
def min_child(self,i):
4949
pass
5050
@abstractmethod
51-
def remove_min(self,i):
51+
def remove_min(self):
5252
pass
5353
class BinaryHeap(AbstractHeap):
5454
def __init__(self):
@@ -64,8 +64,8 @@ def perc_up(self, i):
6464

6565
"""
6666
Method insert always start by inserting the element at the bottom.
67-
it inserts rightmost spot so as to maintain the complete tree property
68-
Then, it fix the tree by swapping the new element with its parent,
67+
It inserts rightmost spot so as to maintain the complete tree property.
68+
Then, it fixes the tree by swapping the new element with its parent,
6969
until it finds an appropriate spot for the element. It essentially
7070
perc_up the minimum element
7171
Complexity: O(logN)
@@ -76,7 +76,7 @@ def insert(self, val):
7676
self.perc_up(self.currentSize)
7777

7878
"""
79-
Method min_child returns index of smaller 2 childs of its parent
79+
Method min_child returns the index of smaller of 2 children of parent at index i
8080
"""
8181
def min_child(self, i):
8282
if 2 * i + 1 > self.currentSize: # No right child
@@ -104,7 +104,7 @@ def perc_down(self, i):
104104
"""
105105
def remove_min(self):
106106
ret = self.heap[1] # the smallest value at beginning
107-
self.heap[1] = self.heap[self.currentSize] # Repalce it by the last value
107+
self.heap[1] = self.heap[self.currentSize] # Replace it by the last value
108108
self.currentSize = self.currentSize - 1
109109
self.heap.pop()
110110
self.perc_down(1)

0 commit comments

Comments
 (0)