Question: During the course of an algorithm, we sometimes find that we need to maintain past versions of a dynamic set as it is updated. Such
Figure 13.8: (a) A binary search tree with keys 2, 3, 4, 7, 8, 10. (b) The persistent binary search tree that results from the insertion of key 5. The most recent version of the set consists of the nodes reachable from the root r′, and the previous version consists of the nodes reachable from r heavily shaded nodes are added when key 5 is inserted. Assume that each tree node has the fields key, left, and right but no parent field. (See also Exercise 13.3-6.)
a. For a general persistent binary search tree, identify the nodes that need to be changed to insert a key k or delete a node y.
b. Write a procedure PERSISTENT-TREE-INSERT that, given a persistent tree T and a key k to insert, returns a new persistent tree T′ that is the result of inserting k into T.
c. If the height of the persistent binary search tree T is h, what are the time and space requirements of your implementation of PERSISTENT-TREE-INSERT? (The space requirement is proportional to the number of new nodes allocated.)
d. Suppose that we had included the parent field in each node. In this case, PERSISTENT-TREE-INSERT would need to perform additional copying. Prove that PERSISTENT-TREE-INSERT would then require Ω (n) time and space, where n is the number of nodes in the tree.
e. Show how to use red-black trees to guarantee that the worst-case running time and space are O (lg n) per insertion or deletion.
21 10 10 (a) (b)
Step by Step Solution
3.45 Rating (158 Votes )
There are 3 Steps involved in it
a When inserting key k all nodes on the path from the root to the added node a new leaf must change since the need for a new child pointer propagates up from the new node to all of its ancestors When ... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
C-S-A (97).docx
120 KBs Word File
