Question: I need help on this python code just the parts where it says #your code here. I can not edit the last 3 screenshots (or

I need help on this python code just the parts where it says #your code here. I can not edit the last 3 screenshots (or last 2 code blocks) because they are just test cells.

I need help on this python code just the parts where itsays #your code here. I can not edit the last 3 screenshots(or last 2 code blocks) because they are just test cells. \#TODO:Complete the insert algorithm below \# To insert first search for itand find out \# the parent whose child the currently inserted keywill be. \# Create a new node with that key and insert.

\#TODO: Complete the insert algorithm below \# To insert first search for it and find out \# the parent whose child the currently inserted key will be. \# Create a new node with that key and insert. \# return None if key already exists in the tree. \# return the new node corresponding to the inserted key otherwise. def insert (self, key): \# your code here \# TODO: Complete algorithm to compute height of the tree \# height of a node whose children are both None is defined \# to be 1 . \# height of any other node is 1 + maximum of the height \# of its children. \# Return a number that is th eheight. def height (self): \# your code here \#TODO: Write an algorithm to delete a key in the tree. \# First, find the node in the tree with the key. \# Recommend drawing pictures to visualize these cases below before \# programming. \# Case 1: both children of the node are None \# .. in this case, deletion is easy: simply find out if the node with key is its \# parent's left/right child and set the corr. child to None in the parent node. \# Case 2: one of the child is None and the other is not. \# . - replace the node with its only child. In other words, \# modify the parent of the child to be the to be deleted node's parent. \# also change the parent's left/right child appropriately. \# Case 3: both children of the parent are not None. \# -- first find its successor (go one step right and all the way to the left). \# -. function get_leftmost_descendant may be helpful here. \# -. replace the key of the node by its successor. \# -- delete the successor node. \# return: no return value specified def delete(self, key): (found, node_to_delete) = self.search(key) assert(found == True), f"key to be deleted: {key}-does not exist in the tree" \# your code here print('- Testing height '.) assert t1. height() ==4, 'test 18 failed' assert t4.height() ==3, 'test 19 failed' assert t2.height() == 2 , 'test 20 failed' print('Success: 15 points.') 4 \# Testing deletion t1 = Node(16, None) \# insert the nodes in the list lst =[18,25,10,14, 8 , 22 , 17 , 12] for elt in lst: t1. insert(elt) \# The tree should Look Like this \# \# \# \# \# \# \#

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!