All Root to Leaf Paths
Given a Binary Tree of size N, write a program that prints all the possible paths from root node to the all the leaf node's of the binary tree.
Let us the tree be like following:
All possible root to leaf paths in this tree is:
8->5->9 8->5->7->1 8->5->7->12->2 8->4->11->3
To print all the root to leaf paths we have used recursive approach.
The idea is to maintain a list of nodes on the paths and to print the list while leaf node is reached.
Input binary tree root, list a
In the main function create an empty list a, And call printpathrecursively(root, a);
Example with explanation:
Nodes are represented by their respective values.
You can do rest by your own to have much more clear idea about how the program is actually working.