Skip to content

Simplify bst.py rotation algorithms#57

Merged
jonathanstallings merged 1 commit into
masterfrom
unknown repository
Oct 18, 2018
Merged

Simplify bst.py rotation algorithms#57
jonathanstallings merged 1 commit into
masterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Oct 17, 2018

Simplify the bst left and right rotation methods

Remove the if block in the _rotate_right and _rotate_left methods from
bst.py that validate the parent node of the pivot, as well as the code
that updates the pivot's parent at the end of _rotate_right and
_rotate_left.

The pivot's parent does not change throughout the rotation of the tree.
Get rid of the lines that update the parent of the pivot node because
the parent of the pivot stays constant in _rotate_left and
_rotate_right. Lines 278, 279, 295, 296 can be deleted without altering
the functionality of the rotation algorithms and gets rid of the
unneeded code that updates the parent of the pivot node.

In addition, lines 283 and 300 also unnecessarily update the parent of
the pivot node. This can be removed without changing the functionality
of _rotate_left and _rotate_right.

The parent of the pivot node does not change in _rotate_right or
_rotate_left. Delete code that updates the parent of pivot.

Simplify the bst left and right rotation methods

Remove the if block in the _rotate_right and _rotate_left methods from
bst.py that validate the parent node of the pivot, as well as the code
that updates the pivot's parent at the end of _rotate_right and
_rotate_left.

The pivot's parent does not change throughout the rotation of the tree.
Get rid of the lines that update the parent of the pivot node because
the parent of the pivot stays constant in _rotate_left and
_rotate_right. Lines 278, 279, 295, 296 can be deleted without altering
the functionality of the rotation algorithms and gets rid of the
unneeded code that updates the parent of the pivot node.

In addition, lines 283 and 300 also unnecessarily update the parent of
the pivot node. This can be removed without changing the functionality
of _rotate_left and _rotate_right.

The parent of the pivot node does not change in _rotate_right or
_rotate_left. Delete code that updates the parent of pivot.
@jonathanstallings
Copy link
Copy Markdown
Owner

Great. Nice work!

@jonathanstallings jonathanstallings merged commit 9e83d2d into jonathanstallings:master Oct 18, 2018
@jonathanstallings jonathanstallings self-assigned this Oct 18, 2018
@jonathanstallings jonathanstallings mentioned this pull request Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant