Week 15 graphs
Week 15 graphs
Week 15 and 16
Dr. sohail
Objectives
• Today’s lecture objectives include:
– 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 4
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 6
Graph – Introduction…
Moral of the Story
7 is adjacent from 5
K2,3 K4,5
R digraph(R) MR
2 1 1 1 1
1 1
2 2 0 1 1 1
3
1
1
3 3 0 0 1
4 4 0 1
4 0 0
Data Structures & Algorithms 15
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 16
Graph Applications
• Modelling a road network with vertices as towns and edge costs as
distances.
• Minimising the cost and time taken for air travel when direct flights don't
exist between starting and ending airports.
• Using a directed graph to map the links between pages within a website
and to analyse ease of navigation between different parts of the site.
• Bipartite Graph
• Adjacency Matrix