← Back

AVL Tree Simulator

What is an AVL Tree?

An AVL Tree is a self-balancing Binary Search Tree. For every node, the height difference between the left and right subtrees—its balance factor—must be −1, 0, or 1.

SearchO(log n)
InsertO(log n)
DeleteO(log n)
Balance factor−1, 0, or 1

Tree operations

400 ms

Example AVL Tree loaded. Choose an operation.

Nodes0
Height0
Maximum |BF|0
Rotations0

Operation path

Rotation history

  1. No rotation was required.

AVL repair cases

LL: rotate right
RR: rotate left
LR: rotate left on child,
    then rotate right
RL: rotate right on child,
    then rotate left

balance factor =
    height(left) - height(right)

AVL concepts

Stored heights

Each node stores its subtree height. Heights are updated after recursive insertion, deletion, and every rotation.

Single rotations

LL imbalance uses a right rotation. RR imbalance uses a left rotation.

Double rotations

LR and RL imbalances require two rotations because the heavy child leans in the opposite direction.

Deletion repair

Deletion can unbalance several ancestors, so balance checks continue all the way back to the root.

AVL invariants

InvariantRequirement
BST orderingLeft values are smaller; right values are larger.
Correct stored height1 + max(left height, right height)
BalanceAbsolute balance factor is at most 1.
Duplicate policyDuplicate keys are rejected.