Bad Trie and Ternary Search Tree implementation