← Traversals · guided lesson

Tree Traversals

1 / 18 · story

the story

Binary tree

Every tool here exists because something was too slow or broke without it. Here is what.

1857 · Arthur Cayley (the name "tree"); no single inventor of the linked binary tree in programs

In 1857 the mathematician Arthur Cayley published "On the theory of the analytical forms called trees" in the Philosophical Magazine. He was counting rooted, branching shapes while studying how calculus operators combine — and the name tree stuck. In programs, a node holding two links (left, right) became a standard building block of early list-processing and compilers; no one person is credited with it. Today every node in a Java TreeMap is built on it: a key and a value, left and right child references (plus a parent link and a red/black colour bit).

the problem it solved

Representing hierarchy and branching — anything where one thing splits into at most two smaller things of the same kind.

why it matters: without it

Hierarchies would be flattened into lists: every "find", "insert in order" or "evaluate this expression" becomes a linear scan.

sources: Cayley — On the theory of the analytical forms called trees (Philosophical Magazine, 1857) ↗ · Knuth — The Art of Computer Programming, Vol. 1: Fundamental Algorithms (§2.3 Trees) ↗

also in this chapter: Depth-first traversal (pre, in, post order) · Breadth-first traversal (level order) · Serialization with null markers