Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON 3 PLEASE FOLLOW INSTRUCTIONS COMPLETE CODE Problem : Complete the functio

ID: 3710757 • Letter: P

Question

PYTHON 3 PLEASE FOLLOW INSTRUCTIONS

COMPLETE CODE

Problem :

Complete the function mirrorTree() to take in a root node of a tree and return another copy of the tree that is a mirror of the original one. Your function cannot modify the tree that is passed in.

This problem also requires that I must use a helper function with recursion as well.

CODE :

def mirrorTree(root):
new_root = Node(root.value)
assign_tree(root, new_root)
return new_root
  
def assign_tree(old_root, new_root):

An example of a mirrored tree is shown below: 3 2 2 3 5 4 4 5 Mirror Trees

Explanation / Answer

here is your solution : -------->>>>>>>>>>>

def mirrorTree(root):
new_root = Node(root.value)
assign_tree(root, new_root)
return new_root
  
def assign_tree(old_root, new_root):
    if old_root.left != None :
        new_node = Node(old_root.left.value)
        new_root.right = new_node
        assign_tree(old_root.left,new_root.right)
    if old_root.right != None :
        new_node = Node(old_root.right.value)
        new_root.left = new_node
        assign_tree(old_tree.right,new_root.left)