DSA Balanced Trees Visualizer

Pick a tree type to begin. Insert values one at a time and watch it take shape — every comparison on the way down, every balance factor or colour on the way back up, and the rotation, recolour, or split that restores the rules.

Binary search tree

The plain one. Nothing keeps it balanced, so the order values arrive in decides its shape — sorted input makes a stick.

  • Insert values one at a time, comparison by comparison
  • Watch sorted input flatten the tree into a stick
  • Traverse it four ways: pre-, in-, post-order, and BFS

AVL tree

Height-balanced. Each node shows its balance factor, height(right) − height(left); when one reaches ±2, a rotation fixes it.

  • Balance factors update as the insertion unwinds
  • Single and double rotations, previewed before they run
  • See the same sorted input stay short instead of stringing out

Red-black tree

Colour-balanced. New nodes go in red; when that puts two reds in a row, a recolour or a rotation restores the rules.

  • Every fix labelled by role: child, parent, grandparent, uncle
  • Recolour or rotate — and why this case needs that one
  • NIL leaves drawn, so the black-height rule is visible

2-3 tree

Balanced by construction. A node holds one or two values; when a value would make three, the node splits and pushes its middle value up — so every leaf stays on the same level.

  • Values land inside a node until it overfills
  • Splits push the middle value up, one level at a time
  • Every leaf stays on the same level, by construction