Practice Discrete Math

Algorithms / Tries Prefix Search

Least You Need to Know: Tries, Prefix Search, and Shared Prefix Structure

A **trie** stores strings by characters along root-to-node paths. It is useful when many words share prefixes and the interview task asks about prefix lookup, autocomplete, or word-search branching.

The least you need to know

Key notation

root empty-prefix start node
terminal / end-of-word marker that a full dictionary word ends here
path label string formed by characters along a root-to-node path

Tiny worked example

  • Insert `to`, `tea`, and `ten`.
  • The root has a `t` edge, then a shared `e` edge for `tea` and `ten`, while `to` branches at the second character.
  • The node for path `te` is a prefix node, not yet a complete word unless a terminal marker is also present.
  • This is why prefix lookup can reuse structure instead of scanning every word separately.

Common mistakes

How to recognize this kind of problem

Start practice