Codacoda
Back to Academy

trees

AVL Tree

An AVL Tree is a self-balancing binary search tree where the heights of the two child subtrees of any node differ by at most one. When this balance condition is violated after an insertion or deletion, the tree performs rotations to restore balance. This guarantees O(log n) time for search, insert, and delete operations in all cases.

Use Cases

  • Database indexing where consistent lookup time is critical
  • In-memory dictionaries with frequent lookups
  • Applications requiring guaranteed worst-case O(log n) operations

Complexity Analysis

MetricBestAverageWorst
TimeO(log n)O(log n)O(log n)
SpaceO(n)

Visualization

Speed:1x
Empty treeStep 1 / 19

Implementation

Output

Click "Run Code" to see output...