ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CSI 403 Data Structures and Algorithms

2019-11-24 18:56:23  阅读:528  来源: 互联网

标签:predecessor search sequence pts tree 403 Algorithms Structures delete



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.

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

标签:predecessor,search,sequence,pts,tree,403,Algorithms,Structures,delete
来源: https://www.cnblogs.com/blogjava2/p/11923371.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有