algo·visual

AVL Tree

Data Structures
avgO(log n)worstO(log n)spaceO(n)

An empty AVL tree; badges will show each node's balance factor

1 / 94
Starting contents0 values
Operations11 / 40
  1. 1. insert(10)
  2. 2. insert(20)
  3. 3. insert(30)
  4. 4. insert(25)
  5. 5. insert(28)
  6. 6. insert(5)
  7. 7. insert(4)
  8. 8. insert(35)
  9. 9. insert(32)
  10. 10. delete(20)
  11. 11. search(28)

How it works

A self-balancing BST: every node's subtrees differ in height by at most one. After each insert or delete the heights are updated on the way back up, and any node that tips out of balance is fixed with one or two rotations, so every operation stays O(log n).

Complexity

Best
O(log n)
Average
O(log n)
Worst
O(log n)
Space
O(n)

Search algorithms

Jump to any algorithm or page