Computing an Adjacency Matrix D. J. Foreman

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Graph Algorithms
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, …,
Epp, section 10.? CS 202 Aaron Bloomfield
CS 253: Algorithms Chapter 22 Graphs Credit: Dr. George Bebis.
Analysis of Algorithms CS 477/677
Graph Theory Arnold Mesa. Basic Concepts n A graph G = (V,E) is defined by a set of vertices and edges v3 v1 v2Vertex (v1) Edge (e1) A Graph with 3 vertices.
Every edge is in a red ellipse (the bags). The bags are connected in a tree. The bags an original vertex is part of are connected.
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
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.
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Degree A F H G B E D C. Adjacent A F H G B E D C.
The Shortest Path Problem
Graphs, relations and matrices
“I can find all the factors of a whole number.”
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CSCI 115 Chapter 8 Topics in Graph Theory. CSCI 115 §8.1 Graphs.
Relation. Combining Relations Because relations from A to B are subsets of A x B, two relations from A to B can be combined in any way two sets can be.
Graph Theory. undirected graph node: a, b, c, d, e, f edge: (a, b), (a, c), (b, c), (b, e), (c, d), (c, f), (d, e), (d, f), (e, f) subgraph.
 Please go through this PowerPoint, you may print it and highlight important ideas, or take notes  At the very end of the slide there are some questions.
Decision Maths 1 Shortest path algorithm Dijkstra’s Algorithm A V Ali :
Dijkstra animation. Dijksta’s Algorithm (Shortest Path Between 2 Nodes) 2 Phases:initialization;iteration Initialization: 1. Included:(Boolean) 2. Distance:(Weight)
Design and Analysis of Algorithms Introduction to graphs, representations of a graph Haidong Xue Summer 2012, at GSU.
1 Closures of Relations Based on Aaron Bloomfield Modified by Longin Jan Latecki Rosen, Section 8.4.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
Subject Four Graphs Data Structures. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes.
1 1 Slide © 2005 Thomson/South-Western Chapter 9 Network Models n Shortest-Route Problem n Minimal Spanning Tree Problem n Maximal Flow Problem.
Kleene’s Theorem and NFA
Aaron Bloomfield CS 202 Rosen, section 7.4
Matrix Representation of Graphs
Graph Representations
Dijkstra’s shortest path Algorithm
“I can find all the factors of a whole number.”
More NP-complete Problems
Mathematical Structures for Computer Science Chapter 6
Shortest Path Problems
Shortest Path Problems
Party-by-Night Problem
Lecture 7 All-Pairs Shortest Paths
Chapter 9: Graphs Basic Concepts
Angle Addition Postulate
Walks, Paths, and Circuits
Shortest Path Problems
Square Roots.
Shortest Path Algorithms
Designing Algorithms for Multiplication of Fractions
All pairs shortest path problem
“I can find all the factors of a whole number.”
Lecture 10: Graphs Graph Terminology Special Types of Graphs
Shortest Path Problems
Computing an Adjacency Matrix D. J. Foreman
Graphs G = (V, E) V are the vertices; E are the edges.
“I can find all the factors of a whole number.”
Shortest Path Problems
Graph Vocabulary.
“I can find all the factors of a whole number.”
Closures of Relations Epp, section 10.1,10.2 CS 202.
“I can find all the factors of a whole number.”
Chapter 9: Graphs Basic Concepts
All Pairs Shortest Path Examples While the illustrations which follow only show solutions from vertex A (or 1) for simplicity, students should note that.
GRAPHS.
Directed Graphs (Part II)
Presentation transcript:

Computing an Adjacency Matrix D. J. Foreman Graphs Computing an Adjacency Matrix D. J. Foreman

The Graph & it's Adj1 A To B A B C D E F 1 D C From F E

Algorithm for Computing Adj2 If Adj[i,1] && Adj[1,j] == 1  path of length 2 from i to j through node 1 Therefore, If ANY Adj[i,n] && Adj[n,j] == 1, for all n, then  a path Length=2 from i to j. Thus, for [i, j] compute: Adj[i,1] && Adj[1,j] || Adj[i,2] && Adj[2,j] || … || Adj[i,n] && Adj[n,j] Repeat for all i and j

Computation for 1 pair (A to B) Let A-F be replaced by 1-6 Find a length 2 path from i=1 to j=2 adj[1,1] && adj[1,2]=0 && 1=>0 adj[1,2] && adj[2,2]=1 && 0=>0 adj[1,3] && adj[3,2]=1 && 1=>1 (13  2) adj[1,4] && adj[4,2]=1 && 0=>0 adj[1,5] && adj[5,2]=0 && 0=>0 adj[1,6] && adj[6,2]=0 && 1=>0 Now "or" these together  Adj[1,2] So  a path of length 2 from A to B (through C) See the red edges in previous slide

Adj[i,1] && Adj[1,j] || Adj[i,2] && Adj[2,j] || … || Adj[i,n] && Adj[n,j] 3 4 5 6 1 2 3 4 5 6 Adj[1] Adj[2]

Key Points Adj (by itself) only tells if a path EXISTS Does NOT tell what the path IS Adj1 * Adj2  Adj3 (path of length 3) Computations describe edges in path Same as regular matrix multiply, but replace * with && + with ||