Question: Instructions: Given a node structure for compact trie: Node { String label; Node rightSibling; Node firstChild; bool isWord; } Write a code for prefix searching
Instructions:
Given a node structure for compact trie:
Node
String label;
Node rightSibling; Node firstChild; bool isWord;
Write a code for prefix searching a string in this trie. Node PrefixSearchNode root, String prefix will return a node which maximally matches.
Node PrefixSearchNode root, String prefix, String label
Node current root;
int index ;
while current null && index prefix.length
char c prefix.charAtindex;
if c is not in children nodes return false.. prefix does not exist in trie..
if currentlabel.charAt null
return null;
else shift current pointer to child pointer and continue searching
else
current current.firstChildc;
Return current when we reach end of word meaning there is a prefix that exists in the trie
return current;
Please use the pseduocode to help my code with the outlined tasks
Instructions #
Now extend the above code to output all the words which match the query prefix.
Instruction : Further, we can not use these node pointers and lists and just use hashtable to do parent child navigation:
class TrieNode String label;
bool isWord;
And a hashtable which maps a h:node char node. Thus, to find a child node of a current node which has a particular beginning character 'char' we use this hashtable. This allows us to jump from parent to child considering appropriate branch character.
Assuming that the Trie and HashTable are already built. Show how to change Node PrefixSearchNode root, String prefix to use hashtable.
Like in the earlier subpart, let's say the query string prefix ends up in an in between node. Is it easy to find out all the words which match this prefix?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
