Print all root to leaf paths of an N | ''Structure of an N ary tree node ; ''Function to print the root to leaf path of the given N-ary Tree ; '' Print elements in the vector ; ''Utility function to print all root to leaf paths of an Nary Tree ; '' If root is null ; ' ' ▁ Insert ▁ current ▁ node ' s data into the vector ; '' If current node is a leaf node ; '' Print the path ; '' Pop the leaf node  and return ; '' Recur for all children of  the current node ; '' Recursive Function Call ; ''Function to print root to leaf path ; '' If root is null, return ; '' Utility function call ; ''Driver Code ; '' Given N-Ary tree ; '' Function Call
class Node : NEW_LINE INDENT def __init__ ( self , x ) : NEW_LINE INDENT self . data = x NEW_LINE self . child = [ ] NEW_LINE DEDENT DEDENT def printPath ( vec ) : NEW_LINE INDENT for ele in vec : NEW_LINE INDENT print ( ele , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT def printAllRootToLeafPaths ( root ) : NEW_LINE INDENT global vec NEW_LINE if ( not root ) : NEW_LINE INDENT return NEW_LINE DEDENT vec . append ( root . data ) NEW_LINE if ( len ( root . child ) == 0 ) : NEW_LINE INDENT printPath ( vec ) NEW_LINE vec . pop ( ) NEW_LINE return NEW_LINE DEDENT for i in range ( len ( root . child ) ) : NEW_LINE INDENT printAllRootToLeafPaths ( root . child [ i ] ) NEW_LINE DEDENT vec . pop ( ) NEW_LINE DEDENT def printRootToLeafPaths ( root ) : NEW_LINE INDENT global vec NEW_LINE if ( not root ) : NEW_LINE INDENT return NEW_LINE DEDENT printAllRootToLeafPaths ( root ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT vec = [ ] NEW_LINE root = Node ( 1 ) NEW_LINE root . child . append ( Node ( 2 ) ) NEW_LINE root . child . append ( Node ( 3 ) ) NEW_LINE root . child [ 0 ] . child . append ( Node ( 4 ) ) NEW_LINE root . child [ 1 ] . child . append ( Node ( 5 ) ) NEW_LINE root . child [ 1 ] . child . append ( Node ( 6 ) ) NEW_LINE root . child [ 1 ] . child [ 1 ] . child . append ( Node ( 7 ) ) NEW_LINE root . child [ 1 ] . child [ 1 ] . child . append ( Node ( 8 ) ) NEW_LINE printRootToLeafPaths ( root ) NEW_LINE DEDENT