Add smooth sort algorithm implementation#13641
Add smooth sort algorithm implementation#13641aadr22 wants to merge 3 commits intoTheAlgorithms:masterfrom
Conversation
- Pure Python implementation of Dijkstra's smoothsort algorithm - Uses Leonardo heap structure for O(n) best case on sorted data - Includes comprehensive doctests with various edge cases - Follows repository coding standards with type hints and docstrings - In-place sorting with O(1) space complexity
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| return collection | ||
|
|
||
|
|
||
| def _generate_leonardo_numbers(max_value: int) -> list[int]: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/smooth_sort.py, please provide doctest for the function _generate_leonardo_numbers
| return leonardo | ||
|
|
||
|
|
||
| def _smooth_sort_build(arr: list[int], leonardo: list[int]) -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/smooth_sort.py, please provide doctest for the function _smooth_sort_build
| _add_to_heap(arr, i, leonardo) | ||
|
|
||
|
|
||
| def _smooth_sort_extract(arr: list[int], leonardo: list[int]) -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/smooth_sort.py, please provide doctest for the function _smooth_sort_extract
| _extract_from_heap(arr, i, leonardo) | ||
|
|
||
|
|
||
| def _add_to_heap(arr: list[int], end: int, leonardo: list[int]) -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/smooth_sort.py, please provide doctest for the function _add_to_heap
sorts/smooth_sort.py
Outdated
| _heapify_up(arr, end, leonardo) | ||
|
|
||
|
|
||
| def _extract_from_heap(arr: list[int], end: int, leonardo: list[int]) -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/smooth_sort.py, please provide doctest for the function _extract_from_heap
| _heapify_down(arr, max_idx, end - 1) | ||
|
|
||
|
|
||
| def _heapify_up(arr: list[int], index: int, leonardo: list[int]) -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/smooth_sort.py, please provide doctest for the function _heapify_up
| break | ||
|
|
||
|
|
||
| def _heapify_down(arr: list[int], index: int, end: int) -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/smooth_sort.py, please provide doctest for the function _heapify_down
sorts/smooth_sort.py
Outdated
| break | ||
|
|
||
|
|
||
| def _find_parent(index: int, leonardo: list[int]) -> int: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/smooth_sort.py, please provide doctest for the function _find_parent
- Added comprehensive doctests for all 7 helper functions - All doctests pass successfully - Addresses bot review feedback for test coverage
- Renamed 'leonardo' to '_leonardo' in _extract_from_heap and _find_parent - Indicates parameters are intentionally unused in this implementation - All doctests still pass - No linter errors
Describe your change:
This PR adds a pure Python implementation of the Smoothsort algorithm to the sorts directory.
About Smoothsort:
Implementation features:
Checklist: