Depth determination In the depth-determination problem, we

Chapter 21, Problem 21-2

(choose chapter or problem)

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.

Unfortunately, we don't have that question answered yet. But you can get it answered in just 5 hours by Logging in or Becoming a subscriber.

Becoming a subscriber
Or look for another answer

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back