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
In this programming exercise you will implement two functions. The first function will prompt the user for a file containing the number of vertices and entries of the adjacency matrix of a graph. It will return a two-dimensional list (a list of lists) containing the adjacency matrix. The second function will take as input the a two-dimensional list that represents the adjacency matrix of a graph, runs Prim's algorithm, and returns the list of edges in a minimal spanning tree and the total weight of the spanning tree. I have figured out the first part of the program. i need help with the second part. Thanks text file    80 1 2 3 100 100 100 1001 0 2 100 3 4 100 1002 2 0 4 4 100 5 1003 100 4 0 100 100 4 100100 3 4 100 0 3 3 3100 4 100 100 3 0 100 1100 100 5 4 3 100 0 2100 100 100 100 3 1 2 0
Computing the intersection of two sets is similar to computing the union;only for this operation we use the And operator instead of the Or operator.Similarly, the difference of two sets is found by executing the And operatorwith a member from the first set and the negation of the corresponding member of the second set. We can determine if one set is a subset of another set byusing the same formula we used for finding the difference. For example, if:setA(index) && !(setB(index))evaluates to False then setA is not a subset of setB.Implement The code for a CSet class based on a BitArray  in c#?
Consider a (singly) linked list. Describe an algorithm to remove every second element from the list. (HINT: The algorithm is similar to the one that is used when we delete a single node. Here, we need to skip an element after every deletion, and then if we have not reached the end of the list repeat this procedure until the list is exhausted.).   (a) Write the steps to removeEverySecondElement from the linked list.  (b) Write a function removeEverySecondElement() that implements the task
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education