pass # nothing to remove else if x.key < root.item.key: root.left <- TREE-DELETE(root.left, x) else if x.key > root.item.key: root.right <- TREE-DELETE (root.right, x) # х.key if root.left is NIL: root <- root.right else: == root.item.key so Remove root.item. # NIL if both children missing else if root.right is NIL: root <- root.left else: # Root has two children: remove element with smallest key in right subtree and # move it to root. Assumption: DELETE-MIN returns two values: element removed # from right subtree and root of resulting subtree (in case root.right changes). root.item, root.right <- DELETE-MIN(root.right) return root DELETE-MIN(root): # Remove element with smallest key in root’s subtree; # return element removed and root of resulting subtree. if root.left is NIL: # Root stores item with smallest key; replace with right child. return root.item, root.right else: # Left subtree not empty: root not the smallest. item, root.left <- DELETE-MIN(root.left) return item, root

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
TREE-DELETE(root, x):
should not happen!
# x.key not in S
# nothing to remove
if root is NIL:
pass
else if x.key < root.item.key:
root.left <- TREE-DELETE(root.left, x)
else if x.key > root.item.key:
root.right <- TREE-DELETE (root.right, x)
# x.key
if root.left is NIL:
root <- root.right
else if root.right is NIL:
else:
root.item.key so Remove root.item.
==
# NIL if both children missing
root <- root.left
else:
# Root has two children: remove element with smallest key in right subtree and
# move it to root. Assumption: DELETE-MIN returns two values: element removed
# from right subtree and root of resulting subtree (in case root.right changes).
root.item, root.right <- DELETE-MIN(root.right)
return root
DELETE-MIN (root):
# Remove element with smallest key in root's subtree;
# return element removed and root of resulting subtree.
if root.left is NIL:
# Root stores item with smallest key; replace with right child.
return root.item, root.right
else:
# Left subtree not empty: root not the smallest.
item, root.left <- DELETE-MIN(root.left)
return item, root
Transcribed Image Text:TREE-DELETE(root, x): should not happen! # x.key not in S # nothing to remove if root is NIL: pass else if x.key < root.item.key: root.left <- TREE-DELETE(root.left, x) else if x.key > root.item.key: root.right <- TREE-DELETE (root.right, x) # x.key if root.left is NIL: root <- root.right else if root.right is NIL: else: root.item.key so Remove root.item. == # NIL if both children missing root <- root.left else: # Root has two children: remove element with smallest key in right subtree and # move it to root. Assumption: DELETE-MIN returns two values: element removed # from right subtree and root of resulting subtree (in case root.right changes). root.item, root.right <- DELETE-MIN(root.right) return root DELETE-MIN (root): # Remove element with smallest key in root's subtree; # return element removed and root of resulting subtree. if root.left is NIL: # Root stores item with smallest key; replace with right child. return root.item, root.right else: # Left subtree not empty: root not the smallest. item, root.left <- DELETE-MIN(root.left) return item, root
2. BST Deletion Average Case
(b) We are interested in the total number of calls to TREE-DELETE and DELETE-MIN that will
be performed to delete nodes from this tree. The code for these functions is distributed with
this test in the file bst-deletions.pdf. It is also the same code that was taught in week 3
lectures.
How
many
calls would be made to these two functions (in total) if we deleted 2?
(c) How many calls will be made to these functions if we deleted 5 (from the original tree that
still holds the 2)?
(d) Assume now that we will randomly select one node from the tree for deletion. Assume that
the probability of selecting the 7 is and the probability of selecting the 8 is . The other
nodes in the tree are equally likely to be selected for deletion and the probability of calling
delete on a node that is not in the tree is 0. Calculate the average-case number of total calls
to TREE-DELETE and DELETE-MIN. Show
your
work.
Transcribed Image Text:2. BST Deletion Average Case (b) We are interested in the total number of calls to TREE-DELETE and DELETE-MIN that will be performed to delete nodes from this tree. The code for these functions is distributed with this test in the file bst-deletions.pdf. It is also the same code that was taught in week 3 lectures. How many calls would be made to these two functions (in total) if we deleted 2? (c) How many calls will be made to these functions if we deleted 5 (from the original tree that still holds the 2)? (d) Assume now that we will randomly select one node from the tree for deletion. Assume that the probability of selecting the 7 is and the probability of selecting the 8 is . The other nodes in the tree are equally likely to be selected for deletion and the probability of calling delete on a node that is not in the tree is 0. Calculate the average-case number of total calls to TREE-DELETE and DELETE-MIN. Show your work.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY