feat: add tournament sort algorithm#14732
Conversation
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.
| if len(sequence) <= 1: | ||
| return list(sequence) | ||
|
|
||
| def build_tree(arr: list[int]) -> 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/tournament_sort.py, please provide doctest for the function build_tree
| tree[i] = min(left, right) | ||
| return tree | ||
|
|
||
| def extract_min(tree: list[int | None], n: 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/tournament_sort.py, please provide doctest for the function extract_min
Please provide descriptive name for the parameter: n
diusazzad
left a comment
There was a problem hiding this comment.
Could you check the failing logs when you have a moment? If the error message is confusing or you need an extra pair of eyes to debug it, just drop a comment here. I’d be super happy to help you fix it together!
Add Tournament Sort algorithm implementation.
Tournament sort builds a binary tournament tree where elements compete
to find the minimum, extracting elements one by one to produce a sorted list.
Time complexity: O(n log n) | Space complexity: O(n)
Reference: https://en.wikipedia.org/wiki/Tournament_sort
Describe your change:
Checklist: