File tree 1 file changed +4
-4
lines changed
03. Data Structures/Trees
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -27,11 +27,11 @@ def parent(self, pos):
27
27
28
28
#Method to return the position of the left child for the node currently at pos
29
29
def left_child (self , pos ):
30
- return 2 * pos
30
+ return ( 2 * pos ) + 1
31
31
32
32
#Method to return the position of the right child for the node currently at pos
33
33
def right_child (self , pos ):
34
- return (2 * pos ) + 1
34
+ return (2 * pos ) + 2
35
35
36
36
#Method that returns true if the passed node is a leaf node.
37
37
#All the nodes in the second half of the heap(when viewed as an array) are leaf nodes.
@@ -83,8 +83,8 @@ def insert(self, element):
83
83
def print_heap (self ):
84
84
for i in range (1 , (self .size // 2 ) + 1 ):
85
85
print (" PARENT : " + str (self .Heap [i ]) + " LEFT CHILD : " +
86
- str (self .Heap [2 * i ]) + " RIGHT CHILD : " +
87
- str (self .Heap [2 * i + 1 ]))
86
+ str (self .Heap [( 2 * i ) + 1 ]) + " RIGHT CHILD : " +
87
+ str (self .Heap [( 2 * i ) + 2 ]))
88
88
89
89
#Method to remove and return the maximum element from the heap . The maximum element will be at the root.
90
90
#So we will copy the element at the end of the heap into the root node and delete the last node, which will leave the heap property disturbed
You can’t perform that action at this time.
0 commit comments