/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q12E Suppose you implement the disjoi... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

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 91Ó°ÊÓ!

One App. One Place for Learning.

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

Get started for free

Study anywhere. Anytime. Across all devices.