human
What is a code to print path from root to all nodes in a Complete Binary Tree and the other steps required given the following:
Print path from root to all nodes in a Complete Binary Tree | Function to print path of all the nodes nth node represent as given node kth node represents as left and right node.
base condition if kth node value is greater then nth node then its means kth node is not valid so we not store it into the res simply we just return.
Storing node into res.
Print the path from root to node.
store left path of a tree So for left we will go node ( kThNode * 2 ).
right path of a tree and for right we will go node ( kThNode * 2 + 1 ).
Function to print path from root to all of the nodes.
res is for store the path from root to particulate node.
Print path from root to all node . third argument 1 because of we have to consider root node is 1.
Driver Code.
Given Node.
Print path from root to all node ."
Solution in Python:
assistant
#Here is code to print path from root to all nodes in a Complete Binary Tree and the other steps required.
 def printPath ( res , nThNode , kThNode ) :
	if kThNode > nThNode :
		return
	res . append ( kThNode )
	for i in range ( 0 , len ( res ) ) :
		print ( res [ i ] , end = " ▁ " )
	print ( )
	printPath ( res [ : ] , nThNode , kThNode * 2 )
	printPath ( res [ : ] , nThNode , kThNode * 2 + 1 )
def printPathToCoverAllNodeUtil ( nThNode ) :
	res = [ ]
	printPath ( res , nThNode , 1 )
if __name__ == " _ _ main _ _ " :
	nThNode = 7
	printPathToCoverAllNodeUtil ( nThNode )