I have a list:
B={423, {{53, {39, 65, 423}}, {66, {67, 81, 423}}, {424, {25, 40, 423}}}};
This list can be visualized as a tree using TreeForm[B]:
![TreeForm[B]](../../images/6469ae0addd5499786e6083c1b7f57fe.webp)
and I would like to find all possible traversals of this tree:
{{423,53,39},{423,53,65},{423,53,423},{423,66,67},{423,66,81},
{423,66,423},{423,424,25},{423,424,40},{423,424,423}}
It seems that Subset might be usable, but when I tried Subset[B,{3}], it gave me the null set. Another possible problem with Subset is that it perhaps does not respect the leveling of the tree. I looked at the Combinatorica package, but I don't see a way to traverse the tree -- in the direction from top to bottom -- in all possible ways.