26.5 Exercises

Factual

  1. Suppose we use the following trie to represent a map. What would get("sea") return? What about get("sell")?

  1. Consider the Trie-based set below. What does keysWithPrefix("sp") return? What nodes does it visit during this call?

Problem 1

sea terminates at the node with value 6. sell does not exist in the trie (since it does not terminate at the node with l, so the get operation returns null.

Problem 2

keysWithPrefix follows the prefix to the final letter of the prefix, then performs DFS from that node to get all children.

During this procedure, it traverses the nodes s, p, i, t, e, y. The final return value is spit, spite, spy.

Problem 3

Metacognitive

Problem 1

Last updated