Skip to content

Updated AVL tree: right vs left rotation #34

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lessons/avl-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ So let's go through the hardest part of AVL trees, the rebalances (actually dele
-> check balance of node A: left height is 0, right height is 2
unbalanced, right heavy, child is right heavy

-> perform right rotation
-> perform a left rotation
-> swap the values of nodes A and B
-> make node B the left child of node A
-> make node C the right child of node A
Expand All @@ -57,7 +57,7 @@ unbalanced, right heavy, child is right heavy
node B node C
```

This was a right rotation, but a left rotation is mirror of this. This generalized formula works for all but one case which we'll examine now.
This was a left rotation, but a right rotation is mirror of this. This generalized formula works for all but one case which we'll examine now.

## Double Rotations

Expand Down Expand Up @@ -108,15 +108,15 @@ That's a problem, right? So now we have to what's called a double rotation. You
[ ... previous steps ]
-> check balance of node A: left height is 0, right height is 2
unbalanced - right heavy, child is left heavy
-> perform left rotation on left heavy right child node B
-> perform right rotation on left heavy right child node B

5 - node A
\
7 - node B
\
8 - node C

-> now perform right rotation on node A
-> now perform left rotation on node A

7 - node A
/ \
Expand Down