Prefix trees for ultra-fast string searching and autocomplete features.

Theory & Description

A trie (pronounced 'try'), also called a prefix tree, is a tree-like data structure used to store a dynamic set of strings. Each node represents a single character, and paths from root to marked nodes form complete words. Tries excel at prefix-based operations, making them ideal for autocomplete systems, spell checkers, and IP routing tables. They trade space for speed, providing O(m) operations where m is the length of the key.

Common Use Cases

  • Autocomplete and typeahead suggestions
  • Spell checking and correction
  • IP routing (longest prefix matching)
  • Word games and dictionary lookups

Complexity Cheat Sheet

OperationAverageWorst
SearchO(m)O(m)
InsertO(m)O(m)
DeleteO(m)O(m)
Prefix SearchO(m + k)O(m + k)
Space ComplexityO(n * m)

Interactive Visualization

Interactive Visualization

An interactive playground for Tries will appear here. Insert elements, step through operations, and watch the data structure update in real time.