Log inStart free
LESSON 3.05 · 6 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Tries

Watch words share letter paths, then find every word with a prefix.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 2 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 3.05 · TRIE BAY1 WORD · 3 LETTERS · 3 NODES
01
Stage 1 of 6 · Insert a word
A trie stores "cat" as a path of 3 letter nodes. The last node gets a word-end mark.
Explain it simply

The trie starts with an empty root on the left. The word "cat" goes in one letter at a time: c, a and t. Each letter gets a new node, linked to the one before. The last node is filled, because a word ends there.

The root links to the nodes c, a and t, in a row. The node t is filled: the word cat ends there.

letter node (filled: word end)shared prefixsearch path, resultmiss, list scan costmissing child
wordstrienew nodescat+3carcartcaredogdorootcatnew = 3 − 0 = 3cat: no shared prefixletters in the words3trie nodes3no letter is sharedwordstrienew nodescat+3carcartcaredogdorootcatnew = 3 − 0 = 3cat: no shared prefixletters in the words3trie nodes3no letter is shared
Toy: 4 to 8 words · larger lists add random 3- to 7-letter words
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
new nodes=∣w∣−∣p∣\sy{new}{data}{\text{new nodes}} = \sy{w}{data}{|w|} - \sy{p}{param}{|p|}
new=∣cat∣−0=3−0=3\text{new} = |\texttt{cat}| - 0 = 3 - 0 = 3

New nodes equal the word length minus the stored prefix length.

Common mix-ups

MYTHIf the path is in the trie, the word is stored.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01The list ant, bee, cow, elk has 12 letters. How many trie nodes does it need?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 2 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.