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

The following statements may or may not be correct, In each case, either prove it (if it is correct) or give a counter-example (if it isn’t correct). Always assume that the graph G=(V,E)is undirected. Do not assume that edge weights are distinct unless this is specifically stated.

  1. If a graph G has more than |V|-1edges, and there is a unique heaviest edge, then this edge cannot be part of a minimum spanning tree.
  2. If G has a cycle with a unique heaviest edge e, then e cannot be part of any MST.
  3. Let e be any edge of minimum weight in G. Then e must be part of some MST.
  4. If the lightest edge in a graph is unique, then it must be part of every MST.
  5. If e is part of some MST of G, then it must be a lightest edge across some cut of .
  6. If G has a cycle with a unique lightest edge e must be part of every MST.
  7. The shortest-path tree computed by Dijkstra’s algorithm is necessarily an MST.
  8. The shortest path between two nodes is necessarily part of some MST.
  9. Prim’s algorithm works correctly when there are negative edges.
  10. (For any r>0, define an r-path to be a path whose edges all have weight <r). If G contains an r-path from node s to t , then every MST of G must also contain an r-path from node s to node t.

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

We use Huffman's algorithm to obtain an encoding of alphabet {a,b,c}with frequencies fa,fb,fc. In each of the following cases, either give an example of frequencies (fa,fb,fc)that would yield the specified code, or explain why the code cannot possibly be obtained (no matter what the frequencies are).

(a) Code:{0,10,11}

(b) Code:{0,1,00}

(c) Code:{10,01,00}

Give a linear-time algorithm that takes as input a tree and determines whether it has a perfect matching: a set of edges that touches each node exactly once.

A feedback edge set of an undirected graph G(V,E) is a subset of edgesE'Ethat intersects every cycle of the graph. Thus, removing the edges will render the graph acyclic.

Give an efficient algorithm for the following problem:

Input: Undirected graph G(V,E) with positive edge weights we.

Output: A feedback edge set E'Eminimum total weight eE'we.

Ternary Huffman. Trimedia Disks Inc. has developed “ternary” hard disks. Each cell on a disk can now store values 0,1, or 2(instead of just 0 or 1). To take advantage of this new technology, provide a modified Huffman algorithm for compressing sequences of characters from an alphabet of size n, where the characters occur with known frequencies f1, f2,...., fn. Your algorithm should encode each character with a variable-length codeword over the values 0,1,2, such that no codeword is a prefix of another codeword and so as to obtain the maximum possible compression. Prove that your algorithm is correct

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