Data Structures · Search trees and balanced trees
Consider BST deletion of a node z
Problem
Consider BST deletion of a node \(z\). Case 0: \(z\) has no children. Case 1: \(z\) has exactly one child. Case 2: \(z\) has two children. Write complete pseudocode \(\mathrm{TREE}\text{-}\mathrm{DELETE}(T, z)\) that handles all three cases, using parent pointers, and that in Case 2 replaces \(z\)'s key by its successor \(y\) and then splices \(y\) out of the tree (\(y\) has no left child). Prove that after \(\mathrm{TREE}\text{-}\mathrm{DELETE}\), the BST property holds on the remaining keys. Your proof must treat Case 2 separately and must argue that moving \(y\)'s key into \(z\)'s node cannot violate the BST property at \(z\) or at any ancestor of \(z\).
Hint
Zero- and one-child deletions are splices: the parent of \(z\) is rewired to \(z\)’s unique child (or to \(\mathrm{NIL}\)). Two-child deletion cannot splice \(z\) without losing a subtree.
Check your work
Work the problem yourself first. Then open it in Training to check your answer and read the full worked solution.
The answer check and full solution for this problem come with ProofAnvil Practice membership ($19 USD monthly). See membership. Or start with the free Data Structures sample problem: Try the free sample problem.
More Data Structures practice problems
- Let V be a dynamic array of n elements stored in a buffer of capacity c, with the…Abstract data types, representation, and invariants
- A ring buffer (circular array) of fixed capacity C≥ 1 stores a sequence of at most C…Abstract data types, representation, and invariants
- Let L be the doubly linked list with values [10, 20, 30, 40, 50], and let I be a…Arrays, linked structures, stacks, queues, and amortization
- Let T be a BST whose nodes contain only key, left, and right fields (no parent…Search trees and balanced trees
- Consider a hash table T of size m = 11 that resolves collisions by chainingHash tables and probabilistic performance
- Throw n balls independently and uniformly into n binsHash tables and probabilistic performance
- `Bubble-Down`(A,i,n) is specified as follows on a 1-based array that is a complete…Heaps, priority queues, and disjoint sets
- The fat-node method of partial persistence stores, in each field of each node, a…Graph representations and traversals
- A duplicate minimum must sit on the min-stack, or one pop forgets the otherArrays, linked structures, stacks, queues, and amortization