Trie - detect cycles old implementation