Complete the code to create a new TrieNode when the character is not present.
if (!node.Children.ContainsKey(ch)) { node.Children[[1]] = new TrieNode(); }
The character ch is used as the key to add a new child node in the Trie.
Complete the code to move to the next node after inserting or finding the character.
node = node.[1][ch];The Children dictionary holds the next nodes for each character.
Fix the error in marking the end of a word after insertion.
node.[1] = true;The property IsWord is used to mark the node as the end of a valid word.
Fill both blanks to complete the insert method for the Trie.
public void Insert(string word) {
var node = root;
foreach (var ch in word) {
if (!node.Children.ContainsKey([1])) {
node.Children[[2]] = new TrieNode();
}
node = node.Children[ch];
}
node.IsWord = true;
}Both blanks require the current character ch to check and add the child node.
Fill all three blanks to complete the insert method with correct variable usage.
public void Insert(string word) {
var [1] = root;
foreach (var [2] in word) {
if (!node.Children.ContainsKey(ch)) {
node.Children[ch] = new TrieNode();
}
[3] = node.Children[ch];
}
node.IsWord = true;
}node is the current node, ch is the current character, and node is updated to the child node.
