讲解:CSI 403、Data Structures、Python,c/c++,JavaPython|Prolog

CSI 403 Data Structures and Algorithms Fall 2019Homework IV HurdProblem 1 [25 pts]:Given the sequence of numbers: 20, 7, 34, 29, 43, 40, 8, 12, 30, 42a) [7 pts] Show the resulting BST after inserting the numbers as keys.b) [9 pts] What will be the resulting tree if you delete the root? Show the tree and explainthe steps taken in deleting the root according to the delete procedure we discussed inclass.c) [9 pts] Can you reorder the original sequence of numbers to obtain a tree of a smallerheight? If, yes, show the permutation of the sequence and the new tree. If no, argue why asmaller height is not obtainable.Problem 2 [25 pts]:We discussed a delete operation that if necessary, swaps with a successor of the deleted nodewhen the deleted node has two children.a) [8 pts] Argue that swapping one can also swap with the predecessor, and that it will resultin a correct BST, once the predecessor is spliced out.b) [2 pts] Demonstrate the delete operation with predecessor swap on the example fromQ1(a) by deleting the root 20. Show the resulting tree?c) [15 pts] Swapping predecessor and successors may result in a relatively balanced tree.Provide the pseudo code of a CSI 403代做、Data Structures代做、Pyprocedure that in case where both children of the node to bedeleted exist:a. swaps with the predecessor if the left subtree of the deleted node is larger(contains more nodes) than the right subtree,b. swaps with the successor otherwise,The procedure should work as the original delete operation for the cases of zero or one children.Problem 3 [25 pts]:Suppose we have integer key values between 1 and 1000 stored in a binary search tree and wewant to search for the key value 363. For each of the following sequences, indicate whether ornot it can be a valid sequence of nodes examined during the search. If the sequence is valid, drawthe search path clearly indicating whether a node is the left child or the right child of its parent. Ifthe sequence is invalid, explain why it cannot arise in the search.a) [12.5 pts] 2, 399, 387, 219, 266, 382, 381, 278, 363.b) [12.5 pts] 935, 278, 347, 621, 299, 392, 358, 363.Problem 4 [25 pts]:Is the delete (remove) operation on a binary search tree \commutative in the sense that deletingkey x and then y leaves the same tree as deleting y and then x? If the operation is commutative,explain why. If not, provide a counter example.转自:http://www.6daixie.com/contents/13/4452.html

你可能感兴趣的:(讲解:CSI 403、Data Structures、Python,c/c++,JavaPython|Prolog)