1 Algorithms CSCI 235, Fall 2015 Lecture 35 Graphs IV.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Graph Algorithms
Advertisements

CSE 2331/5331 CSE 780: Design and Analysis of Algorithms Lecture 14: Directed Graph BFS DFS Topological sort.
Comp 122, Spring 2004 Graph Algorithms – 2. graphs Lin / Devi Comp 122, Fall 2004 Identification of Edges Edge type for edge (u, v) can be identified.
Tirgul 7 Review of graphs Graph algorithms: –DFS –Properties of DFS –Topological sort.
Elementary Graph Algorithms Depth-first search.Topological Sort. Strongly connected components. Chapter 22 CLRS.
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
Graph Traversals. For solving most problems on graphs –Need to systematically visit all the vertices and edges of a graph Two major traversals –Breadth-First.
More Graphs COL 106 Slides from Naveen. Some Terminology for Graph Search A vertex is white if it is undiscovered A vertex is gray if it has been discovered.
Graphs – Depth First Search ORD DFW SFO LAX
CSE 2331/5331 Topic 11: Basic Graph Alg. Representations Undirected graph Directed graph Topological sort.
Graphs II Kruse and Ryba Chapter 12. Undirected Graph Example: Subway Map.
Graphs - Definition G(V,E) - graph with vertex set V and edge set E
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Graph traversals / cutler1 Graph traversals Breadth first search Depth first search.
Tirgul 8 Graph algorithms: Strongly connected components.
Tirgul 11 DFS Properties of DFS Topological sort.
16a-Graphs-More (More) Graphs Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
CS 473Lecture 151 CS473-Algorithms I Lecture 15 Graph Searching: Depth-First Search and Topological Sort.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Makeup Lecture Chapter 23: Graph Algorithms Depth-First SearchBreadth-First.
Shortest Path Problems
1 Data Structures DFS, Topological Sort Dana Shapira.
Lecture 10 Topics Application of DFS Topological Sort
CSE 780 Algorithms Advanced Algorithms Graph Alg. DFS Topological sort.
Depth-First Search Idea: Keep going forward as long as there are unseen nodes to be visited. Backtrack when stuck. v G G G G is completely traversed.
November 6, Algorithms and Data Structures Lecture XI Simonas Šaltenis Aalborg University
COSC 3101A - Design and Analysis of Algorithms 10
Spring 2015 Lecture 10: Elementary Graph Algorithms
1 Depth-First Search Idea: –Starting at a node, follow a path all the way until you cannot move any further –Then backtrack and try another branch –Do.
Elementary Graph Algorithms CLRS Chapter 22. Graph A graph is a structure that consists of a set of vertices and a set of edges between pairs of vertices.
CSC 413/513: Intro to Algorithms Graph Algorithms DFS.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
Topological Sort (an application of DFS) CSC263 Tutorial 9.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Elementary Graph Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
 2004 SDU Lectrue4-Properties of DFS Properties of DFS Classification of edges Topological sort.
Chapter 22: Elementary Graph Algorithms
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 20.
Topological Sort: Definition
Shahed University Dr. Shahriar Bijani May  A path is a sequence of vertices P = (v 0, v 1, …, v k ) such that, for 1 ≤ i ≤ k, edge (v i – 1, v.
1 Chapter 22: Elementary Graph Algorithms III. 2 About this lecture Topological Sort.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture nine Dr. Hamdy M. Mousa.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
November 19, Algorithms and Data Structures Lecture XI Simonas Šaltenis Nykredit Center for Database Research Aalborg University
11 Graph Search Algorithms. 2 What parts of the graph are reachable from a given vertex ?
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.
Chapter 22: Elementary Graph Algorithms Overview: Definition of a graph Representation of graphs adjacency list matrix Elementary search algorithms breadth-first.
Graph Algorithms – 2. graphs Parenthesis Theorem Theorem 22.7 For all u, v, exactly one of the following holds: 1. d[u] < f [u] < d[v] < f [v] or.
CS 3343: Analysis of Algorithms Lecture 24: Graph searching, Topological sort.
CS138A Elementary Graph Algorithms Peter Schröder.
Introduction to Algorithms
Topological Sorting.
Chapter 22 Elementary Graph Algorithms
Main algorithm with recursion: We’ll have a function DFS that initializes, and then calls DFS-Visit, which is a recursive function and does the depth first.
CSE 2331/5331 Topic 9: Basic Graph Alg.
Topological Sort Minimum Spanning Tree
CS200: Algorithm Analysis
Many slides here are based on E. Demaine , D. Luebke slides
CS 3343: Analysis of Algorithms
Graph Algorithms – 2 DAGs Topological order
Graph Representation Adjacency list representation of G = (V, E)
Graph Algorithms – 2.
Advanced Algorithms Analysis and Design
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
Algorithms CSCI 235, Spring 2019 Lecture 34 Graphs III
Algorithms CSCI 235, Spring 2019 Lecture 35 Graphs IV
Chapter 22: Elementary Graph Algorithms III
Presentation transcript:

1 Algorithms CSCI 235, Fall 2015 Lecture 35 Graphs IV

2 Time Stamps We can gain information about the relationships between vertices using a global time stamp. A time stamp records when a vertex is first discovered and when we finish examining its adjacency list. Time stamps are useful in reasoning about search behavior. Time stamps are used in many graph algorithms.

DFS with Time Stamps DFS(G) for v in vertices[G] do{Initialize vertices} color[v] <- white pred[v] parent} time <- 0{time is a global variable} for v in vertices[G] do if color[v] = white then{If any vertices not discovered} DFS-Visit(v){Start a new tree with them} DFS-Visit(v) color[v] <- gray time <- time + 1 discovery[v] <- time for a in Adj[v] do if color[a] = white then pred[a] = v DFS-Visit[a] color[v] <- black time <- time + 1 finish[v] <- time

4 Example yzst uvwx vd[v]f[v]

5 Diagramming time intervals Plotting the start and finish times of each node in a DFS forest gives a nested structure (s (z (y (x x) y)(w w)z) s) (t (v v) (u u) t) s z y x w t vu

6 Parenthesis Theorem For two vertices, a and b, in a depth-first forest of G, exactly one of the following three holds: The intervals (discovery[a], finish[a]) and (discovery[b], finish[b]) are disjoint. The interval (discovery[a], finish[a]) is nested within (discovery[b], finish[b]). (This is true when a is a descendant of b). The interval (discovery[b], finish[b]) is nested within (discovery[a], finish[a]). (This is true when b is a descendant of a).

7 Topological Sort A directed acyclic graph (DAG) is a directed graph without cycles. A topological sort of a DAG = (V, E) is a linear ordering of vertices in V consistent with the partial order a < b if (a, b) is in E. In other words, each vertex in a topological sort must precede all its descendants in the DAG and must follow all its ancestors. Another way to look at it: A topological sort lines up all the vertices in the DAG so that all the edges point from left to right.

8 Algorithm for Topological sort Topological-Sort(G) 1)Call DFS(G) to compute the finish times f[v] for each vertex in v. 2)As each vertex is finished, insert it into the front of a linked list. 3)Return the linked list of vertices. Because each vertex is finished after all its descendants are finished, each vertex precedes all its descendants in the list. Running time = Running time of DFS + time to insert into list =  (V+E) +  (V) =  (V + E)

9 Example: Professor Bumstead gets dressed Professor Bumstead must put on certain items before others (e.g. socks before shoes). undershorts pants belt shirt tie jacket socks shoes watch We will work out the topological sort in class

10 Connected and Strongly Connected components A connected component of a graph is a maximal set of vertices such that for any two vertices, a and b, in the set, there is a path from a to b or from b to a. In other words: two vertices are in the same connected component if there is a path from one to the other. A strongly connected component of a graph is a maximal set of vertices such that for any two vertices, a and b, in the set, there is a path from a to b and from b to a. In other words: In a strongly connected component there is a path from every member of the set to every other member of the set. Importance: Decomposing a graph into its strongly connected components is the first step in many graph algorithms.

11 Algorithm for strongly connected components Definition: The transpose of G, written G T, is a graph with the same vertices as G in which the directions of the edges have been reversed. Strongly-Connected-Components(G) 1.Call DFS(G) to compute finish[v] for each vertex in G. 2.Call Modified-DFS(G T ), where the main loop of Modified- DFS(G T ) processes vertices in order of decreasing finish[v]. 3.Each tree in the depth-first forest of Modified-DFS(G T ) is a strongly connected component of G. Running time = running time of DFS =  (V + E)

12 Example abcd hgfe