← ~/visualizations

balanced-trees

Shows a single local tree rotation (left and right) transforming an imbalanced BST region into a balanced one. The animation fades out old parent/child links and fades in the new links while keeping the BST in-order sequence (A < x < B < y < C) visibly unchanged. It also contrasts AVL-style balance factors vs Red-Black invariants and connects the local invariant to the global height bound O(log n).

canvasclick to interact
t=0s

practical uses

  • 01.Keeping ordered maps/sets fast (TreeMap/TreeSet-style structures)
  • 02.Database indexes and in-memory indexes where worst-case latency matters
  • 03.Implementing priority/range queries with predictable O(log n) performance

technical notes

Time-based 4s cycle: alternates left/right rotation each cycle and alternates AVL vs Red-Black explanation every two cycles. Node positions are interpolated between pre/post rotation layouts using the provided cubic ease(). Edges are drawn with orthogonal (blocky) connectors and cross-faded to emphasize which pointers change while preserving in-order order.