There are two very common structures used for trie nodes:
CharNode
char letter
CharNode[26] children
CharNode
char letter
Dictionary<char, CharNode> children
Those work well, but they waste a huge amount of memory because the list of children is remarkably sparse. In my opinion, neither gives a performance benefit that offsets the memory cost. I prefer to use:
CharNode
char letter
CharNode[] children
or
CharNode
char letter
CharNode* firstChild
CharNode* sibling
In the first case, the children
array is variably sized to hold just the number of children actually used, and the children are arranged with the most frequently used letter first. Sequential search finds the required child.
In the second case, you have a linked list of children, and each child has a sibling pointer. Again, children are arranged in the list based on frequency.
I prefer the second, because in many runtime environments the cost of allocating an array is pretty high. In .NET, for example, array allocation overhead is on the order of 50 bytes. Considering that a trie node often has fewer than five children, the array allocation overhead is larger than the data that the array holds. With the linked list arrangement, you don't waste any memory.
Sequential search of the small child list is very fast, because the list of children to search is usually very short and the distribution of letter frequencies is usually very skewed. That is, the first two children usually are used far more frequently than the rest. So on average you'll only have to search two or three child nodes.
Either of these saves a huge amount of memory, which can make for a faster program. My tests haven't shown an appreciable performance hit in going with these alternate structures.