Top | MCQs on Graph Data Strcuture with Answers | Question 36
The following code snippet is the function to insert a string in a trie. Find the missing line.
Java
private void insert(String str){
TrieNode node = root;
for ( int i = 0 ; i < length; i++){
int index = key.charAt(i) - 'a' ;
if (node.children[index] == null )
node.children[index] = new TrieNode();
________________________
}
node.isEndOfWord = true ;
}
|
b)
c)
d)
(A)
node = node.children[index];
(B)
node = node.children[str.charAt(i + 1)];
(C)
node = node.children[index++];
(D)
node = node.children[index++];
Answer: (A)
Explanation:
Quiz of this Question
Please comment below if you find anything wrong in the above post
Last Updated :
23 May, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...