码迷,mamicode.com
首页 > 其他好文 > 详细

CSI 403 Data Structures and Algorithms

时间:2019-11-24 19:36:57      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:height   ble   RoCE   ali   com   pos   sse   each   its   


CSI 403 Data Structures and Algorithms Fall 2019
Homework IV Hurd
Problem 1 [25 pts]:
Given the sequence of numbers: 20, 7, 34, 29, 43, 40, 8, 12, 30, 42
a) [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 explain
the steps taken in deleting the root according to the delete procedure we discussed in
class.
c) [9 pts] Can you reorder the original sequence of numbers to obtain a tree of a smaller
height? If, yes, show the permutation of the sequence and the new tree. If no, argue why a
smaller height is not obtainable.
Problem 2 [25 pts]:
We discussed a delete operation that if necessary, swaps with a successor of the deleted node
when the deleted node has two children.
a) [8 pts] Argue that swapping one can also swap with the predecessor, and that it will result
in a correct BST, once the predecessor is spliced out.
b) [2 pts] Demonstrate the delete operation with predecessor swap on the example from
Q1(a) by deleting the root 20. Show the resulting tree?
c) [15 pts] Swapping predecessor and successors may result in a relatively balanced tree.
CSI 403作业代做
Provide the pseudo code of a procedure that in case where both children of the node to be
deleted 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 we
want to search for the key value 363. For each of the following sequences, indicate whether or
not it can be a valid sequence of nodes examined during the search. If the sequence is valid, draw
the search path clearly indicating whether a node is the left child or the right child of its parent. If
the 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 deleting
key 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.

因为专业,所以值得信赖。如有需要,请加QQ99515681  微信:codehelp

CSI 403 Data Structures and Algorithms

标签:height   ble   RoCE   ali   com   pos   sse   each   its   

原文地址:https://www.cnblogs.com/blogjava2/p/11923371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!