Massive Data Algorithmics. Lecture 10: Connected Components and MST

Similar documents
Info 2950, Lecture 16

Chapter 23. Minimum Spanning Trees

CS 561, Lecture 9. Jared Saia University of New Mexico

On External-Memory Planar Depth-First Search

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Math 776 Graph Theory Lecture Note 1 Basic concepts

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Lecture 25 Spanning Trees

Discrete mathematics

Definition Example Solution

Algorithms for Large Data Sets. Giuseppe F. (Pino) Italiano Università di Roma Tor Vergata

Notes on Minimum Spanning Trees. Red Rule: Given a cycle containing no red edges, select a maximum uncolored edge on the cycle, and color it red.

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Outline. Graphs. Divide and Conquer.

Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1

Minimum Spanning Trees My T. UF

1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m

Problem Set 2 Solutions

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

Homework 5: Graphs, Minimum Spanning Trees, and Dijkstra Shortest-Path

Let G = (V, E) be a graph. If u, v V, then u is adjacent to v if {u, v} E. We also use the notation u v to denote that u is adjacent to v.

The Six Color Theorem

Kruskal s MST Algorithm

I/O-Efficient Algorithms for Planar Graphs I: Separators

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Graph Algorithms Using Depth First Search

Minimum Spanning Trees Ch 23 Traversing graphs

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

Lecture 6 Basic Graph Algorithms

MATH 363 Final Wednesday, April 28. Final exam. You may use lemmas and theorems that were proven in class and on assignments unless stated otherwise.

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Minimum Spanning Trees

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

COP 4531 Complexity & Analysis of Data Structures & Algorithms

22.3 Depth First Search

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

Minimum Spanning Tree (5A) Young Won Lim 5/11/18

Discrete Structures CISC 2315 FALL Graphs & Trees

COS 226 Lecture 19: Minimal Spanning Trees (MSTs) PFS BFS and DFS examples. Classic algorithms for solving a natural problem

K 4 C 5. Figure 4.5: Some well known family of graphs

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

More PRAM Algorithms. Techniques Covered

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

What is a minimal spanning tree (MST) and how to find one

Parallel Breadth First Search

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs

Randomized Graph Algorithms

Undirected Graphs. Hwansoo Han

Math 778S Spectral Graph Theory Handout #2: Basic graph theory

4 Basics of Trees. Petr Hliněný, FI MU Brno 1 FI: MA010: Trees and Forests

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

Union/Find Aka: Disjoint-set forest. Problem definition. Naïve attempts CS 445

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Greedy Algorithms Part Three

Chapter 9 Graph Algorithms

Prim & Kruskal Algorithm

Chapter 9 Graph Algorithms

Sample Solutions to Homework #4

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

Assignment 5: Solutions

Lecture 5: Graph algorithms 1

Lecture 13: Minimum Spanning Trees Steven Skiena

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

csci 210: Data Structures Graph Traversals

Lecture 3: Graphs and flows

Week 11: Minimum Spanning trees

Solving Linear Recurrence Relations (8.2)

A Vizing-like theorem for union vertex-distinguishing edge coloring

Recitation 11. Graph Contraction and MSTs Announcements. SegmentLab has been released, and is due Friday, April 14. It s worth 135 points.

Lecture Notes for Chapter 23: Minimum Spanning Trees

Minimum Spanning Trees

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Lecture 13: Minimum Spanning Trees Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Spanning Trees. Lecture 22 CS2110 Spring 2017

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

Graph Algorithms. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

Partha Sarathi Manal

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

COMPSCI 311: Introduction to Algorithms First Midterm Exam, October 3, 2018

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

Minimum Spanning Trees

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Greedy Algorithms and Matroids. Andreas Klappenecker

Greedy Algorithms and Matroids. Andreas Klappenecker

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Outline. Disjoint set data structure Applications Implementation

Theorem 2.9: nearest addition algorithm

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4)

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

Solutions to Exercises 9

Minimum Spanning Tree

Week 12: Minimum Spanning trees and Shortest Paths

Transcription:

Connected Components

Connected Components 1 1 2 2 4 1 1 4 1 4 4 3 4

Internal Memory Algorithms BFS, DFS: O( V + E ) time 1: for every edge e E do 2: if two endpoints v and w of e are in different CCs then 3: Let µ(v) and µ(w) be the component label of v and w 4: for every u V do 5: if µ(u) = µ(v) or µ(u) = µ(w) then 6: µ(u) = min(µ(v), µ(w)) O( E V ) time but it can be improved to O( V log V + E ) time using the union-find DS

Semi-External Connectivity Algorithm Assumption: V M Procedure SemiExternalConnectivity 1: Load all vertices of G into memory and mark each of them as being in its own connected component, that is, µ(v) = v 2: for every edge e E do 3: if two endpoints v and w of e are in different CCs then 4: Let µ(v) and µ(w) be the component label of v and w 5: for every u V do 6: if µ(u) = µ(v) or µ(u) = µ(w) then 7: µ(u) = min(µ(v), µ(w)) O(scan( V + E )) I/Os

Overall view - If V M then apply SemiExternalConnectivity - Apply graph contraction to produce a graph G with at most half as many vertices as G - Recursively compute CCs of G - Compute a labeling of G using the labeling of G

1 3 6 2 12 5 10 8 7 13 9 11 4

3 5 6 2 4 10 7 8 1 13 12 11 9

H 3 5 6 2 4 10 7 8 1 13 12 11 9

G 2 4 8 1 11

Procedure FullyExternalConnectivity 1: if V M then 2: call SemiExternalConnectivity 3: else 4: v V, compute the smallest neighbor w v 5: Compute the CCs of the subgraph H of G induced by {v,w v },v V 6: Compress each of CCs into a single vertex. Remove isolated vertices. Let G be the resulting graph. 7: Recursively compute the CCs of G and assign a unique label to each such vertex. 8: Re-integrate the isolated vertices into G and assign a unique label to each such vertex. 9: For every vertex v G and every vertex v in the CC of H represented by v, let µ G (v) = µ G (v )

Line 2: O(scan( V + E ) I/Os Line 4: computing H - Replace each edge {u,v} with (u,v) and (v,u) - Sort edges lexicographically to obtain sorted adjacency list - Scan edges and select w v for every vertex v G as the first in the adjacency list - Sort the selected edges and scan in order to remove duplicates O(sort(E) I/Os

Line 5: Computing CCs of H - The main observation: H is forest - Sort edges lexicographically to obtain sorted adjacency list - Scan edges and select w v for every vertex v G as the first in the adjacency list - Sort the selected edges and scan in order to remove duplicates O(sort(E) I/Os

Line 5: Computing CCs of H - Apply the Euler tour technique to H in order to transform each tree T of H into a cycle C T. Let H be the resulting graph. - Each C T is a connected component of H and consequently specify a connected component of H - Apply listranking to lists (cycles) in H. Note the head for each list is not specified but with a small change to listranking we can distinguish lists and label components. - Scan H and write each vertex and its label in H into disk and sort them to remove duplicates O(sort( H )) = O(sort( V )) I/Os

Line 6: Computing G - Sort (v, µ H (v)) based on the vertex id - Sort the edges of G based on the first endpoints and then scan it and replace each vertex v with µ H (v). - Sort the edges of G based on the second endpoints and then scan it and replace each vertex v with µ H (v). - Lexicographically sort the resulting edges and remove duplicates - To remove isolated vertices, scan the edges of G and for each edge {u,w} add u,w into a list X. Remove duplicates in X by sorting. Isolated vertices not appear in X. O(sort( V + E )) I/Os The rest of the algorithm can be similarly done using several scan and sorting.

Analysis { O(scan( V + E )) if V M I( V, E ) = O(sort( V + E )) + I( V /2, E ) if V > M I( V, E ) = sort( V ) + sort( E )log 2 ( V /M) I/Os

: Improvement Idea: stop recursion sooner BFS can be done in O( V + sort E ) (to be explained in next lecture) Stop recursion whenever V E /B and apply BFS O(sort( V ) + sort( E )log 2 ( V B/ E )) I/Os The best known result: O(sort( V ) + sort( E )log 2 log 2 ( V B/ E ))

Spanning Tree of G Procedure ExternalST 1: Construct H 2: Contract G to get G 3: Compute a spanning tree T of G recursively 4: A spanning tree T of G is all edges of H as well as one edge {u,w} per edge {u,w } T

Minimum Spanning Tree of G The major modification - In SemiExternalConnectivity, first sort edges by increasing weights. This is indeed a semi-external Kruskal s algorithm - In construction of H, edge {v,w v } is chosen as the minimum-weight edge incident to v. - In construction of G, among edges connecting two component of H, one with the minimum weight is chosen. O(sort( V ) + sort( E )log 2 ( V /M)) I/Os Note since BFS can not be used to compute MST, we can not get O(sort( V ) + sort( E )log 2 ( V B/ E )) I/Os result

Summary: Connected Components and MST Computing CCs can be performed in O(sort( V ) + sort( E )log 2 ( V B/ E )) I/Os or O(sort( V ) + sort( E )log 2 ( V /M)) Algorithms of CCs can be simply modified to obtain efficient algorithms for - Computing a spanning tree - Computing the minimum spanning tree Techniques - Contraction

References I/O efficient graph algorithms Lecture notes by Norbert Zeh. - Section 5