CoursesTrees & Graphs

Tries

Lessons
9
Exercises
58
Minutes
61
  1. 1

    Letters as Edges

    A trie stores strings one character-edge at a time: shared prefixes share a path, and a word-end flag marks where real words stop.

    Complete codeMultiple choiceTap
    6 exercises
    5 min
  2. 2

    Longest Common Prefix

    Scan column by column across all strings at once, and stop at the first disagreement — or when the shortest string runs out.

    Complete codeMultiple choiceTrace
    7 exercises
    6 min
  3. 3

    Implement Trie (Prefix Tree)

    Build the canonical node — children[26] plus an isWord flag — and see why search and startsWith differ by exactly one check.

    Complete codeDebugCode orderMultiple choiceTrace
    7 exercises
    7 min
  4. 4

    Replace Words

    Insert every root into a trie, then walk each sentence word and stop at the FIRST word-end — the shortest root wins automatically.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    6 min
  5. 5

    Longest Word in Dictionary

    A word qualifies only if EVERY prefix of it is also a word — so DFS the trie and refuse to step onto any node that isn't a word-end.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  6. 6

    Search Suggestions System

    Autocomplete = one trie cursor that advances a single edge per keystroke, plus a DFS that collects the 3 smallest words below it — sorted order comes from the alphabet, not from sorting.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  7. 7

    Tries CheckpointCheckpoint

    No new concepts — carry the island's trie moves into unseen problems: counting contacts by prefix, summing values under a prefix, camelCase matching, and prefix-free code checks.

    Complete codeCode orderMultiple choiceTrace
    6 exercises
    7 min
  8. 8

    Tries ReviewReview

    Mixed recap of the island: node anatomy and the isWord flag, insert vs search asymmetry, when a trie beats a hashset, shortest vs longest root walks, enumerating below a node, and what bounds a trie's size.

    Complete codeCode orderMultiple choice
    6 exercises
    6 min
  9. 9

    Boss: Add and Search WordsBoss

    The island's final test: a word dictionary whose search allows '.' wildcards. A hashset cannot hash a wildcard, and a trie walk cannot pick just one child — at every '.', DFS must fan out across ALL children, and one success anywhere wins.

    Complete codeDebugCode orderMultiple choiceTrace
    8 exercises
    10 min
AlgoFox Pro

Trees & Graphs is part of AlgoFox Pro

You can read the whole course outline here. The exercises are in the app, along with your streak, your mistake review, and the progress that carries across your devices.

Pro starts with a 3 day free trial. The app store decides who is eligible for an introductory offer, and a lapsed subscription does not get another one.

Download AlgoFox on the App StoreGet AlgoFox on Google Play

Already subscribed in the app? Sign in with the same account and Pro works here too. Quick Play and Battle are free on the web, and so is the first course in every subject.