Add traversal function for tries