SDE & MLE Prep

Tries

When to use: many prefix queries, autocomplete, word dictionaries with wildcards, searching many words in a grid at once, and bitwise tries for XOR maximization.

Each node = map of char → child + end flag. Insert/search cost O(word length), independent of the number of words.

insert "app", "apple", "bat"
(root)
 ├─ a ─ p ─ p* ─ l ─ e*
 └─ b ─ a ─ t*                 * = end of word

Problems