×
Log in to StudySoup
Get Full Access to Introduction To Algorithms - 3 Edition - Chapter 21 - Problem 21-2
Join StudySoup for FREE
Get Full Access to Introduction To Algorithms - 3 Edition - Chapter 21 - Problem 21-2

Already have an account? Login here
×
Reset your password

Depth determination In the depth-determination problem, we

Introduction to Algorithms | 3rd Edition | ISBN: 9780262033848 | Authors: Thomas H. Cormen ISBN: 9780262033848 130

Solution for problem 21-2 Chapter 21

Introduction to Algorithms | 3rd Edition

  • Textbook Solutions
  • 2901 Step-by-step solutions solved by professors and subject experts
  • Get 24/7 help from StudySoup virtual teaching assistants
Introduction to Algorithms | 3rd Edition | ISBN: 9780262033848 | Authors: Thomas H. Cormen

Introduction to Algorithms | 3rd Edition

4 5 1 349 Reviews
24
3
Problem 21-2

Depth determination In the depth-determination problem, we maintain a forest F D fTi g of rooted trees under three operations: MAKE-TREE./ creates a tree whose only node is . FIND-DEPTH./ returns the depth of node within its tree. GRAFT.r; / makes node r, which is assumed to be the root of a tree, become the child of node , which is assumed to be in a different tree than r but may or may not itself be a root. a. Suppose that we use a tree representation similar to a disjoint-set forest: :p is the parent of node , except that :p D if is a root. Suppose further that we implement GRAFT.r; / by setting r:p D and FIND-DEPTH./ by following the find path up to the root, returning a count of all nodes other than encountered. Show that the worst-case running time of a sequence of m MAKETREE, FIND-DEPTH, and GRAFT operations is .m2/. By using the union-by-rank and path-compression heuristics, we can reduce the worst-case running time. We use the disjoint-set forest S D fSi g, where each set Si (which is itself a tree) corresponds to a tree Ti in the forest F . The tree structure within a set Si , however, does not necessarily correspond to that of Ti . In fact, the implementation of Si does not record the exact parent-child relationships but nevertheless allows us to determine any nodes depth in Ti . The key idea is to maintain in each node a pseudodistance :d, which is defined so that the sum of the pseudodistances along the simple path from to the of its set Si equals the depth of in Ti . That is, if the simple path from to its root in Si is 0; 1;:::;k, where 0 D and k is Si s root, then the depth of in Ti is Pk jD0 j :d. 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 pseudodistances correctly. d. Show how to implement GRAFT.r; /, which combines the sets containing r and , by modifying the UNION and LINK procedures. Make sure that your implementation updates pseudodistances 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 MAKETREE, FIND-DEPTH, and GRAFT operations, n of which are MAKE-TREE operations.

Step-by-Step Solution:
Step 1 of 3

L3 - 11 Now You Try It (NYTI): x − cosx 1. Is f(x)= even, odd, or neither Verify your answer. x 3 2 3π 3π 2. Suppose that sinα = − 5,t β = − , 3

Step 2 of 3

Chapter 21, Problem 21-2 is Solved
Step 3 of 3

Textbook: Introduction to Algorithms
Edition: 3
Author: Thomas H. Cormen
ISBN: 9780262033848

Since the solution to 21-2 from 21 chapter was answered, more than 250 students have viewed the full step-by-step answer. This full solution covers the following key subjects: tree, depth, Find, root, set. This expansive textbook survival guide covers 35 chapters, and 151 solutions. This textbook survival guide was created for the textbook: Introduction to Algorithms, edition: 3. The full step-by-step solution to problem: 21-2 from chapter: 21 was answered by , our top Engineering and Tech solution expert on 11/10/17, 05:55PM. Introduction to Algorithms was written by and is associated to the ISBN: 9780262033848. The answer to “Depth determination In the depth-determination problem, we maintain a forest F D fTi g of rooted trees under three operations: MAKE-TREE./ creates a tree whose only node is . FIND-DEPTH./ returns the depth of node within its tree. GRAFT.r; / makes node r, which is assumed to be the root of a tree, become the child of node , which is assumed to be in a different tree than r but may or may not itself be a root. a. Suppose that we use a tree representation similar to a disjoint-set forest: :p is the parent of node , except that :p D if is a root. Suppose further that we implement GRAFT.r; / by setting r:p D and FIND-DEPTH./ by following the find path up to the root, returning a count of all nodes other than encountered. Show that the worst-case running time of a sequence of m MAKETREE, FIND-DEPTH, and GRAFT operations is .m2/. By using the union-by-rank and path-compression heuristics, we can reduce the worst-case running time. We use the disjoint-set forest S D fSi g, where each set Si (which is itself a tree) corresponds to a tree Ti in the forest F . The tree structure within a set Si , however, does not necessarily correspond to that of Ti . In fact, the implementation of Si does not record the exact parent-child relationships but nevertheless allows us to determine any nodes depth in Ti . The key idea is to maintain in each node a pseudodistance :d, which is defined so that the sum of the pseudodistances along the simple path from to the of its set Si equals the depth of in Ti . That is, if the simple path from to its root in Si is 0; 1;:::;k, where 0 D and k is Si s root, then the depth of in Ti is Pk jD0 j :d. 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 pseudodistances correctly. d. Show how to implement GRAFT.r; /, which combines the sets containing r and , by modifying the UNION and LINK procedures. Make sure that your implementation updates pseudodistances 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 MAKETREE, FIND-DEPTH, and GRAFT operations, n of which are MAKE-TREE operations.” is broken down into a number of easy to follow steps, and 434 words.

Other solutions

People also purchased

Related chapters

Unlock Textbook Solution

Enter your email below to unlock your verified solution to:

Depth determination In the depth-determination problem, we