IntermediateAbout 20 min

    Trie (Prefix Tree)

    Read the full article on Substack

    7 min read.

    Optimize prefix-based searches! Visualize how words are stored as a tree of characters. Key for autocomplete and spell checkers.

    Think of it this way: Think of autocomplete on your phone. As you type 'A-P-P', it narrows down the massive dictionary to just the branch containing 'Apple', 'Appetizer', etc. efficient prefix lookup.

    root

    Empty trie: just the root.

    1/25

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    Insert "cat"

    Sequence

    Order the steps of inserting the word "cat" into a trie.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Quiz

    21 questions
    Question 1 of 21
    Score: 0

    What is the Time Complexity of searching for a word of length L in a Trie?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going