Ternary Search Tries June 5, 2009 Several of our exercises (Mark
V. Shaney, Word Frequencies, Dodgson’s Doublets, Anagrams) have
used hash tables based on string keys. When the keys are
strings, a useful alternative to hash tables is a data structure
called a ternary search trie, which can be faster than a hash
table because it takes advantage of the fact that keys are
strings, and also provides in-order access to the keys. Ternary
search tries were introduced by Jon Bentley and Robert Sedgewick
at the 1997 SODA conference. As the name implies, ternary search
tries are a cross between binary search trees and radix tries.
Ternary search tries consist of recursive nodes and leaves, just
like binary search trees and radix tries. As the name implies, a
node of a ternary search trie has three children, one for lesser
children, one for greater children, and a third for equal
children. Searches proceed character-by-character, as with a
trie. At each level of the trie, the search compares the current
character of the