| With a basic Trie, you always have this problem of how to keep the pointers at each node. Naively, you can: 1) Keep an array of size equal to the alphabet size, indexed by the characters, holding pointers to successive nodes. - but this blows the memory to O(N * alphabet_size) where N is the input size 2) Keep a linked list of pairs (character, pointer). - but this blows the lookup time to O(word_length * alphabet_size) 3) Keep something like an STL map<character, pointer>. - still suboptimal complexity of O(word_length * log alphabet_size) + it complicates the code + it dramatically increases the constant time per operation Or you research a bit more and actually learn a way to properly implement a trie, called a Ternary Search Tree:
http://en.wikipedia.org/wiki/Ternary_search_tree |