1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Graphs - II Algorithms G. Miller V. Adamchik CS Spring 2014 Carnegie Mellon University.
Greed is good. (Some of the time)
Minimum Spanning Tree CSE 331 Section 2 James Daly.
Discussion #36 Spanning Trees
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
CSE 780 Algorithms Advanced Algorithms Graph Alg. DFS Topological sort.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 25: Graph Traversal, DAGs, and Weighted Graphs.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 9 Instructor: Paul Beame.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
Minimum Spanning Trees
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.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Introduction to Graph Theory
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
Graphs 2015, Fall Pusan National University Ki-Joune Li.
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
Graph Search Applications, Minimum Spanning Tree
Introduction to Algorithms
Minimum Spanning Tree Chapter 13.6.
Graph Algorithms Using Depth First Search
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
Graph Algorithm.
Minimum Spanning Tree.
EMIS 8373: Integer Programming
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
Chapter 11 Graphs.
Autumn 2015 Lecture 10 Minimum Spanning Trees
2017, Fall Pusan National University Ki-Joune Li
Richard Anderson Autumn 2016 Lecture 5
Richard Anderson Lecture 10 Minimum Spanning Trees
Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Autumn 2016 Lecture 10 Minimum Spanning Trees
CSE 417: Algorithms and Computational Complexity
Minimum Spanning Trees (MSTs)
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Richard Anderson Winter 2019 Lecture 6
Winter 2019 Lecture 10 Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Richard Anderson Winter 2019 Lecture 5
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame

2 DFS(v) for a directed graph

3 DFS(v) tree edges back edges forward edges  cross edges NO  cross edges

4 Strongly-connected components  In directed graph if there is a path from a to b there might not be one from b to a  a and b are strongly connected iff there is a path in both directions (i.e. a directed cycle containing both a and b  Breaks graph into components

5 Strongly-connected components

6 Uses for SCC’s  Optimizing compilers need to find loops, which are SCC’s in the program flow graph.  If (u,v) means process u is waiting for process v, SCC’s show deadlocks.

7 Directed Acyclic Graphs  If we collapse each SCC to a single vertex we get a directed graph with no cycles  a directed acyclic graph or DAG  Many problems on directed graphs can be solved as follows:  Compute SCC’s and resulting DAG  Do one computation on each SCC  Do another computation on the overall DAG

8 Simple SCC Algorithm  u,v in same SCC iff there are paths u  v & v  u  DFS from every u, v: O(nm) = O(n 3 )

9 Better method  Can compute all the SCC’s while doing a single DFS! O(n+m) time  We won’t do the full algorithm but will give some ideas

10 Definition The root of an SCC is the first vertex in it visited by DFS. Equivalently, the root is the vertex in the SCC with the smallest number in DFS ordering.

11 Subgoal  All members of an SCC are descendants of its root.  Can we identify some root?  How about the root of the first SCC completely explored by DFS?  Key idea: no exit from first SCC (first SCC is leftmost “leaf” in collapsed DAG)

12 Definition x is an exit from v (from v’s subtree) if  x is not a descendant of v, but  x is the head of a (cross- or back-) edge from a descendant of v (including v itself)  Any non-root vertex v has an exit v x v x

13 Finding SCC’s  A root nodes v sometimes have exits  only via a cross-edge to a node x that is not in a component with a root above v, e.g. vertex 10 in the example.

14 Strongly-connected components

15 Minimum Spanning Trees (Forests)  Given an undirected graph G=(V,E) with each edge e having a weight w(e)  Find a subgraph T of G of minimum total weight s.t. every pair of vertices connected in G are also connected in T  if G is connected then T is a tree otherwise it is a forest

16 Weighted Undirected Graph

17 First Greedy Algorithm  Prim’s Algorithm:  start at a vertex v  add the cheapest edge adjacent to v  repeatedly add the cheapest edge that joins the vertices explored so far to the rest of the graph.  We’ll show it works later

18 Prim’s Algorithm

19 Prim’s Algorithm

20 Prim’s Algorithm

21 Prim’s Algorithm

22 Prim’s Algorithm

23 Prim’s Algorithm

24 Prim’s Algorithm

25 Prim’s Algorithm

26 Prim’s Algorithm

27 Prim’s Algorithm

28 Prim’s Algorithm

29 Prim’s Algorithm

30 Prim’s Algorithm MST weight =41

31 Second Greedy Algorithm  Kruskal’s Algorithm  Start with the vertices and no edges  Repeatedly add the cheapest edge that joins two different components. i.e. that doesn’t create a cycle  Again we save the proof of correctness for later

32 Kruskal’s Algorithm

33 Kruskal’s Algorithm

34 Kruskal’s Algorithm

35 Kruskal’s Algorithm

36 Kruskal’s Algorithm

37 Kruskal’s Algorithm

38 Kruskal’s Algorithm

39 Kruskal’s Algorithm

40 Kruskal’s Algorithm

41 Kruskal’s Algorithm

42 Kruskal’s Algorithm

43 Kruskal’s Algorithm

44 Kruskal’s Algorithm

45 Kruskal’s Algorithm

46 Kruskal’s Algorithm produces same tree as Prim’s algorithm