-
-
Notifications
You must be signed in to change notification settings - Fork 50k
Splaytree v3 #13819
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
Splaytree v3 #13819
Conversation
|
The code i have given will work only with the provided example |
e78178a to
4ba2d14
Compare
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.
| #class node | ||
| class Node: | ||
| """A node in the Splay Tree.""" | ||
| def __init__(self, key, parent=None, left=None, right=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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
Please provide type hint for the parameter: parent
Please provide type hint for the parameter: left
Please provide type hint for the parameter: right
| #Spary Tree class | ||
| class SplayTree: | ||
| """A self-adjusting Binary Search Tree.""" | ||
| def __init__(self): |
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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
|
|
||
| # --- Basic Rotation Operations --- | ||
|
|
||
| def _rotate_left(self, x): |
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 _rotate_left
Please provide return type hint for the function: _rotate_left. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
| y.left = x | ||
| x.parent = y | ||
|
|
||
| def _rotate_right(self, x): |
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 _rotate_right
Please provide return type hint for the function: _rotate_right. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Core Splay Operation --- | ||
|
|
||
| def _splay(self, x): |
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 _splay
Please provide return type hint for the function: _splay. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Example Search Method (Uses splay) --- | ||
|
|
||
| def search(self, key): |
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 search
Please provide return type hint for the function: search. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
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.
| class Node: | ||
| """A node in the Splay Tree.""" | ||
|
|
||
| def __init__(self, key, parent=None, left=None, right=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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
Please provide type hint for the parameter: parent
Please provide type hint for the parameter: left
Please provide type hint for the parameter: right
| class SplayTree: | ||
| """A self-adjusting Binary Search Tree.""" | ||
|
|
||
| def __init__(self): |
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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
|
|
||
| # --- Basic Rotation Operations --- | ||
|
|
||
| def _rotate_left(self, x): |
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 _rotate_left
Please provide return type hint for the function: _rotate_left. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
| y.left = x | ||
| x.parent = y | ||
|
|
||
| def _rotate_right(self, x): |
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 _rotate_right
Please provide return type hint for the function: _rotate_right. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Core Splay Operation --- | ||
|
|
||
| def _splay(self, x): |
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 _splay
Please provide return type hint for the function: _splay. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Example Search Method (Uses splay) --- | ||
|
|
||
| def search(self, key): |
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 search
Please provide return type hint for the function: search. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
3535104 to
4ba2d14
Compare
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.
| #class node | ||
| class Node: | ||
| """A node in the Splay Tree.""" | ||
| def __init__(self, key, parent=None, left=None, right=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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
Please provide type hint for the parameter: parent
Please provide type hint for the parameter: left
Please provide type hint for the parameter: right
| #Spary Tree class | ||
| class SplayTree: | ||
| """A self-adjusting Binary Search Tree.""" | ||
| def __init__(self): |
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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
|
|
||
| # --- Basic Rotation Operations --- | ||
|
|
||
| def _rotate_left(self, x): |
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 _rotate_left
Please provide return type hint for the function: _rotate_left. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
| y.left = x | ||
| x.parent = y | ||
|
|
||
| def _rotate_right(self, x): |
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 _rotate_right
Please provide return type hint for the function: _rotate_right. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Core Splay Operation --- | ||
|
|
||
| def _splay(self, x): |
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 _splay
Please provide return type hint for the function: _splay. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Example Search Method (Uses splay) --- | ||
|
|
||
| def search(self, key): |
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 search
Please provide return type hint for the function: search. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
3be2619 to
4ba2d14
Compare
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.
| #class node | ||
| class Node: | ||
| """A node in the Splay Tree.""" | ||
| def __init__(self, key, parent=None, left=None, right=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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
Please provide type hint for the parameter: parent
Please provide type hint for the parameter: left
Please provide type hint for the parameter: right
| #Spary Tree class | ||
| class SplayTree: | ||
| """A self-adjusting Binary Search Tree.""" | ||
| def __init__(self): |
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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
|
|
||
| # --- Basic Rotation Operations --- | ||
|
|
||
| def _rotate_left(self, x): |
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 _rotate_left
Please provide return type hint for the function: _rotate_left. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
| y.left = x | ||
| x.parent = y | ||
|
|
||
| def _rotate_right(self, x): |
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 _rotate_right
Please provide return type hint for the function: _rotate_right. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Core Splay Operation --- | ||
|
|
||
| def _splay(self, x): |
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 _splay
Please provide return type hint for the function: _splay. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Example Search Method (Uses splay) --- | ||
|
|
||
| def search(self, key): |
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 search
Please provide return type hint for the function: search. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
62b7fd2 to
f7b25c1
Compare
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.
| class Node: | ||
| """A node in the Splay Tree.""" | ||
|
|
||
| def __init__(self, key, parent=None, left=None, right=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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
Please provide type hint for the parameter: parent
Please provide type hint for the parameter: left
Please provide type hint for the parameter: right
| class SplayTree: | ||
| """A self-adjusting Binary Search Tree.""" | ||
|
|
||
| def __init__(self): |
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.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
|
|
||
| # --- Basic Rotation Operations --- | ||
|
|
||
| def _rotate_left(self, x): |
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 _rotate_left
Please provide return type hint for the function: _rotate_left. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
| y.left = x | ||
| x.parent = y | ||
|
|
||
| def _rotate_right(self, x): |
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 _rotate_right
Please provide return type hint for the function: _rotate_right. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Core Splay Operation --- | ||
|
|
||
| def _splay(self, x): |
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 _splay
Please provide return type hint for the function: _splay. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
|
|
||
| # --- Example Search Method (Uses splay) --- | ||
|
|
||
| def search(self, key): |
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 search
Please provide return type hint for the function: search. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: key
Describe your change:
Added an implementation of the Splay Tree data structure in Python, located at
data_structures/binary_tree/splay_tree.py.A Splay Tree is a self-adjusting binary search tree that moves recently accessed elements closer to the root using rotations (splaying).
This improves access time for frequently used elements.
The code includes:
_rotate_left,_rotate_right)._splayoperation implementing Zig, Zig-Zig, and Zig-Zag cases.searchmethod that splays the found node to the root.Reference: Wikipedia - Splay Tree
Checklist:
data_structures/binary_tree/.splay_tree.py).Example Output
Before search: 10
Found: True
After splay, new root: 5
Complexity Analysis
Additional Notes
This code was tested manually to verify splay rotations and root updates.
It follows the standard Splay Tree algorithm used in self-adjusting BSTs and adheres to the repository’s coding standards.