WorkspaceLearning path
Level 3 · Advanced Data Structures
BUILD YOUR INTUITION

Trie

Share character-by-character paths so every node represents a prefix and can retain information about words with that prefix.

THE MENTAL MODEL

When should this come to mind?

Share character-by-character paths so every node represents a prefix and can retain information about words with that prefix.

Prefix lookupAutocompleteShared string prefixes

What makes it work

Define the alphabet, duplicate-word behavior, and empty-prefix behavior. An exact-word query needs terminal markers; prefix counts instead store words passing through each node.

When to choose something else

Exact membership alone may be simpler with a hash set; tries can use substantial memory for sparse keys.

See the pattern in action

Change the input. Follow the state. Make it yours.