Binary Search Trees

Build and traverse binary search trees — insert, search, delete nodes with animated tree visualizations.

Category: Data Structures · v1.0.0
Step 1 of 6

Step 1: What is a Binary Search Tree?

A Binary Search Tree (BST) is a binary tree where every node follows one rule: all values in the left subtree are less than the node, and all values in the right subtree are greater.

This ordering property makes searching, insertion, and deletion efficient — on average O(log n) instead of O(n).

Key Terms:

  • Root — The topmost node with no parent
  • Node — An element storing a value, with up to two children
  • Leaf — A node with no children
  • Left Child — The child with a smaller value
  • Right Child — The child with a greater value
  • Height — The longest path from root to a leaf
  • BST Property — left < parent < right for every node

Sample BST

The BST Property Illustrated

In the tree above, notice how every node satisfies the ordering rule. For example, the root 50 has 30 on its left (30 < 50) and 70 on its right (70 > 50). This pattern holds recursively at every level — making the entire tree a valid BST.

About This Lab

Binary Search Trees (BSTs) combine the fast lookup of sorted arrays with the flexible insertion of linked lists. In this lab, you'll build a BST by inserting values, watch the tree balance and grow, perform in-order/pre-order/post-order traversals, search for values, delete nodes, and understand BST properties visually.

How It Works

  1. Read each step's explanation of BST concepts
  2. Insert values and watch the tree grow
  3. Step through traversal algorithms
  4. Search and delete nodes interactively
  5. Complete the quiz to test your understanding