Question: In the depth-determination problem, we maintain a forest F = (Ti) of rooted trees under three operations: MAKE-TREE (v) creates a tree whose only
• MAKE-TREE (v) creates a tree whose only node is v.
• FIND-DEPTH (v) returns the depth of node v within its tree.
• GRAFT(r, v) makes node r, which is assumed to be the root of a tree, become the child of node v, which is assumed to be in a different tree than r but may or may not itself be a root.
The key idea is to maintain in each node v a "pseudo distance" d[v], which is defined so that the sum of the pseudo distances along the path from v to the root of its set Si equals the depth of v in Ti. That is, if the path from v to its root in Si is v0, v1, ..., vk, where v0 = v and vk is Si's root, then the depth of v in Ti is .
b. Give an implementation of MAKE-TREE.
c. Show how to modify FIND-SET to implement FIND-DEPTH. Your implementation should perform path compression, and its running time should be linear in the length of the find path. Make sure that your implementation updates pseudo distances correctly.
d. Show how to implement GRAFT(r, v), which combines the sets containing r and v, by modifying the UNION and LINK procedures. Make sure that your implementation updates pseudo distances correctly. Note that the root of a set Si is not necessarily the root of the corresponding tree Ti.
e. Give a tight bound on the worst-case running time of a sequence of m MAKE-TREE, FIND-DEPTH, and GRAFT operations, n of which are MAKE-TREE operations.
d. Show how to implement GRAFT(r, v), which combines the sets containing r and v, by modifying the UNION and LINK procedures. Make sure that your implementation updates pseudo distances correctly. Note that the root of a set Si is not necessarily the root of the corresponding tree Ti.
e. Give a tight bound on the worst-case running time of a sequence of m MAKE-TREE, FIND-DEPTH, and GRAFT operations, n of which are MAKE-TREE operations.
Step by Step Solution
3.51 Rating (168 Votes )
There are 3 Steps involved in it
a Denote the number of nodes by n and let n m 13 so that m 3n 1 First perform then operations MAKETREE 1 MAKETREE V MAKETREE U Then perform the sequence of n 1 GRAFT operations GRAFT V V GRAFTU2 U3 GR... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
C-S-A (106).docx
120 KBs Word File
