Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.

Slides:



Advertisements
Similar presentations
1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine.
Advertisements

Lecture 15. Graph Algorithms
Coloring Warm-Up. A graph is 2-colorable iff it has no odd length cycles 1: If G has an odd-length cycle then G is not 2- colorable Proof: Let v 0, …,
CS 473Lecture 131 CS473-Algorithms I Lecture 13-A Graphs.
Representing Relations Rosen 7.3. Using Matrices For finite sets we can use zero-one matrices. Elements of each set A and B must be listed in some particular.
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
8.3 Representing Relations Connection Matrices Let R be a relation from A = {a 1, a 2,..., a m } to B = {b 1, b 2,..., b n }. Definition: A n m  n connection.
CompSci 102 Discrete Math for Computer Science April 19, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Reachability as Transitive Closure
Transitive Closure Theorem 1. Let R be a relation on a set A. Then R  is the transitive closure of R. the reachability relation R * of a relation R on.
Advanced Algorithm Design and Analysis (Lecture 7) SW5 fall 2004 Simonas Šaltenis E1-215b
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22.
Discussion #33 Adjacency Matrices. Topics Adjacency matrix for a directed graph Reachability Algorithmic Complexity and Correctness –Big Oh –Proofs of.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
1 Chapter 22: Elementary Graph Algorithms IV. 2 About this lecture Review of Strongly Connected Components (SCC) in a directed graph Finding all SCC (i.e.,
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Discussion #34 1/17 Discussion #34 Warshall’s and Floyd’s Algorithms.
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
Representing Relations Using Matrices
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
1 Representing Graphs. 2 Adjacency Matrix Suppose we have a graph G with n nodes. The adjacency matrix is the n x n matrix A=[a ij ] with: a ij = 1 if.
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.
DAST 2005 Tirgul 11 (and more) sample questions. DAST 2005 Q.Let G = (V,E) be an undirected, connected graph with an edge weight function w : E→R. Let.
1 Data Structures and Algorithms Graphs I: Representation and Search Gal A. Kaminka Computer Science Department.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
Algorithms All pairs shortest path
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Discrete Math for CS Chapter 8: Directed Graphs. Discrete Math for CS digraph: A digraph is a graph G = (V,E) where V is a finite set of vertices and.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
All-Pairs Shortest Paths
CS 473 All Pairs Shortest Paths1 CS473 – Algorithms I All Pairs Shortest Paths.
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.
Graphs, relations and matrices
MATRICES. Matrices A matrix is a rectangular array of objects (usually numbers) arranged in m horizontal rows and n vertical columns. A matrix with m.
Applied Discrete Mathematics Week 10: Equivalence Relations
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
1 WEEK 9-10 Graphs II Unweighted Shortest Paths Dijkstra’s Algorithm Graphs with negative costs Acyclic Graphs Izmir University of Economics.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
Chapter 2 Graph Algorithms.
1 Closures of Relations: Transitive Closure and Partitions Sections 8.4 and 8.5.
Slide Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
Parallel Programming: All-Pairs Shortest Path CS599 David Monismith Based upon notes from multiple sources.
The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every.
Chapter 10 Graph Theory Eulerian Cycle and the property of graph theory 10.3 The important property of graph theory and its representation 10.4.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Matrices Section 2.6. Section Summary Definition of a Matrix Matrix Arithmetic Transposes and Powers of Arithmetic Zero-One matrices.
1 Chapter Equivalence, Order, and Inductive Proof.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
All-Pairs Shortest Paths
Great Theoretical Ideas in Computer Science for Some.
C&O 355 Lecture 19 N. Harvey TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A A A A A A A A.
COMPSCI 102 Introduction to Discrete Mathematics.
1 Closures of Relations Based on Aaron Bloomfield Modified by Longin Jan Latecki Rosen, Section 8.4.
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
1 Lecture 5 (part 2) Graphs II (a) Circuits; (b) Representation Reading: Epp Chp 11.2, 11.3
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Matrix Representation of Graphs
Algorithm Analysis Fall 2017 CS 4306/03
Mathematical Structures for Computer Science Chapter 6
Graphs Chapter 13.
Graphs G = (V, E) V are the vertices; E are the edges.
Discrete Mathematics for Computer Science
Negative-Weight edges:
Directed Graphs (Part II)
Presentation transcript:

Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these matrices to study graphs is path algebra. With "path algebra" we can solve the following problems: Compute the total number of paths between all pairs of vertices in a directed acyclic graph; Solve the "all-pairs-shortest-paths" problem in a weighted directed graph with no negative cycles; Compute the "transitive" closure of a directed graph. Think: what is the meaning of M 2 where M is an adjacency matrix of a graph G?

All paths of length r Claim. M r describes paths of length r in G, with entry i,j denoting number of distinct paths from i to j, here, M is the adjacency matrix of G. Proof. The base case is r = 0, trivial. For the induction step, assume the claim is true for r' < r; we prove it for r. Then M r ij = (M · M r-1 ) ij = ∑ 1 ≤ k ≤ n M ik M r-1 kj Now any r-step path from i to j must start with a step to some intermediate vertex k. If there is such a path, M ik is 1; otherwise it is 0. So adding up M ik M r-1 kj gives the number of r-step paths.

Computing the matrix powers Suppose G is acyclic (no path longer than n-1). Consider I + M + M M n-1 : the ij'th entry gives the total number of distinct paths from i to j. Therefore, in O(n ω+1 ) steps, we can compute the total number of distinct paths between all pairs of vertices. Here ω denotes the best-known exponent for matrix multiplication; currently ω = We can even do better, if n=2 k, by first calculating M 2, M 4,..., M 2^(k-1), and then calculating (I+M)(I+M 2 )(I+M 4 )...(I+M 2^(k-1) ) = I + M + M M 2^k–1, where 2 k is the least power of 2 that is ≥ n. This gives an algorithm that runs in O(n ω log n) time, where n is the number of vertices.

Reachability graph Given an un-weighted directed graph G = (V,E), and we want to form the graph G' that has an edge between u and v if and only if there exists a path (of any length) in G from u to v. Let's first see how to solve it using what we know from say CS 240. There, we explored depth-first and breadth-first search algorithms. These algorithms could find all vertices reachable from a given vertex in O(|V|+|E|) time. So if we run depth-first search from every vertex, the total time is O(n(|V|+|E|), which could be as bad as O(n 3 ) if the graph is dense. Can we do better than O(n 3 )?

Transitive closure Back to path algebra. Now our matrix M consists of 1's and 0's. How can we find the matrix where there's a 1 in row i and column j iff there is a length-2 path connecting vertex i and j? I claim the entry in row i and column j should be OR 1 ≤ k ≤ n M ik AND M kj. That is: we just need to use “boolean multiplication and additions in our matrix computation. So the transitive closure of G is given by M' = I + M + M M n-1 where +, * are corresponding boolean operations. It tells if there is a path between any two nodes.

Transitive closure continues.. How fast can we compute: I + M + M M n-1 ? we can multiply 2 Boolean matrices in O(n ω ) steps. Since, using the “doubling trick”, we have to do log n Boolean matrix multiplications, this gives a total cost of O(n ω log n) to solve the transitive closure problem. This is indeed better than simply running breadth-first or depth-first search from each vertex. Think: what if n is not a power of 2?