Binary Search Trees (BST)

A Binary Search Tree is a node-based data structure where each node has at most two children, and every left child is smaller than its parent while every right child is larger.

Core Properties

Common Operations

Insert

Start at the root and compare the new value. Go left if smaller, right if larger, until an empty spot is found.

Search

Same traversal logic as insert — return true if the value is found, false if a null node is reached.

Delete

Three cases: leaf node (remove directly), one child (replace with child), two children (replace with in-order successor).

Time Complexities

  1. Search: O(log n) average, O(n) worst case (unbalanced)
  2. Insert: O(log n) average, O(n) worst case
  3. Delete: O(log n) average, O(n) worst case

BST Diagram

Binary Search Tree diagram showing nodes with values

A sample BST — note how left children are always smaller than their parent.

Learn More

For a deeper dive, visit the Wikipedia page on Binary Search Trees.