Unit 04

Trees & Binary Search Trees

A tree organizes data hierarchically: one root, and every other node has exactly one parent. A binary search tree adds a rule about ordering that turns that shape into a fast lookup structure.

8 3 10 1 6 14 left < parent < right, at every node

// looking for 6: go left of 8, right of 3, found — two steps instead of scanning everything

What it is

A tree is a hierarchy of nodes starting from a single root, where each node can have child nodes beneath it. A binary tree limits each node to at most two children. A binary search tree (BST) adds one rule: for every node, everything in its left subtree is smaller, and everything in its right subtree is larger. That rule is what makes searching fast.

Why it's useful

Where it struggles

Time complexity (balanced BST)

OperationAverageWorst case (unbalanced)
SearchO(log n)O(n)
InsertO(log n)O(n)
DeleteO(log n)O(n)

Quick check

← Stacks & Queues Next: Graphs →