Answer to Question #204497 in Python for Hshsksknrnwhehe

Question #204497

Hi, please help me with this one. Thank you. Question is below and link of photo. Needed it already. Thanks!


Determine the in-order, pre-order and post-order sequence. The link below is where the photo of this problem. Thank you!


https://www.bartleby.com/questions-and-answers/52-37-64-24-39-59-73-19-29-56-in-order-pre-order-post-order/100dd94b-74dc-49e0-a700-97b1a7f6afbd


1
Expert's answer
2021-06-08T23:47:27-0400
class Node:
    def __init__(self, key):
        self.left = None
        self.right = None
        self.val = key
 
 
# A function to do inorder tree traversal
def Inorder(root):
 
    if root:
 
        # First recur on left child
        Inorder(root.left)
 
        # then print the data of node
        print(root.val),
 
        # now recur on right child
        Inorder(root.right)
 
 
 
 
# A function to do preorder tree traversal
def Preorder(root):
 
    if root:
 
        # First print the data of node
        print(root.val),
 
        # Then recur on left child
        Preorder(root.left)
 
        # Finally recur on right child
        Preorder(root.right)
# A function to do postorder tree traversal
def Postorder(root):
 
    if root:
 
        # First recur on left child
        Postorder(root.left)
 
        # the recur on right child
        Postorder(root.right)
 
        # now print the data of node
        print(root.val),
 
 
#Tree
root = Node(52)
root.left = Node(37)
root.right = Node(64)
root.left.left = Node(24)
root.left.right = Node(39)
root.right.left = Node(59)
root.right.right = Node(73)
root.left.left.left = Node(19)
root.left.left.right = Node(29)
root.right.left.left = Node(56)


print ("\nInorder traversal of binary tree is")
Inorder(root)


print ("Preorder traversal of binary tree is")
Preorder(root)
 
 
print ("\nPostorder traversal of binary tree is")
Postorder(root)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS