I have a fully built generic Trie in java. I am trying to traverse through the Trie to obtain all the complete combinations for each path. For example, if the Trie contained chars then it would return all the word combinations. For my purposes, I am trying to put all the nodes for each combination into an array and return them. I am stumped however. I only came up with the traversal that goes through each child (+ subchildren) before going back to the parent/starting node (much like a BST traversal). I am using an ArrayList to hold the children for each node. Sorry if it is a bit confusing. A code sample or pseudo code will be much appreciated. Thanks.
EDIT
By combinations, I mean the following. If I had a Trie<char> that looked like the following:
"null"
/ | \
a i t
/ /|\ \
t f m n o
The combinations that I would want returned would be:
[a, t]
[i, f]
[i, m]
[i, n]
[t, o]
and all these arrays/lists could be in one single ArrayList which is returned at the end.
Do a recursive method to (at least) get all the chars in the tree. Just make sure you initialize the
charsas an empty Listwith this you will have a return value of a Stack consisting Lists of value for each combination.
Hope this helps. 🙂