Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
Question
Book Icon
Chapter 13, Problem 1P

(a)

Program Plan Intro

To explain the nodes that needs to change to insert a key k or delete a node y .

(a)

Expert Solution
Check Mark

Explanation of Solution

For the insertion of the key k in the tree it first checks the ancestors of the tress then it traverses the children of that ancestor. The insertion causes some misbalancing situation so the tree needs to maintain the property of tree by changing the nodes.

The deletion of a node y is done by checking the children of the node y and the successor of the node y so that their children are placed into suitable node after deletion of the parent node y.

So, for the efficient execution of the operations it needs some changing in the ancestors of the node to accept the change by the insertion or deletion.

(b)

Program Plan Intro

To gives an algorithm for insertion in persistent tree.

(b)

Expert Solution
Check Mark

Explanation of Solution

The algorithm for insertion in persistent tree is given below:

PERSISTENT-TREE-INSERT( T,k )

  x=T.root .

if x==NIL then

  T.root=newnode(k) .

end if.

while xNIL do

  y=x .

if k!=x.key then

  x=x.left.y.left=copyof(x).

else

  x=x.right.y.right=copyof(x).

end if.

end while.

  z=newnode(k,y) .

if k!=y.key then

  y.left=z .

else

  y.right=z .

end if.

end.

The algorithm is used to insert a key k into the node. The algorithm checks the value of the nodes of the tree and then finds the suitable place to insert the key by comparing the value of key with the nodes of the tree.

The algorithm performs the insertion in such a way that it consider the root and start visiting the node of similar depth then it copy the nodes and then make new version of the tree with old and key k .

(c)

Program Plan Intro

To explain the space required for the implementation of PERSISTENT-TREE-INSERT.

(c)

Expert Solution
Check Mark

Explanation of Solution

The algorithm consists of the while loop that runs h times as the height of the tree and the value of the x is increased by 1 with bounded h.

The iterations of the algorithm run in constant time as they are just simple iteration or conditional iteration. For the purpose of storing all the h it needs some additional space equals to h .

Thus, the space and time required for the algorithm is depends upon the h and equals to O(h) .

(d)

Program Plan Intro

To prove that the PERSISTENT-TREE-INSERT would require Ω(n) time and space.

(d)

Expert Solution
Check Mark

Explanation of Solution

The insertion of the a key into tree by using above algorithm is based on the fact that it first copy the original tree then it find the appropriate position for key and insert the key by addition key on the original tree.

The node that points to the appropriate position will copy and then it copy the ancestor of the node and so on until it copy all the connected nodes of the tree

The copying of a node takes constant time and one storage space for each node but there are total n nodes in the tree so it takes total time of n .

Thus, the algorithm takes total of Ω(n) time as well as space.

(e)

Program Plan Intro

To explain the worse-case running time and space is O(lgn) per insertion and deletion in RB-tree.

(e)

Expert Solution
Check Mark

Explanation of Solution

The insertion or deletion of the key into tree cause dis-balancing in the tree so it needs to maintain the tree by changing the ancestors and children of the ancestors.

The algorithm allocates space of 2h for iteration so it only changes to the nodes equal to 2h and the other nodes are remains same.

For the finding the appropriate position it need to compare and check the values of node and for worse case it is equal to total nodes in 2h that is order of h .

The operation is considering the ancestor of the node where the key is going to be inserted or deleted, the node with their children and ancestors are considered that is another subtree and for the worse case the height of that subtree is equal to the height of tree that is lgh or lgn .

Therefore, the total space and time requires for the operation is equals to O(lgn) .

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Suppose there are two singly linked lists both of which intersect at some point and become a single linked list. The head or start pointers of both the lists are known, but the intersecting node is unknown. Also, the number of nodes in each of the list before they intersect are unknown and both the list may have it different.  List1 may have  n nodes before it reaches intersection point and  List2 might have  m nodes before it reaches intersection point where  m and  n may be  m =  n,  m >  n or  m <  n. Give an algorithm for finding the merging point.   Hints: A brute force approach would be to compare every pointer in one list with every pointer in another list.  But in this case the complexity would be O(mn)
Given a singly linked list, print reverse of it using a recursive function printLinkedList( node *first ) where first is the pointer pointing to the first data node. For example, if the given linked list is 1->2->3->4, then output should be: 4 3 2 1 (note the whitespace in between each data value)
The general utility of numbering with collections  The use of integer index values to access objects in a collection is something that we will see over and over again—not just with ArrayLists but also with several different types of collections. So it is important to understand what we have seen of this so far: that the index values start at zero; that the objects are numbered sequentially; and that there are usually no gaps in the index values of consecutive objects in the collection.  Using integer values as indices also makes it very easy to express in program code expressions such as “the next item” and “the previous item” with respect to an item in the collection. If an item is at index p, then “the next” one will be at index (p+1) and “the previous” one is now at index (p–1). We can also map natural-language selections such as “the first three” to program-related terminology. For example, “the items at indices 0, 1, and 2” or “the last four” could be “the items at indices…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning