Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

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

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?

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.

Show how to find the maximum spanning tree of a graph, that is , the spanning tree of largest total weight.

Graphs with prescribed degree sequences. Given a list of n positive integers d1,d2,,dn, we want to efficiently determine whether there exists an undirected graphG=(V,E) whose nodes have degrees preciselyd1,d2,,dn . That is, if V={v1,,vn}, then the degree of vi should be exactly di. We call (d1,,dn) the degree sequence of G. This graph G should not contain self-loops (edges with both endpoints equal to the same node) or multiple edges between the same pair of nodes.

(a) Give an example of d1,d2,d3,d4 where all the di3 and d1+d2+d3+d4 is even, but for which no graph with degree sequence(d1,d2,d3,d4) exists.

(b) Suppose that d1d2d3dn and that there exists a graph G=(V,E) with degree sequence (d1,,dn). We want to show that there must exist a graph that has this degree sequence and where in addition the neighbors of v1 are v2,v3,,vdi+1 . The idea is to gradually transform G into a graph with the desired additional property.

i. Suppose the neighbors ofv1 in Gare not v2,v3,,vdi+1. Show that there exists i<jn and uV and such that {v1,vi},{u,vj}Eand {v1,vj},{u,vi}E

ii. Specify the changes you would make to G to obtain a new graph G'=(V,E') with the same degree sequence as G and where (v1,vi)E'.

iii. Now show that there must be a graph with the given degree sequence but in which v1 has neighbors v2,v3,,vdi+1.

c) Using the result from part (b), describe an algorithm that on input d1,,dn (not necessarily sorted) decides whether there exists a graph with this degree sequence. Your algorithm should run in time polynomial in n and in m=i=1ndi .

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.

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