One boss, many reports

Trees as Org Charts

The analogy

A company chart: one person at the top, each person has reports below them, and nobody has two bosses. To find someone you start at the top and take the right branch down — you never search the whole company.

Visualizer

Descending the org chart

step 1 / 7
50307020406080

A search tree. Everything left of a node is smaller; everything right is bigger.searching for 40

def search(node, t):
    if node is None:
        return None
    if t == node.value:
        return node
    if t < node.value:
        return search(node.left, t)
    return search(node.right, t)
# each comparison discards half the tree
Check yourself

Search in a balanced BST costs…