5A-Graphs1 _ Updated
5A-Graphs1 _ Updated
Graphs
Part 1
It has no multiple
A directed graph
edges and no loops
with multiple edges
An undirected graph
with loops
An undirected graph
with multiple edges
incident edges
Graph representations.
A graph (a) can be represented as
(b–c) an adjacency list.
Data Structures and Algorithms in Java 15/36
Graph Representation – 2
16
(Adjacency matrix)
• we can see that: the shortest path from vertex 1 to vertex 4 will be road
1-> 3-> 4.
• Dijkstra : 5 False
1 3
4 6
4
• If (1) – (2) – (3) is the shortest path from (1) – (3): weight = 8.
(1,2) also be the shortest path from (1) to (2) and (2,3) also be the shortest path
from (2) to (3)
pair Weight
4 – 1- 5 10
4–1–2 14
2–1-5 6
• With this matrix, we can get the shortest path of any pair of
vertices.
• Example:
– (2) – (4): 8
– (1) – (3): 7