Study Atlas › Computer Science › Data structures
Trees and binary search trees
Hierarchical structures; in a BST, left children are smaller and right children larger.
Edited by Alex C, EduAlx · Sources cited below
Explanation
Balanced BSTs (AVL, 1962; red–black trees) keep height O(log n). B-trees (Bayer and McCreight, 1972) power databases and file systems. Heaps implement priority queues. Tries index strings.
Example
Inserting 8, 3, 10, 1, 6 into a BST: 8 is root, 3 left, 10 right, 1 under 3 on the left, 6 under 3 on the right.
How it works, step by step
- Start at the root
- Compare the key
- Go left if smaller, right if larger
- Insert at the empty spot or return a match
Open the interactive page with diagrams →
People behind it
- Georgy Adelson-Velsky
- Evgenii Landis
- Rudolf Bayer
References
- G. M. Adelson-Velsky, E. M. Landis, Dokl. Akad. Nauk SSSR 1962, 146, 263–266.
- R. Bayer, E. McCreight, Acta Inform. 1972, 1, 173–189.
Textbooks
- Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein (MIT Press, 4th ed. 2022). 'CLRS', the standard algorithms text.
- Algorithms, Robert Sedgewick, Kevin Wayne (Addison-Wesley, 4th ed. 2011). Practical algorithms with Java code.
Related topics
Heaps and priority queuesHash tablesData structures: arrays, linked lists, stacks, queuesGraph algorithms: BFS, DFS and Dijkstra's shortest pathDynamic programmingTuring machines and computabilitySorting algorithms (quicksort, mergesort, heapsort)P versus NPAlgorithms and Big-O complexityBoolean logic and digital circuits