II · Trees, with shape

Trie (prefix tree)

A tree you walk one character at a time.

The story

Briandais introduced the structure for retrieval; Fredkin gave it the name "trie", pronounced "tree" originally, now usually "try" to disambiguate. Each edge is labelled with one character; each node is a prefix. Searching for a string of length k takes O(k), not O(k log n).

How it works

Root is empty string. Each child edge is one character; each node optionally marks "this prefix is a complete word". Lookup walks the input character by character. Insert allocates nodes for any new prefixes.

Where it lives

Search autocomplete. Spell-checkers. IP routing tables (a radix trie variant). Firewall ACLs. Browser URL bar. Virtually every text-input system has a trie hiding in it.

The key insight

Trie memory cost can dominate. Radix tries (compressed tries) merge single-child chains into edge labels: same lookup, dramatically less memory. The Linux kernel's routing table is a level-compressed trie.