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

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

Suppose we want to find the minimum spanning tree of the following graph.

(a) Run Prim’s algorithm; whenever there is a choice of nodes, always use alphabetic ordering (e.g., start from node A). Draw a table showing the intermediate values of the cost array.

(b) Run Kruskal’s algorithm on the same graph. Show how the disjoint-sets data structure looks at every intermediate stage (including the structure of the directed trees), assuming path compression is used.

Question:Show how to implement the stingy algorithm for Horn formula satisfiability (Section 5.3) in time that is linear in the length of the formula (the number of occurrences of literals in it). (Hint: Use a directed graph, with one node per variable, to represent the implications.)

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.

Design a linear-time algorithm for the following task.

Input: A connected, undirected graphG.

Question:Is there an edge you can remove fromGwhile still leavingGconnected?

Can you reduce the running time of your algorithm toO(V)?

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