December 2023
Intermediate to advanced
504 pages
11h 43m
English
These are the solutions to the exercises found in the section Exercises.
This trie stores the words: “tag”, “tan”, “tank”, “tap”, “today”, “total”, “we”, “well”, and “went”.
Here is a trie that stores the words “get”, “go”, “got”, “gotten”, “hall”, “ham”, “hammer”, “hill”, and “zebra”:

The following code starts at the trie’s node and iterates over each of its children. For each child, it prints the key and then recursively calls itself on the child node:
| | def traverse(self, node=None): |
| | current_node = node or self.root |
| | |
| | for key, child_node in current_node.children.items(): |
| | print(key) |
| | |
| | if key != "*": |
| | self.traverse(child_node) ... |
Read now
Unlock full access