In the depth-determination problem, we maintain a forest F = {T i } of rooted trees under

Question:

In the depth-determination problem, we maintain a forest F = {Ti} 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 = ν if ν is a root. Suppose further that we implement GRAFT (r, ν) by setting r.p = ν 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 MAKE-TREE, 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 = {Si}, 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 node's 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 root of its set Si equals the depth of ν in Ti. That is, if the simple path from ν to its root in Si is ν′, ν1, . . . ,νk, where ν′ = ν and νk is S’s root, then the depth of ν in Ti is ∑kj=0 ν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 MAKETR GRAFT operations, n of which are MAKE-TREE operations.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Introduction to Algorithms

ISBN: 978-0262033848

3rd edition

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

Question Posted: