What is the role of count and how it is getting updated in the code?
Search in trie problem
count will tell that if a particular children is present or not. It was being updated when you were building the trie. Please refer the video again for more clarity.
i am a bit confused. can u explain that count part with an example
Suppose your trie is R->A->C->E and you want to search for word RAT. count of a node will store the count of children of that node. So while building the trie for RACE count for each node will get updated.
when temp pointer(according to the code) is at R , temp->children.count(‘A’) will be 1 , for all other character the count will be zero. Similarly when temp pointer moves to ‘A’ , temp->children.count(‘C’) will be 1 and so on.
So when you search for RAT in the trie, you will have to check the child count at each node for the given search word. So while searching RAT in RACE. when your temp pointer reaches A… you check that if temp->children.count(‘T’) is 1 or not. Since it is 0, you can say that search word is not present.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.