An AVL tree is a self-balancing binary search tree in which the difference in heights between the left and right subtrees (the balance factor) of any node is at most 1. Named after its inventors Adelson-Velsky and Landis (1962), it was the first self-balancing BST ever invented. The tree automatically performs rotations (single or double) during insertions and deletions to maintain balance, guaranteeing O(log n) time for all operations.
| Rotation Type | Condition | Steps | Balance Restored |
|---|---|---|---|
| Left Rotation (LL) | Right-heavy subtree | Pivot right child up | Yes |
| Right Rotation (RR) | Left-heavy subtree | Pivot left child up | Yes |
| Left-Right Rotation (LR) | Left child is right-heavy | Left rotate child, then right rotate root | Yes |
| Right-Left Rotation (RL) | Right child is left-heavy | Right rotate child, then left rotate root | Yes |
Wikimedia Commons, CC BY-SA
A binary search tree (BST) is a binary tree in which every node satisfies the property that all keys in its left subtree are less than the node's key and all keys in its right subtree are greater. This ordering property makes search, insertion, and deletion operations efficient, averaging O(log n) for balanced trees. BSTs are foundational in database indexing, symbol tables, and dynamic set operations.
A red-black tree is a self-balancing binary search tree in which each node carries an extra bit of information — its color (red or black) — and the tree satisfies a set of coloring rules that ensure the tree remains approximately balanced. Introduced by Rudolf Bayer in 1972 and further developed by Leonidas Guibas and Robert Sedgewick in 1978, it guarantees O(log n) worst-case performance for search, insert, and delete. Red-black trees are widely used in language standard libraries, including C++ STL's map and Java's TreeMap.
A binary tree is a hierarchical data structure in which each node has at most two children, referred to as the left child and the right child. It is one of the most fundamental structures in computer science, forming the basis for more specialized trees like binary search trees and heaps. Binary trees are widely used in expression parsing, Huffman coding, and database indexing.
The name "AVL" is an acronym derived from the surnames of its Soviet inventors, Georgy Adelson-Velsky and Evgenii Landis, who published the structure in their 1962 paper "An algorithm for the organization of information."