Title: Graph Representations
1Graph Representations
- There are two main ways of representing graphs in
a computer - The adjacency matrix representation.
- The adjacency list representation.
2Graph Representations
The adjacency matrix representation
1 if (v, w) ? E
M(v, w)
0 otherwise
A B C D E F
0 1 0 1 0 0
A B C D E F
B
1 0 1 0 0 0
C
A
0 1 0 1 1 0
F
1 0 1 0 1 0
D
0 0 1 1 0 0
E
0 0 0 0 0 0
3Graph Representations
The adjacency matrix representation
1 if (v, w) ? E
M(v, w)
0 otherwise
A B C D E F
0 1 0 1 0 0
A B C D E F
B
1 0 1 0 0 0
C
A
0 1 0 1 1 0
F
1 0 1 0 1 0
D
0 0 1 1 0 0
E
0 0 0 0 0 0
4Graph Representations
The adjacency list representation
L(v) list of w such that (v, w) ? E, for v
? V
A B C D E F
B
D
B
C
A
C
A
B
D
E
F
A
E
C
D
E
C
D
5Graph Representations
The adjacency list representation
How much space ?
A B C D E F
B
D
B
C
A
C
A
B
D
E
F
A
E
C
D
E
C
D
6Graph Representations
The adjacency list representation
Space a V 2 b E
a
b
A B C D E F
B
D
B
C
A
C
A
B
D
E
F
A
E
C
D
E
C
D
7Graph Representations
The adjacency matrix representation,
again, this time representing a directed graph.
A B C D E F
0 1 0 1 0 0
A B C D E F
B
0 0 1 0 0 0
C
A
0 0 0 0 1 0
F
0 0 1 0 0 0
D
0 0 0 1 0 0
E
0 0 0 0 0 0
8Graph Representations
The adjacency list representation, again, this
time representing a directed graph.
A B C D E F
B
D
B
C
C
A
E
F
C
D
E
D
9Graph Representations
The adjacency list representation, again, this
time representing a directed graph.
How much space?
A B C D E F
B
D
B
C
C
A
E
F
C
D
E
D
10Graph Representations
The adjacency list representation, again, this
time representing a directed graph.
Space a V b E
a
b
A B C D E F
B
D
B
C
C
A
E
F
C
D
E
D