AVL Trees — step by step

Explore insertion, deletion, searching, heights, balance factors and rotations in a self-balancing binary search tree.
SetupStep 1
AVL treeEmpty tree
The tree is empty. Insert a key to begin.
Normal node Search path Current node Rotation Found
Tree properties
Balance factor (BF)
BF(node) = height(left subtree) − height(right subtree).

An AVL tree maintains −1 ≤ BF ≤ 1 at every node.
Operation sequenceUse non-negative integer keys
Format: +k inserts key k, -k deletes one occurrence of k, and ?k searches for k. Separate operations with commas, spaces or new lines. Duplicate insertions are counted in the node.
Normal
Heights use h(null) = 0 and h(leaf) = 1. Balance factor is left height minus right height.