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):
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)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.