Skip to content
Commitwise
Menu

Trie

Also called: Prefix tree

A tree that stores words character by character, so all words with the same prefix share one path.

Definition

Each node represents a prefix and has children for the possible next characters; a flag marks nodes where a word ends. Inserting, looking up a word and checking a prefix take time proportional to the word's length, regardless of how many words are stored. Tries power autocomplete, spell checking and longest-prefix matching.

In practice

Typing "swi" walks three nodes and lists the words stored below them: swift, swim, switch.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.