Skip to content

Commit

Permalink
Add AVL tree rotation example image;
Browse files Browse the repository at this point in the history
Update image;

Update image;
  • Loading branch information
Antondomashnev committed Dec 17, 2016
1 parent 24b721a commit a277fed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Binary file added AVL Tree/Images/Rotation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions AVL Tree/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ If after an insertion or deletion the balance factor becomes greater than 1, the

Each tree node keeps track of its current balance factor in a variable. After inserting a new node, we need to update the balance factor of its parent node. If that balance factor becomes greater than 1, we "rotate" part of that tree to restore the balance.

TODO: describe with pictures how these rotations work
Example of balancing the unbalanced tree using rotation:
![Rotation](Images/Rotation.jpg)

Insertion never needs more than 2 rotations. Removal might require up to *log(n)* rotations.

Expand All @@ -56,7 +57,7 @@ Most of the code in [AVLTree.swift](AVLTree.swift) is just regular [binary searc

> **Note:** If you're a bit fuzzy on the regular operations of a binary search tree, I suggest you [catch up on those first](../Binary Search Tree/). It will make the rest of the AVL tree easier to understand.
The interesting bits are in the `balance()` method which is called after inserting or deleting a node.
The interesting bits are in the `balance()` method which is called after inserting or deleting a node.

## See also

Expand Down

0 comments on commit a277fed

Please sign in to comment.