Iterative implementation of trie