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
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
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.
Algorithm:
Pre-requisite:
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.
C++ Implementation:
Output