25 Graphs and Adjacency Matricies

25 Graphs and Adjacency Matricies - Chapter 25: Graphs and...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 25: Graphs and adjacency matrices Motivation In the preceding chapter, we defined graphs and built them up using structures. This time, we show a particular representation of graphs called adjacency matrices, which allows us to manipulate graphs using MATLAB’s powerful matrix libraries. Adjacency Matrices The adjacency matrix is an alternative way to represent a graph. Let’s start with a graph whose nodes are already labeled with consecutive integer labels. In the adjacency matrix of the graph, the matrix element a( i , j ) = 1 if and only if there is an edge { i , j } in the graph, and a( i , j ) = 0 otherwise. Let’s look at an example: The edges of this graph are [{1, 2} {1, 3} {2, 3} {3, 4}]. When we convert to matrix form, we get: A = [ 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 ] For an undirected graph, if { i , j } exists, then both a( i , j ) and a( j , i ) must equal 1. So an adjacency matrix for an undirected graph is symmetric. The adjacency matrix representation is very simple (although not necessarily very efficient). Path Counting The adjacency matrix representation is very useful for analyzing paths in the graph. Suppose for example, we wanted to count all the paths in the graph that have length exactly 2, that is, they traverse two edges. Let A be the adjacency matrix of the graph,
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
and let B be a matrix that counts paths of length 2 defined like this, B( i , j ) = n , where n is the number of paths of length 2 from node i to node j . For any path of length 2 from i to j , there is an intermediate vertex k . There will be a path through k if and only if A( i , k ) = 1 and A( k , j ) = 1. Now for the clever part: the number of paths from i to j through k
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/12/2011 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 4

25 Graphs and Adjacency Matricies - Chapter 25: Graphs and...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online