2.2
Representing Graphs as Adjaceny Matrices
An alternate representation of is known as an adjacency matrix. In this data structure, a
matrix is established such that
|
|
|
(1) |
The storage required to implement an adjacency matrix is
proportional to . When
is represented as an adjacency matrix, the best time complexity you
can expect for graph algorithms
is . This is the time required to access each element of the
matrix exactly one time.
Once again consider the directed graph of Figure 1. Its
adjacency matrix
follows.
|
|
|
The adjacency matrix of the undirected version of the
graph (Figure 2) is as
follows.
|
|
|
Observe that the adjacency matrix of an undirected graph
is symmetric.