human
Can you provide a code to print Postorder traversal from given Inorder and Preorder traversals and the other steps required given the following:
Print Postorder traversal from given Inorder and Preorder traversals | Python3 program to prPostorder traversal from given Inorder and Preorder traversals ..
Find index of next item in preorder traversal in inorder ..
traverse left tree.
traverse right tree.
prroot node at the end of traversal.
Driver code"
Solution in Python:
assistant
#Here is code to print Postorder traversal from given Inorder and Preorder traversals and the other steps required.
 def printPost ( inn , pre , inStrt , inEnd ) :
	global preIndex , hm
	if ( inStrt > inEnd ) :
		return
	inIndex = hm [ pre [ preIndex ] ]
	preIndex += 1
	printPost ( inn , pre , inStrt , inIndex - 1 )
	printPost ( inn , pre , inIndex + 1 , inEnd )
	print ( inn [ inIndex ] , end = " ▁ " )
def printPostMain ( inn , pre , n ) :
	for i in range ( n ) :
		hm [ inn [ i ] ] = i
	printPost ( inn , pre , 0 , n - 1 )
if __name__ == ' _ _ main _ _ ' :
	hm = { }
	preIndex = 0
	inn = [ 4 , 2 , 5 , 1 , 3 , 6 ]
	pre = [ 1 , 2 , 4 , 5 , 3 , 6 ]
	n = len ( pre )
	printPostMain ( inn , pre , n )