Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 3 - I Persistent dynamic sets During the course of an algorithm, you sometimes find that you need to maintain past versions of a
I Persistent dynamic sets
During the course of an algorithm, you sometimes find that you need to maintain
past versions of a dynamic set as it is updated. We call such a set persistent. One
way to implement a persistent set is to copy the entire set whenever it is modi
fied, but this approach can slow down a program and also consume a lot of space.
Sometimes, you can do much better.
Consider a persistent set with the operations INSERT, Delete, and SEARCh,
which you implement using binary search trees as shown in Figure a Main
tain a separate root for every version of the set. In order to insert the key into the
set, create a new node with key This node becomes the left child of a new node
with key since you cannot modify the existing node with key Similarly, the
new node with key becomes the left child of a new node with key whose right
child is the existing node with key The new node with key becomes, in turn,
the right child of a new root with key whose left child is the existing node with
key Thus, you copy only part of the tree and share some of the nodes with the
original tree, as shown in Figure b
Assume that each tree node has the attributes key, left, and right but no parent.
See also Exercise on page
a For a persistent binary search tree not a redblack tree, just a binary search
tree identify the nodes that need to change to insert or delete a node.
Figure a A binary search tree with keys b The persistent binary search
tree that results from the insertion of key The most recent version of the set consists of the nodes
reachable from the root and the previous version consists of the nodes reachable from Blue
nodes are added when key is inserled.
b Write a procedure PersistentTreeInSert that, given a persistent
binary search tree and a node to insert, returns a new persistent tree
that is the result of inserting into Assume that you have a procedure
COPYNODE that makes a copy of node including all of its attributes.
c If the height of the persistent binary search tree is what are the time and
space requirements of your implementation of PERSISTENTTREEINSERT?
The space requirement is proportional to the number of nodes that are copied.
d Suppose that you include the parent attribute in each node. In this case, the
PersistentTREeINSERT procedure needs to perform additional copying.
Prove that PersistentTreeInSert then requires time and space,
where is the number of nodes in the tree.
e Show how to use redblack trees to guarantee that the worstcase running time
and space are per insertion or deletion. You may assume that all keys
are distinct.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started