Multiple paths through trees
I have a tree structure (root, internal nodes and leaves) and at each internal node I have recorded one or more values.
I want to be able to move from the root to the leaves and generate all possible paths through the tree. Im using recursion to move through the tree and processing each node individually.
i.e. where an internal node has two values I need to generate two paths and if the next node has only one value this is appended to each path and so on.
Therefore the number of possible paths is the product of the number of values at each node.
I have managed to code this but it is inefficient and generates an out of memory error when the number of potential paths through the tree is large (i.e. about 7 million)
I was wondering if anyone could suggest data structures or an api suitable for this type of problem.
Thanks in advance.