Module 11 · Trie · Trie Operations and Applications

Matching and deletion in a trie

The Trie from Trie Operations gets two recursive methods. match works like search, but a . in the pattern matches any letter, so there it tries every child until one works. delete goes down to the word's last letter, takes its double ring away, and on the way back up removes every node that no other word needs.

In the trie each node holds one letter (the root none), and a double ring marks a node where a word ends. word is the word of the current call, with the pointer at the letter the current recursive call looks at.