Question: Given a set x = {e 1 , e 2, ..., e n} and a collection of sets S 1 , S 2, ..., S

Given a set x = {e1, e2, ..., en} and a collection of sets S1, S2, ..., Sn. Each element ei has a corresponding set Si = {ei}.

You are now given a sequence of commands of type Union(ex , ey ) interspersed with commands Query(ex , ey ). The union operation takes the two sets one containing ex , and the other containing ey (they might be the same set, but not at the beginning) and union it to a single set containing the elements of both. As we go creating sets we query command

asks whether the two elements in its argument NOW (at the time you reached it in the sequence) belong to the same set or a different set.

(a) Given a list of O(n) operations of Union and Query. Design an algorithm that processes

the sequence of commands in O(n log n) time. To process the sequence means to answer all

the queries in the sequence. (Hint: keep a set as a rooted tree with depth that is O(log n).

The Crux is how to union two trees and keep this property.)

(b) Given an undirected weighted graph G = (V, E). Show an implementation of Kruskals Minimum

Spanning Tree(MST) algorithm by using the Union and Query commands. Your implementation

should have O(|E| log |V|) time complexity. (Hint: In Kruskals algorithm, it

builds the MST by processing every edge in G and asks whether two endpoints of an edge

belong to two disjoint trees. If so, the algorithm adds the edge making two disjoint trees

into a single tree. )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!