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

  1. Start at the root
  2. Compare the key
  3. Go left if smaller, right if larger
  4. Insert at the empty spot or return a match

Open the interactive page with diagrams →

People behind it

References

  1. G. M. Adelson-Velsky, E. M. Landis, Dokl. Akad. Nauk SSSR 1962, 146, 263–266.
  2. R. Bayer, E. McCreight, Acta Inform. 1972, 1, 173–189.

Textbooks

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