Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 21.3, Problem 4E
Program Plan Intro
To add a single attribute to each node in a disjoint-set so that PRINT-SET( x ) takes linear time and the asymptotic time is not changed.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Consider the array t = [1, 2, 3, 4, 5, 8, 0 , 7, 6] of size n = 9, .
a) Draw the complete tree representation for t.
b) What is the index of the first leaf of the tree in Part a (in level order)? In general, give a formula for the index of the first leaf in the corresponding complete binary tree for an arbitrary array of size n.
c) Redraw the tree from Part a after each call to fixheap, in Phase 1 of heapsort. Remember, the final tree obtained will be a maxheap.
d) Now, starting with the final tree obtained in Part c, redraw the tree after each call to fixheap in Phase 2 of heap sort. For each tree, only include the elements from index 0 to index right (since the other elements are no longer considered part of the tree).
e) For the given array t, how many calls to fixheap were made in Phase 1? How many calls to fixheap were made in Phase 2?
f) In general , give a formula for the total number of calls to fixheap in Phase 1, when heapsort is given an arbitrary array of size n. Justify…
In this exercise we are going to modify the DFS procedure so that it returns for the given
undirected graph G, the connected components of that graph. To do this we will modify the DFS
procedure so that it computes the connected components as follows:
• It maintains a counter i, initially set in 1, that counts how many connected components we found
so far
• On each vertex v ∈ G.V it maintains an attribute component indicating to which connected component number v belong to. That is, when DFS terminates, v.component indicates the component
number 1, 2, . . . i that v belongs to.
Answer the following questions:
(a) Write the pseudocode for this slightly modified version of the DFS algorithm
(b) Explain why your algorithm is correct
(c) Explain its running time.
Draw the portion of the state space tree generated by LCBB for the following instances. n = 4, m = 15, (P₁, ..., P) = (10, 10, 12, 18) (w₁,..... W 4) = (2, 4, 6, 9).
Knowledge Booster
Similar questions
- Let T be an arbitrary splay tree storing n elements A1, A2, . An, where A1 ≤ A2 ≤ . . . ≤ An. We perform n search operations in T, and the ith search operation looks for element Ai. That is, we search for items A1, A2, . . . , An one by one. What will T look like after all these n operations are performed? For example, what will the shape of the tree be like? Which node stores A1, which node stores A2, etc.? Prove the answer you gave for formally. Your proof should work no matter what the shape of T was like before these operations.arrow_forwardThe mapping strategy that takes a complete binary tree to a vector can actually be used to store general trees, albeit in a space-inefficient manner. The strategy is to allocate enough space to hold the lowest, rightmost leaf, and to maintain null references in nodes that are not currently being used. What is the worst-case Vector length needed to store an n-element binary tree?arrow_forwardCreate a programme that does a range search on all components that fall between bounds a, b along a dimension i of the multidimensional data collection, represented as a k-d tree.Given the data collection (7, 5), (4, 2), (6, 8), (1, 4), (3, 5), (2, 4), (3, 7), (9, 1), (6, 6), (5, 1) expressed as a k-d tree (k = 2), a range search of data components falling inside (a = 3, b = 7) along dimension i = 2 produces (7, 5), (1, 4), (3, 5), (3, 7), (6, 6).arrow_forward
- Suppose that we have an estimate ahead of time of how often search keys areto be accessed in a BST, and the freedom to insert them in any order that we desire.Should the keys be inserted into the tree in increasing order, decreasing order of likely frequency of access, or some other order? Explain your answer.arrow_forward1. Input: An undirected weighted graph G = (V, E, w)2. Output: An MST T = (V, E) of G3. T ← Ø4. Sort edges of G in non-increasing order and place them in a queue Q.5. repeat6. Remove the first edge (u, v) from Q and add it to T if it does not form a cyclewith the edges edge that are already included in T .7. until there are n − 1 edges in T .We can use union-find data structure to find whether the two endpoints of theselected edge are in the same set (the current MST fragment). It can be shown thatthis algorithm is correct and has a time complexity of O(m log n) [1].Give Python Implementation of algoarrow_forwardSimulate the node expansion from start state (S) to reach goal state (G) using BFS, DFS, UCS, Greedy, A*, and also given heuristic function that h(A) = 8 , h(B) = 9, h(C) = 7, h(D) = 5, h(F) = 4, h(H) = 2, h(G) = 0, h(J) = 3,h(I) = 1arrow_forward
- Create a weighted quick union implementation for UF that always ties the shorter tree to the taller tree and follows the tree height tracking. Using your approach, establish a logarithmic upper constraint on the height of the trees for N sites.arrow_forwardGiven a world map in the form of a Generic M-ary Tree consisting of N nodes and an array of queries[], the task is to implement the functions Lock, Unlock and Upgrade for the given tree. For each query in queries[], the functions return true when the operation is performed successfully, otherwise, it returns false. The functions are defined as: X: Name of the node in the tree and will be uniqueuid: User Id for the person who accesses node X 1. Lock(X, uid): Lock takes exclusive access to the subtree rooted.- Once Lock(X, uid) succeeds, then lock(A, any user) should fail, where A is a descendant of X.- Lock(B. any user) should fail where X is a descendant of B.- Lock operation cannot be performed on a node that is already locked. 2. Unlock(X, uid): To unlock the locked node.- The unlock reverts what was done by the Lock operation.- It can only be called on same and unlocked by same uid. 3. UpgradeLock(X, uid): The user uid can upgrade their lock to an ancestor node.- It is only possible…arrow_forwardGiven a world map in the form of a Generic M-ary Tree consisting of N nodes and an array of queries[], the task is to implement the functions Lock, Unlock and Upgrade for the given tree. For each query in queries[], the functions return true when the operation is performed successfully, otherwise, it returns false. The functions are defined as: X: Name of the node in the tree and will be uniqueuid: User Id for the person who accesses node X 1. Lock(X, uid): Lock takes exclusive access to the subtree rooted.- Once Lock(X, uid) succeeds, then lock(A, any user) should fail, where A is a descendant of X.- Lock(B. any user) should fail where X is a descendant of B.- Lock operation cannot be performed on a node that is already locked. 2. Unlock(X, uid): To unlock the locked node.- The unlock reverts what was done by the Lock operation.- It can only be called on same and unlocked by same uid. 3. UpgradeLock(X, uid): The user uid can upgrade their lock to an ancestor node.- It is only possible…arrow_forward
- Given a world map in the form of a Generic M-ary Tree consisting of N nodes and an array of queries[], the task is to implement the functions Lock, Unlock and Upgrade for the given tree. For each query in queries[], the functions return true when the operation is performed successfully, otherwise, it returns false. The functions are defined as: X: Name of the node in the tree and will be uniqueuid: User Id for the person who accesses node X 1. Lock(X, uid): Lock takes exclusive access to the subtree rooted.- Once Lock(X, uid) succeeds, then lock(A, any user) should fail, where A is a descendant of X.- Lock(B. any user) should fail where X is a descendant of B.- Lock operation cannot be performed on a node that is already locked. 2. Unlock(X, uid): To unlock the locked node.- The unlock reverts what was done by the Lock operation.- It can only be called on same and unlocked by same uid. 3. UpgradeLock(X, uid): The user uid can upgrade their lock to an ancestor node.- It is only possible…arrow_forward(a) Assume that we ran DFS on a digraph G, and obtained a directed spanning forest F. We are interested in the set R of vertices reachable from a given fixed vertex a ∈V (G). (i) Show in general R cannot be obtained from F. (ii) How must we modify the operation of DFS on G, so that we can obtain R from F? Also explain how to obtain R.arrow_forwardIn fact, general trees can be stored using the same mapping technique that converts a full binary tree to a vector, albeit in a space-inefficient way. The plan is to set aside enough room to store the lowest, rightmost leaf and to keep null references in any nodes that are not being used right now. How long a vector must be in the worst-case scenario to store an n-element binary tree?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education