Suppose you implement the disjoint-sets data structure usingunion-by-rank but not path compression. Give a sequence ofm union and find operations onnelements that take Ω(mlogn)time.

Short Answer

Expert verified

The disjoint sets of data structure using union-by-rank a sequence of union and operations on elements by using forest implementation of disjoint sets that takesΩ(mlogn) time.

Step by step solution

01

Forest Implementation

A forest implementation of disjoint sets with only the weighted union heuristics without path comparison. The disjoint sets of data structure using union-by-rank a sequence of m union and operations on n elements by using forest implementation of disjoint sets.

02

Create Sequence and Perform Operation

Let’s a forest implementation of disjoint sets with only the weighted union heuristics without path comparison. And it consists n distinct elements. For proving this given statement suppose n be the power of variable 2 and consider x1,x2.........xn be the variables.

Let the sequence of unions. And there are log2nlevels of union operations. And n2 unions which is equals to the x1,x2,x3,x4,...,xn-1,xn.

n2=x1,x2,x3,x4,...,xn-1,xn

And after this, there are some disjoint sets.

Let T1.............Tnare some disjoint sets at the beginning of level K.

Then the following unions are as follows:

rootT1,rootT2....

Here the number of disjoint sets decreases by a factor of 2, and as there n2sets after level 1, after level k,

There are n2ksets.

This indicates after the level log2n-1, there is one disjoint set T.

And the height of this set T is log2n-1. As the union the roots of the trees.

So far, n - 1 operations of unions are taking place.

And an extra union of x1,x2and the number of unions is exactly n, which does not change the structure of the given tree.

Now, after this sequence of unions, there is a node with height log2n-1in T.

After this step just find the operations on x. And without the path compression, it will not change the structure of the tree.

Since the depth of x, then the operation will takeΩlogntime. So, the total time for finding the operation on x is Ωmlogn.

The disjoint sets of data structure using union-by-rank a sequence of m union and operations on n elements by usingforest implementation of disjoint setsis given as

constintN=10;

Let the constant be ten, after that take integer,

int P[N+1]; //stores parent of each set, initially all elements set to -1 to indicate no parent.

int Min[N+1]; //stores min element of each set

intFind(intu){returnP[u]<o?uP[u]=Find(P[u];}voidUnion(intu,intv){u=Find(u);v=Find(v);if(u==v)return;Min[u]=<Min[v]?Min[u]:Min[v];P[v]=u;}

intFindMin(intu){returnMin[Find(u)];}Therefore,thetotaltimecomplexityisΩ(mlogn).

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Ternary A server has customers waiting to be served. The service time required by eachcustomer is known in advance: it is ciminutes for customer i. So if, for example, the customers are served in order of increasing i , then the ithcustomer has to wait Pij=1tjminutes. We wish to minimize the total waiting time.

T=Xni=1(time spent waiting by customer ).

Give an efficient algorithm for computing the optimal order in which to process the customers.

A binary counter of unspecified length supports two operations: increment (which increases its value by one) and reset (which sets its value back to zero). Show that, starting from an initially zero counter, any sequence of n increment and reset operations takes time O(n); that is, the amortized time per operation is O(1) .

A long string consists of the four characters A,C,G,T ; they appear with frequency 31%,20%,9%and40% respectively. What is the Huffman encoding of these four characters?

In this problem, we will develop a new algorithm for finding minimum spanning trees. It is based upon the following property:

Pick any cycle in the graph, and let e be the heaviest edge in that cycle. Then there is a minimum spanning tree that does not contain e.

(a) Prove this property carefully.

(b) Here is the new MST algorithm. The input is some undirected graph G=(V,E) (in adjacency list format) with edge weights {we}.sort the edges according to their weights for each edge eE, in decreasing order of we:

if e is part of a cycle of G:

G = G - e (that is, remove e from G )

return G , Prove that this algorithm is correct.

(c) On each iteration, the algorithm must check whether there is a cycle containing a specific edge . Give a linear-time algorithm for this task, and justify its correctness.

(d) What is the overall time taken by this algorithm, in terms of |E|? Explain your answer.

Give the state of the disjoint-sets data structure after the following sequence of operations, starting from singleton sets 1,,8. Usepath compression. In the case of ties, always make the lower numbered root point to the higher numbered ones.

union1,2,union3,4,union5,6,union7,8

,union1,4,union6,7,union4,5,find1

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free