dr_dos_ok - El

Algorithm Analysis and Design
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
4.1.2 Representations of graphs
For sparse graphs a simple representation technique is given by an
adjacency list which specifies all vertices which are adjacent to
each vertex in the graph. This list is typically implemented as a
table in which case it is referred to as a star representation. It can
also be implemented as a matrix (a two-dimensional table) in which
case it comes in two possible forms: an adjacency matrix or an
incidence matrix.
 An adjacency matrix, A, of graph G = (V, E) is a binary
matrix:
V Vsuch that each entry of the matrix
is:
1 if there exists an edge ( Vi , Vj )
A ij  
0 otherwise
 An incidence matrix, A, of graph G = (V, E) is a binary
matrix:
V Esuch that each entry of the matrix
is:
1 if edge E j is incident with vertex Vi
A ij  
0 otherwise
Figure 4.5 shows adjacency-list
representations of an undirected graph.
and
adjacency
matrix
77
Chapter 4 Graph Algorithms
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Figure 4.5 adjacency-list and adjacency matrix representations of an
undirected graph
Figure 4.6 adjacency-list and adjacency matrix representations of a
directed graph.
78
Algorithm Analysis and Design
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Figure 4.6 adjacency-list and adjacency matrix representations of a
directed graph
79
Chapter 4 Graph Algorithms
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Example let us represent graph shown in figure 4.7.
a
b
c
d
e
f
g
Figure 4.7 sample graph
The adjacency matrix:
a
b
c
d
e
f
g
a
b
c
d
e
f
g
80
a
0
0
1
1
0
1
0
b
0
0
0
1
1
0
0
The incident matrix:
ac
ad
af
1
1
1
0
0
0
1
0
0
0
1
0
0
0
0
0
0
1
0
0
0
c
1
0
0
0
0
1
0
d
1
1
0
0
1
1
0
bd
0
1
0
1
0
0
0
e
0
1
0
1
0
0
0
be
0
1
0
0
1
0
0
f
1
0
1
1
0
0
0
cf
0
0
1
0
0
1
0
g
0
0
0
0
0
0
0
de
0
0
0
1
1
0
0
df
0
0
0
1
0
1
0
Algorithm Analysis and Design
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Figure 4.8 shows the adjacency list.
Figure 4.8 The adjacency list
81