Skip to content

feat: Add Heap Sort Algorithm

Yun.Long requested to merge feature/add-heap-sort into main

Closes #23 (closed) - Add heap sort algorithm

This MR adds heap sort implementation to the sorting algorithms collection.

Changes

  • Implemented heap_sort() function with O(n log n) time, O(1) space complexity
  • 🧪 All 50 tests passing (including new heap sort tests)
  • 📚 Updated README with heap sort complexity information
  • 🎯 Added heap sort to demo program

Algorithm Details

  • Time Complexity: O(n log n) best/worst case
  • Space Complexity: O(1) (in-place sorting)
  • Stable: No
  • Method: Builds max-heap and repeatedly extracts maximum element

Test Results

============================= test session starts ==============================
collected 50 items

test_sort.py::test_empty_list[bubble_sort] PASSED
test_sort.py::test_empty_list[selection_sort] PASSED
test_sort.py::test_empty_list[insertion_sort] PASSED
test_sort.py::test_empty_list[merge_sort] PASSED
test_sort.py::test_empty_list[heap_sort] PASSED
... (45 more tests)

============================== 50 passed in 0.05s ===============================

Merge request reports