联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2019-11-23 10:46

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.

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.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp