using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
trie.Insert("Naveeen_Jun");
trie.Insert("Naveeen Snr");
trie.PrintAllChildren("Nav");
public Dictionary<char, TrieNode> children;
children = new Dictionary<char, TrieNode>();
public void Insert(string word)
for(int i = 0; i < word.Length; i++)
if(!cur.children.ContainsKey(word[i]))
cur.children.Add(word[i], new TrieNode());
cur = cur.children[word[i]];
public bool Search(string word)
for(int i = 0; i < word.Length; i++)
if(!cur.children.ContainsKey(word[i]))
cur = cur.children[word[i]];
public bool StartsWith(string prefix)
for(int i = 0; i < prefix.Length; i++)
if(!cur.children.ContainsKey(prefix[i]))
cur = cur.children[prefix[i]];
public void PrintAllChildren(string prefix)
foreach(char c in prefix)
if(cur.children.ContainsKey(c))
List<string> result = new List<string>();
Helper(prefix, result, cur);
foreach(string s in result)
Console.WriteLine("{0}", s);
private void Helper(string input, List<string> result, TrieNode cur)
foreach(KeyValuePair<char, TrieNode> pair in cur.children)
Helper(input + pair.Key, result, pair.Value);