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.
| Operation | Average Case | Worst Case (Skewed) | Best Case |
|---|---|---|---|
| Search | O(log n) | O(n) | O(1) |
| Insert | O(log n) | O(n) | O(1) |
| Delete | O(log n) | O(n) | O(log n) |
| Find Min/Max | O(log n) | O(n) | O(1) |
| In-order Traversal | O(n) | O(n) | O(n) |
Wikimedia Commons, CC BY-SA
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.
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.
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.
The term "binary search tree" combines "binary" (from Latin "binarius," two) with "search tree," a structure designed for efficient search operations. The concept was formalized in the 1960s by computer scientists developing efficient sorting and retrieval algorithms.