Finally, let's try to delete from a Trie:
- Verify whether the given word is part of the Trie.
- If it is part of the Trie, then simply remove it.
Deletion takes place in a bottom-up manner using recursion and following these rules:
- If the given word is not in the Trie, then nothing happens (return false)
- If the given word is unique (not part of another word), then delete all corresponding nodes (return true)
- If the given word is a prefix of another long word in the Trie, then set the leaf node flag to false (return false)
- If the given word has at least another word as a prefix, then delete the corresponding nodes from the end of the given word until the first leaf node of the longest prefix word (return false)
In terms ...