ITP3902 DMS Lec 6 Graph Part2
ITP3902 DMS Lec 6 Graph Part2
Lecture 6 (Graph 2)
7
1 6
S 4 B
9 3 T
3
C
7
4
1
7
1 6
0
4 B 4 (S)
S
9 3 T
3
C 9(S)
7 4
1
D 7(S)
• Assign to vertex S potential 0.
• Label each vertex V reached directly from S with distance from S to V.
• Choose the smallest of these labels, and make it the potential of the
corresponding vertex or vertices.
ITP3902 Discrete Mathematics & Statistics Page 4
Lecture 6 Shortest Path Algorithm & Trees
9 3 T
3
C 7(SB)
7
4
1
D 77 (S)
• For each vertex V, look at each other vertex W reached directly from V until W
already has a smaller label.
7
1 6
0 4 4 (S)
S B
9 3 T 11 (SBA)
7 (SB)
3
7 C
4
1
D 7 (S)
7
1 6
0 4
S B 4 (S)
9 3 (SB) 3
T 10 (SBC)
7
7 C
4
1
7 (S)
D
• Finally, the shortest path from S to T is SBCT with path length 10.
8
Step 1 - Initialisation
Find the shortest path from A to F.
State the shortest distance from A to F.
9
Step 2 – General Step
Find the shortest path from A to F.
State the shortest distance from A to F.
10
Step 2 – General Step (cont.)
Find the shortest path from A to F.
State the shortest distance from A to F.
11
Step 2 – General Step (cont.)
Find the shortest path from A to F.
State the shortest distance from A to F.
12
Step 3 – STOP
Find the shortest path from A to F.
State the shortest distance from A to F.
13
The shortest path is: A – B – D – E – C – F.
The shortest distance is 25 units
Lecture 6 Shortest Path Algorithm & Trees
Trees
A tree is a connected graph which contains no cycles.
Example 2
# of vertices Tree Structure
1, 2, 3
4
5
Properties of Tree
Spanning Trees
Let G be a connected and undirected graph. A
spanning tree of G is a subgraph of G that connects all
the vertices of G together and is in a tree structure.
Example 3
Possible Spanning Trees of G
v w v w
Graph G
x x
v w
z y z y
x v w
z y x
2 4
D 5 A
6 15
7 9 7 12
C 8 B
E E
2 4 2
D 5 A D A
6 15
7 9 7 12
C 8 B C B
ITP3902 Discrete Mathematics & Statistics Page 21
Lecture 6 Shortest Path Algorithm & Trees
E E
2 4 2 4
D 5 A D A
6 15
7 9 7 12
C 8 B C B
ITP3902 Discrete Mathematics & Statistics Page 22
Lecture 6 Shortest Path Algorithm & Trees
2 4 2 4
D 5 A D A
6 15 6
7 9 7 12
C 8 B C B
ITP3902 Discrete Mathematics & Statistics Page 23
Lecture 6 Shortest Path Algorithm & Trees
2 4 2 4
D 5 A D A
6 15 6
7 9 7 12
C 8 B C 8 B
ITP3902 Discrete Mathematics & Statistics Page 24
Lecture 6 Shortest Path Algorithm & Trees
minimum
spanning tree