Examveda

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];

B. node = node.children[str.charAt(i + 1)];

C. node = node.children[index++];

D. node = node.children[index++];

Answer: Option A


Join The Discussion

Related Questions on Advanced Trees (AVL, RedBlack, BTrees)