-
-
Notifications
You must be signed in to change notification settings - Fork 49.1k
Add Splay Tree implementation #13761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Self-adjusting binary search tree with splaying operations - Implements all standard BST operations (insert, delete, search, min, max) - Includes zig, zig-zig, and zig-zag rotation operations - Amortized O(log n) time complexity for all operations - Comprehensive doctests with 81 passing tests - Performance demonstration showing locality of reference - Includes tree visualization and traversal methods
for more information, see https://pre-commit.ci
|
@darkstar please check the PR and merge this under hacktober fest label |
Replace if-else block with ternary operator at line 302 to comply with Ruff linting rules
- Add explicit type annotations for current and parent variables - Add type annotation for result lists in traversal methods - Add null check for parent before accessing its key - Fixes all 6 MyPy errors reported by pre-commit hooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| self.right: Node | None = None | ||
| self.parent: Node | None = None | ||
|
|
||
| def __repr__(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/splay_tree.py, please provide doctest for the function __repr__
| ) | ||
|
|
||
|
|
||
| def performance_comparison() -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/splay_tree.py, please provide doctest for the function performance_comparison
- Add 14 comprehensive doctests to performance_comparison function - Fix MyPy union-attr error at line 259 by adding proper null check - Total doctests increased from 81 to 95 - All tests verify splay tree behavior and BST property maintenance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| self.right: Node | None = None | ||
| self.parent: Node | None = None | ||
|
|
||
| def __repr__(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/splay_tree.py, please provide doctest for the function __repr__
Remove redundant 'import random' on line 683 that was already imported on line 657 in the performance_comparison function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| self.right: Node | None = None | ||
| self.parent: Node | None = None | ||
|
|
||
| def __repr__(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/splay_tree.py, please provide doctest for the function __repr__
- Add 11 comprehensive doctests for __repr__ method - Test various data types: int, string, negative numbers, float, None - Test both repr() and str() functions - Total doctests increased from 95 to 106
Describe your change:
This PR adds a complete implementation of a Splay Tree - a self-adjusting binary search tree that provides excellent amortized performance and cache locality.
Key Features:
Why Splay Tree?
Implementation Details:
data_structures/binary_tree/splay_tree.pyFixes #13760
Checklist: