Deletion in a Trie
This lesson defines all the cases needed for deleting a word in Trie, along with implementing this functionality in Java.
Deleting a word in Trie #
While deleting a word from a Trie, we make sure that the node that we are trying to delete does not have any further branches. If there are no branches, then we can easily remove the node. However, if the node
contains further branches then this opens up a lot of the scenarios covered below.
Case 1: If the word to be deleted has no common subsequence #
- If the word to be deleted has no common subsequence, then all the nodes of that word are deleted.
For example, in the figure given below, we have to delete all characters of “bat” in order to delete the word bat
.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.