Question: COMP 3 3 3 BST Programming Project Part 3 In this part we will complete the BST program by adding the delete function. The function
COMP BST Programming Project Part In this part we will complete the BST program by adding the delete function. The function is complex mainly because of the number of cases to consider. Insert is naturally simpler because a newly inserted node has no child nodes and becomes the child node of an existing node, with no impact on any other nodes. In contrast, a deleted node can have both a parent node and child nodes, requiring any link broken by the deletion to be repaired. This gives rise to a large number of cases. The cases are somewhat similar, but each case requires a customized response. We will organize the cases with the help of a few helper functions to cover specific cases and subcases. TopLevel Function: Delete Value from BST: delete t v The first parameter t is a reference to a bst and the second parameter v is a value to find and delete. Like the insert function, delete will directly resolve a few special cases. For the general cases, it will call find t v to obtain a list of nodes that represent a path from the root to the node to be deleted, and will then call a helper function deletenode path to handle the rest of the work. In the case of delete the helper function will further rely on secondary helper functions to resolve cases and subcases. Deletion cases are based on the following considerations: is the deleted node the root of the tree, and how many child nodes the deleted node has. Looking ahead to testing, any code that has lots of cases will need a similar number of test cases, at least one test case for each deletion case. Delete Cases Before we look at the detailed code for delete in Racket, lets look at the general approach. As for some of the other functions, it will be convenient to create a toplevel function delete t v and several helper functions that manage specific detailed cases. There will be some initial special cases that should be managed separately, before launching any lower level helper function. Special cases for delete t v: Tree t is empty: end the function because there is nothing to do At this point, call find t v to create the path from root to node to delete if it is present. Assume the list returned is bound to a symbol named path The node of interest will be the first node in the list: car path By examining node car path you can determine if the value to delete is present or not. Value v is not in the tree: end the function because the
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
