Question: PYTHON 3 PLEASE FOLLOW INSTRUCTIONS COMPLETE CODE Problem : Complete the function deleteNode() to take in a root node of a tree and a value

PYTHON 3 PLEASE FOLLOW INSTRUCTIONS

COMPLETE CODE

Problem : Complete the function deleteNode() to take in a root node of a tree and a value of a node that is in the tree, and delete that node. (The tree is a binary search tree)

CODE:

class Node: def __init__(self, value): self.value = value self.left = None self.right = None def deleteNode(root, value): (node, parent) = findNodeAndParent(root, value)

def findNodeAndParent(root, target, parent=None): # DO NOT MODIFY if root is None: return (None, None) if root.value == target: return (root, parent)

if target < root.value: return findNodeAndParent(root.left, target, root) return findNodeAndParent(root.right, target, root) def findMinAndParent(root): # DO NOT DELETE OR MODIFY if root.left is None: return (root, None) if root.left.left is None: return (root.left, root) return findMinAndParent(root.left)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!