KickSolve • Free • Private

AVL Tree Visualizer

A self-balancing binary search tree where the balance factor of every node is -1, 0, or +1. Insert, delete and search, and see every rotation, recoloring, split and merge explained step by step.

Balance factor on every nodeRotations explainedInsert and delete steps

How to use the AVL Tree Visualizer on KickSolve

Three quick steps, no account needed.

Insert a valueType a number and press Insert. The log explains each comparison on the way down and where the new leaf is placed.
Watch the balance checkAfter the insert the tree walks back up. Every node shows its balance factor (bf). If a node reaches +2 or -2, it turns red and the case is named.
See the rotationPink nodes show the rotation. The log says which node moves up, which moves down, and why the order is still sorted.

About the AVL Tree Visualizer on KickSolve

What it is and how it works.

What is an AVL tree?

An AVL tree is a binary search tree that keeps itself balanced. For every node, the height of the left and right subtrees differs by at most 1. The difference is the balance factor: left height minus right height.

Key properties

  • Balance factor of every node is -1, 0 or +1
  • Height is always O(log n), at most about 1.44 log2(n)
  • Search, insert and delete all take O(log n)
  • An insert needs at most one rotation (single or double); a delete may need rotations at several levels

Real-world uses

  • In-memory ordered dictionaries and sets
  • Databases and indexes that are read much more than written
  • Lookup tables where worst-case speed matters

Comparing trees? Try the AVL Tree, Red-Black Tree, B-Tree or B+ Tree visualizer.

AVL Tree cases at a glance

The situations the step-by-step log will name for you.

CaseWhere the extra height isFix
Left-LeftLeft child, left subtreeRight rotation at the unbalanced node
Right-RightRight child, right subtreeLeft rotation at the unbalanced node
Left-RightLeft child, right subtreeLeft rotation at the left child, then right rotation at the node
Right-LeftRight child, left subtreeRight rotation at the right child, then left rotation at the node

Worked example

The same steps the visualizer animates for any input.

Insert 10: root.
Insert 20: goes right of 10. bf(10) = -1, fine.
Insert 30: goes right of 20. bf(10) = -2, bf(20) = -1.
  Unbalanced at 10, Right-Right case -> left rotation at 10.
Result: 20 is the root with 10 on the left and 30 on the right.
All balance factors are 0.

AVL Tree FAQ

Quick answers.

What is an AVL tree?

A self-balancing binary search tree in which the balance factor (left height minus right height) of every node is -1, 0 or +1.

What is the balance factor?

It is the height of the left subtree minus the height of the right subtree. The visualizer shows it as bf under every node.

When does an AVL tree rotate?

When an insert or delete makes a balance factor +2 or -2. The tree then does a single or double rotation to restore balance.

What are the four rotation cases?

Left-Left and Right-Right need one rotation. Left-Right and Right-Left need two rotations.

What is the time complexity of an AVL tree?

Search, insert and delete are all O(log n) because the height is always logarithmic.

AVL tree vs red-black tree?

AVL trees are more strictly balanced, so lookups are slightly faster. Red-black trees do fewer rotations on insert and delete, so writes are slightly faster.

Can I undo a change?

Yes. Press Undo to step back through your last 40 changes.

Is the visualizer free and private?

Yes. It is free with no signup, and everything runs in your browser.

More free tools from KickSolve

Other tree visualizers.