Search in a Trie
This lesson defines the algorithm for a word search in a trie. It also highlights the different scenarios which are taken care of in the algorithm.
Search Algorithm #
If we want to check whether a word is present in the trie or not, we need to keep tracing the path in the trie corresponding to the characters in word.
The logic isn’t too complex, but there are a few cases we need to take care of.
Case 1: Non-Existent Word #
If we are searching for a word that doesn’t exist in the trie and is not a subset of any other word, by principle, we will find NULL
before the last character of the word can be found.
For a better understanding, check out the illustration below:
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.