CS2420: Lecture 43 Vladimir Kulyukin Computer Science Department Utah State University.

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

Instructor Neelima Gupta Table of Contents Graph Algorithms Thanks to: Sunaina Kalucha (29) (MCS '11)
1 Disjoint Sets Set = a collection of (distinguishable) elements Two sets are disjoint if they have no common elements Disjoint-set data structure: –maintains.
1 Minimum Spanning Tree Prim-Jarnik algorithm Kruskal algorithm.
CS38 Introduction to Algorithms Lecture 5 April 15, 2014.
Andreas Klappenecker [Based on slides by Prof. Welch]
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
CS2420: Lecture 37 Vladimir Kulyukin Computer Science Department Utah State University.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
CS2420: Lecture 10 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 22 Vladimir Kulyukin Computer Science Department Utah State University.
© 2004 Goodrich, Tamassia Union-Find1 Union-Find Partition Structures.
CS2420: Lecture 40 Vladimir Kulyukin Computer Science Department Utah State University.
Vladimir Kulyukin Computer Science Department Utah State University
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 17 Union-Find on disjoint sets Motivation Linked list representation Tree representation.
Chapter 9: Union-Find Algorithms The Design and Analysis of Algorithms.
Lecture 16: Union and Find for Disjoint Data Sets Shang-Hua Teng.
CS2420: Lecture 8 Vladimir Kulyukin Computer Science Department Utah State University.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
CSE 373, Copyright S. Tanimoto, 2002 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
Data Structures & Algorithms Union-Find Example Richard Newman.
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
Trees Featuring Minimum Spanning Trees HKOI Training 2005 Advanced Group Presented by Liu Chi Man (cx)
Analysis of Algorithms
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
COMP 261 Lecture 12 Disjoint Sets. Menu Kruskal's minimum spanning tree algorithm Disjoint-set data structure and Union-Find algorithm Administrivia –Marking.
10/2/2015 3:00 PMCampus Tour1. 10/2/2015 3:00 PMCampus Tour2 Outline and Reading Overview of the assignment Review Adjacency matrix structure (§12.2.3)
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
D ESIGN & A NALYSIS OF A LGORITHM 06 – D ISJOINT S ETS Informatics Department Parahyangan Catholic University.
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
1 Greedy Algorithms and MST Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
Disjoint Sets Data Structure. Disjoint Sets Some applications require maintaining a collection of disjoint sets. A Disjoint set S is a collection of sets.
Union-find Algorithm Presented by Michael Cassarino.
Disjoint-Set Operation. p2. Disjoint Set Operations : MAKE-SET(x) : Create new set {x} with representative x. UNION(x,y) : x and y are elements of two.
ICS 353: Design and Analysis of Algorithms Heaps and the Disjoint Sets Data Structures King Fahd University of Petroleum & Minerals Information & Computer.
1 The Disjoint Set ADT CS146 Chapter 8 Yan Qing Lei.
Minimum Spanning Trees Featuring Disjoint Sets HKOI Training 2006 Liu Chi Man (cx) 25 Mar 2006.
Chapter 23: Minimum Spanning Trees: A graph optimization problem Given undirected graph G(V,E) and a weight function w(u,v) defined on all edges (u,v)
Union-Find  Application in Kruskal’s Algorithm  Optimizing Union and Find Methods.
MA/CSSE 473 Days Answers to student questions Prim's Algorithm details and data structures Kruskal details.
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
MST Lemma Let G = (V, E) be a connected, undirected graph with real-value weights on the edges. Let A be a viable subset of E (i.e. a subset of some MST),
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
MA/CSSE 473 Day 37 Student Questions Kruskal Data Structures and detailed algorithm Disjoint Set ADT 6,8:15.
CSE 373: Data Structures and Algorithms
Lecture ? The Algorithms of Kruskal and Prim
Introduction to Algorithms
Minimum Spanning Tree Chapter 13.6.
Disjoint Sets Data Structure
Lecture 12 Algorithm Analysis
CMSC 341 Disjoint Sets Based on slides from previous iterations of this course.
Disjoint Set Neil Tang 02/23/2010
Disjoint Set Neil Tang 02/26/2008
ICS 353: Design and Analysis of Algorithms
CSE 373 Data Structures and Algorithms
Lecture 12 Algorithm Analysis
ICS 353: Design and Analysis of Algorithms
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Lecture 20: Disjoint Sets
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
Lecture 12 Algorithm Analysis
CSE 373: Data Structures and Algorithms
Chapter 9: Graphs Spanning Trees
Presentation transcript:

CS2420: Lecture 43 Vladimir Kulyukin Computer Science Department Utah State University

Outline Graph Algorithms (Chapter 9)

Kruskal’s Algorithm: UnionFind Kruskal’s Algorithm can be implemented with the UnionFind data structure. A set is first partitioned into singletons, i.e. single element sets. The subsets are repeatedly unified into larger subsets until some termination criterion is met. One termination criterion is that there are no more subsets to unify.

Review: UnionFind Operations MakeSet(x) - creates a one-element set {x}. Find(x) - returns a subset containing x. Union(x, y) - constructs the union of the disjoint sets S x and S y such that S x contains x and S y contains y. S x U S y replaces both S x and S y in the collection of subsets.

UnionFind: Two Implementations Use one element of each subset as a representative. Two implementation alternatives: –QuickFind: Find = O(1); Union = O(N). –QuickUnion: Union = O(1); Find = O(N).

QuickFind: Asymptotic Run Time When performing the union operation, always append the shorter list to the longer one (union by size). The worst case run time of any legitimate sequence of unions is O(nlogn). The worst case run time of a sequence of n-1 unions and m finds is O(nlogn + m).

QuickUnion: Asymptotic Run Time If union by size (number of elements in the tree) or union by rank (tree height) is used, the height of the tree is logn. The time efficiency of a sequence of n-1 unions and m finds is O(n + mlogn).

Kruskal’s Algorithm: Code Kruskal(V, E) { // The input is a graph G = (V, E) Sort E in non-decreasing order of edge weights; TreeEdges = new UnionFind(); k = 0; // number of processed edges // A min spanning tree has |V|-1 edges. for each (u, v) in E { if ( k == |V| - 1 ) break; T 1 = TreeEdges.Find(u); T 2 = TreeEdges.Find(v); if ( T 1 != T 2 ) { TreeEdges.Union(u, v); k = k + 1; }// end if }// end for return TreeEdges; }// end Kruskal

Kruskal’s Algorithm: Asymptotic Analysis Sorting the edges is O(|E|log(|E|)). In the worst case, the Union and Find operations are executed |E| times. If we use the QuickUnion implementation of UnionFind, we have O(|E| + |E|log(|E|)). If we use the QuickFind implementation of UnionFind, we also have O(|E| + |E|log(|E|)). Thus, we have O(|E|log(|E|)) + O(|E|+ |E|log(|E|)) = O(|E|log(|E|)).

Depth First Search (DFS) Each vertex V in G has a distance V.Dist associated with it. Each vertex V in G has a pointer to the vertex it was reached from (V.Prev). Initially, V.Dist = INF for every V. The start vertex S is the input.

Depth First Search DFS(G, S) { // G is a graph; S is the start vertex S.Dist = 0; S.Prev = NULL; DFS_REC(S); } // V is a vertex in G. DFS_REC(G, V) { For each U adjacent to V { If ( U.Dist == INF ) { U.Prev = V; U.Dist = V.Dist + 1; DFS_REC(G, U); } // end If } // end For } // end DFS_REC

DFS: Example V0V0 V6V6 V5V5 V3V3 V4V4 V1V1 V2V2 Start Vertex

DFS: Example V0V0 V6V6 V5V5 V3V3 V4V4 V1V1 V2V2

V0V0 V6V6 V5V5 V3V3 V4V4 V1V1 V2V2

V0V0 V6V6 V5V5 V3V3 V4V4 V1V1 V2V2

V0V0 V6V6 V5V5 V3V3 V4V4 V1V1 V2V2

V0V0 V6V6 V5V5 V3V3 V4V4 V1V1 V2V2

V0V0 V6V6 V5V5 V3V3 V4V4 V1V1 V2V2

DFS: Asymptotic Analysis If the graph is represented with adjacency lists: O(|V|+|E|).