All lessonsOpen Open Open Open Open
11. DP, Greedy & Tries
Tries (prefix trees)
0 of 5 activities0%
Reading 1
Character by character
A trie node has up to Σ children (e.g., 26 letters) and a flag isEnd.
Insert/search walk character links. Great for autocomplete and word dictionaries.
Space can be large; compressed tries exist.
struct TrieNode {
TrieNode* next[26];
bool end;
};Check 2
Strength
Tries excel at
Fill in 3
Also called
Try it 4
Prefix check
Does "app" share prefix with "apple"?
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Starts with
Read word and prefix. Print yes if word starts with prefix, else no.
main.cpp
Loading editor…