Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

Suppose that A B. Show that Bc Ac.

Answered: 1 week ago

Question

7-16 Compare Web 2.0 and Web 3.0.

Answered: 1 week ago