30/35
Part 7 of 7 · Follow-upsLearn

Pick a trie when the search walks it letter by letter, its nodes carry changing data, or the keys are bits

So which would you use?

  • For a fixed word list and prefix questions only, the sorted list: it's the smallest, and it counts and lists.
  • For yes or no on prefixes, many times, the set of prefixes.
  • The trie wins when the search walks letter by letter alongside something else, as in word break and the grid. It also wins when nodes carry data that changes, like counts with deletions, and when the keys are bits.

Say the honest version out loud. Knowing what a trie costs, and when not to build one, is what shows you've used one.