Graph
Graph
– Graph introduction
– Bipartite Graph
– Adjacency Matrix
V: set of vertices
• Example:
V = {a, b, c, d, e}
E = {(a, b), (a, c),
(a, d), (b, e),
(c, d), (c, e),
(d, e)}
B
Data Structures & Algorithms 3
Graph – Introduction…
Example
• This is also a graph. The vertices just happen to have people’s
names (e.g., first character).
• Such a graph could represent friendships (or any kind of
relationship).
F B L
R A P
L R
F
Previous figure
A F B L
B
P Z Z
R A P
Data Structures & Algorithms 5
Graph – Introduction…
Moral of the Story
• One graph may be drawn in (infinitely) many ways, but it always
provides us with the same information.
• Graphs are a structure for describing relationships between
objects.
– The vertices denote the objects and the edges represent the relationship.
7 is adjacent from 5
R digraph(R) MR
2 1 1 1 1
1 1 0 1 1 1
1 3
2 2 0 0 1 1
3 3
0 0 0 1
4 4 4
Data Structures & Algorithms 13
Adjacency Matrix
Q: What is the adjacency matrix?
1 4 3
0 3 0 1
A: 0 1 2 0
0 1 2 0
0 0 0 0
Data Structures & Algorithms 14
Graph Applications
• Modelling a road network with vertices as towns and edge costs as
distances.
• Modelling a water supply network.
• Bipartite Graph
• Adjacency Matrix