Skip to content

Commit 00f049f

Browse files
authored
Update heap_sort.py
1 parent c7b2850 commit 00f049f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sort/heap_sort.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def max_heap_sort(arr):
99
arr[0] = arr[i]
1010
arr[i] = temp
1111

12+
1213
def max_heapify(arr, end):
1314
""" Max heapify helper for max_heap_sort
1415
"""
@@ -35,13 +36,15 @@ def max_heapify(arr, end):
3536
# If no swap occured, no need to keep iterating
3637
else:
3738
break
39+
3840

3941
def min_heap_sort(arr):
4042
""" Heap Sort that uses a min heap to sort an array in ascending order
4143
Complexity: O(n log(n))
4244
"""
4345
for i in range(0, len(arr)-1):
4446
min_heapify(arr, i)
47+
4548

4649
def min_heapify(arr, start):
4750
""" Min heapify helper for min_heap_sort
@@ -87,4 +90,4 @@ def min_heapify(arr, start):
8790
min_heap_sort(array)
8891
print(array)
8992
print("Max Heapify Time:", timeit.timeit('max_heap_sort(array)', setup="from __main__ import max_heap_sort, array",number=10000))
90-
print("Min Heapify Time:", timeit.timeit('min_heap_sort(array)', setup="from __main__ import min_heap_sort, array",number=10000))
93+
print("Min Heapify Time:", timeit.timeit('min_heap_sort(array)', setup="from __main__ import min_heap_sort, array",number=10000))

0 commit comments

Comments
 (0)