Skip to content

Commit 32606b5

Browse files
committed
Fixed bug in max_heap_sort. Accidentally iterated one too many times
1 parent c9a55ea commit 32606b5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

sort/heap_sort.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ def max_heap_sort(arr):
22
""" Heap Sort that uses a max heap to sort an array in ascending order
33
Complexity: O(n log(n))
44
"""
5-
for i in range(len(arr)-1,-1,-1):
5+
for i in range(len(arr)-1,0,-1):
66
max_heapify(arr, i)
7-
7+
88
temp = arr[0]
99
arr[0] = arr[i]
1010
arr[i] = temp
1111

12-
1312
def max_heapify(arr, end):
1413
""" Max heapify helper for max_heap_sort
1514
"""

0 commit comments

Comments
 (0)