Learn
Now that you have finished constructing your trie data structure, in this exercise, you will get a chance to see it in action.
In the following checkpoints, you will add strings, search for strings, and count prefixes.
Instructions
1.
Create an instance of a Trie
and call it trie
.
2.
Using a Trie
method, add the following list of words to the trie:
words = ["AMBER", "ALICE", "AMPLE", "BALLOON", "BALL", "BLAST", "BAND", "DENSE", "DUTCH", "DECK", "DANCE", "DRAMA", "MESS", "MAVERICK", "MAVEN", "PHYSICS", "PHONE", "PHANTOM", "PASS", "PEAK", "PACK", "ZEST", "ZEAL", "ZAP", "ZIP", "ZIPPER"]
3.
Given the following list of words, use a Trie
method to print the ones that exist in the trie:
more_words = ["APPLE", "AMPLIFIER", "AMPLE", "BALLOON", "BALL", "DART", "DUTCH", "DECK", "DRAM", "FLAG", "MOP", "MAVERICK", "MANSION", "PHYSICS", "PHONE", "PHANTOM", "PASS", "PECK", "PAIN", "ZAM", "ZEST", "ZAP", "ZIP", "ZEBRA"]
4.
Given the following list of prefixes, use a Trie
method to print the count of each one:
prefix = ["A", "AM", "B", "BALL", "BA", "C", "CA" "DUTCH", "DECK", "GA", "J", "MA", "P", "PH", "PE", "Z", "ZIP"]
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.