3.4.4 · D1Trees

Foundations — Binary Search Tree (BST) — BST property, insert, search, delete (3 cases)

1,789 words8 min readBack to topic

Before you can read the parent note, you need every word and symbol it leans on. This page builds them from nothing, in an order where each new idea only uses ideas already defined. Read top to bottom.


1. What is a "key"?

We need keys because the whole magic of a BST is comparing them (, , ) to decide where to go. No comparison, no search.


2. The comparison symbols: , ,

Figure — Binary Search Tree (BST) — BST property, insert, search, delete (3 cases)

Why the topic needs these: every BST decision is one comparison that picks a direction. This is the single tool that turns a shapeless pile of keys into a searchable order — the same idea used in Binary Search on Sorted Array.


3. Node, edge, root, leaf, child, parent

These come from ordinary trees. If you have met them, skim; if not, this is your foundation. See also Binary Tree — terminology & traversals.

Figure — Binary Search Tree (BST) — BST property, insert, search, delete (3 cases)

Why the topic needs these: a BST is a binary tree with the ordering rule bolted on. Without "at most two children named left/right" the phrase "left subtree" has no meaning.


4. Subtree

Why the topic needs this: the BST property talks about whole subtrees, not just direct children (). This "everyone beneath" scope is the exact trap the parent's validation mistake warns about — 6 was in the right subtree of 10, not a direct child.


5. The BST property itself (built from §1–§4)

Figure — Binary Search Tree (BST) — BST property, insert, search, delete (3 cases)

6. None / null — the empty spot

Why the topic needs this: insert works by descending until it hits a None, and search returns "not found" precisely when it lands on None. The empty slot is a first-class idea, not an afterthought.


7. Height , depth, and

See Tree Height vs Depth for the two-way view.

Figure — Binary Search Tree (BST) — BST property, insert, search, delete (3 cases)

Why the topic needs : a balanced BST halves the remaining nodes at each fork, so a path is only about long — fast. A degenerate "stick" (keys inserted already sorted) has height — slow. This gap is the whole reason AVL Tree and Red-Black Tree exist.


8. Big-O: , ,

Why the topic needs it: every cost claim in the parent (, balanced , worst ) uses this language to compare BSTs against sorted arrays and linked lists.


9. In-order traversal (why "sorted" pops out)


Prerequisite map

Key - a comparable value

Comparisons less greater equal

Node holds one key

Binary Tree - root edges leaves

BST property left small right big

Subtree - node and all below

None - empty slot

Height h and log n

Search Insert Delete

Cost Big-O of h

In-order gives sorted


Equipment checklist

Cover the right side and answer each before revealing.

What does tell you about direction in a BST?
belongs on the left (smaller) side — the direction on the number line.
What is a leaf?
A node with no children (both left and right are None).
What is the subtree of node ?
and every node reachable downward from it — not just its direct children.
State the BST property in full.
For every node with key : all keys in its left subtree are , all in its right subtree are , recursively.
What does landing on None during a search mean?
The key is not present (you fell off the tree).
What is the height ?
The number of edges on the longest root-to-leaf path.
What does count?
How many times you can halve before reaching .
Why is a balanced BST search ?
Each comparison discards half the nodes, so the path length is about .
When does height become ?
When keys are inserted already sorted, building a one-sided "stick."
Why does in-order traversal come out sorted?
It visits all smaller keys (left), then the node, then all larger keys (right), recursively.

Ready? Head back to the parent BST note and the property will read like plain English.