Vidyalelo
Data Structure · Q69

Advanced Trees (AVL, RedBlack, BTrees)

Programming · Data Structure · question 69

Q69

Following code snippet is the function to insert a string in a trie. Find the missing line. 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;

A.
node = node.children[index];
Answer
B.
node = node.children[str.charAt(i + 1)];
C.
node = node.children[index++];
D.
node = node.children[index++];

Answer: Option A

Solution

Answer: Option A
No explanation is given for this question Let's Discuss on Board