Graphs and
Networks
Königsberg bridges The Königsberg bridges is a
famous mathematics problem
inspired by an actual place and
situation.
The city of Königsberg on the
River Pregel in Prussia includes
two large islands which were connected to each other and
the mainland by seven bridges. The citizens of Königsberg
allegedly walked about on Sundays trying to find a route
that crossed each bridge exactly once, and returned to the
starting point.
Model it as a graph
where the edges
represent the bridges
and the vertices
represent the
islands.
Königsberg bridges Simplify the problem
Image from wiki commons
Königsberg bridges
Königsberg bridges
Königsberg bridges
Königsberg bridges In 1736 Leonhard Euler proved that it was not
possible because all the vertices of the
graph are odd.
Update: Kaliningrad
Two of the seven original bridges were destroyed during World War II. Two others were later demolished and replaced by a modern motorway.
The three other bridges remain, although only two
of them are from Euler's time (one was rebuilt in
1935).
Hence there are now only 5 bridges in Konigsberg.
Activity: The Icosian Game (a.k.a. A Voyage Round the World)
Find a closed cycle that visits every vertex exactly once.
D C
A
E B F H
J I
G
O
N
M L
K T
S R
Q P
Understand notation and terminology.
• Nodes/vertices; arcs/edges; node order;
• simple, complete, connected and bipartite graphs;
• walks, trails, paths, cycles and Hamilton cycles;
• trees; digraphs; planarity.
Be able to model appropriate problems by using graphs.
• e.g. Königsberg bridges;
• various river crossing problems;
• the tower of cubes problem;
• filing systems.
Graphs
MEI D1 January 2010 question 3
Link to the examination paper
Link to FMSP revision recordings for MEI D1
Graph Theory
Definitions Puzzle
Minimum Spanning
Tree
Networks
Be able to model and solve problems using networks
Minimum Connector (minimum spanning tree)
• Kruskal’s algorithm (on a network)
• Prim’s algorithm (on a network and on a table)
What sort of network is a ‘tree’?
Image from wiki commons
A problem A cable TV company based in Plymouth
wants to link all the towns on the map. To
keep costs to a minimum they want to
use as little cable as possible.
What strategy should they use to solve
the problem?
Spanning tree
of minimum
length
Minimum
connector
Kruskal’s algorithm
1. Select the shortest edge
in a network
2. Select the next shortest
edge which does not
create a cycle
3. Repeat step 2 until all
vertices have been
connected
Prim’s algorithm
1. Select any vertex
2. Select the shortest edge
connected to that vertex
3. Select the shortest edge
connected to any vertex
already connected
4. Repeat step 3 until all
vertices have been
connected
minimum connector algorithms
A cable company want to connect five villages to their network
which currently extends to the market town of Avonford. What is
the minimum length of cable needed?
Avonford Fingley
Brinleigh Cornwell
Donster
Edan
2
7
4 5
8 6 4
5
3
8
We model the situation as a network, then the
problem is to find the minimum connector for the
network
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
List the edges in
order of size:
ED 2
AB 3
AE 4
CD 4
BC 5
EF 5
CF 6
AF 7
BF 8
CF 8
Kruskal’s Algorithm
Select the shortest
edge in the network
ED 2
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Kruskal’s Algorithm
Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
A
F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Kruskal’s Algorithm
Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4 (or AE 4)
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Kruskal’s Algorithm
Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4
AE 4
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Kruskal’s Algorithm
Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4
AE 4
BC 5 – forms a cycle
EF 5
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Kruskal’s Algorithm
All vertices have been
connected.
The solution is
ED 2
AB 3
CD 4
AE 4
EF 5
Total weight of tree: 18
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Kruskal’s Algorithm
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Select any vertex
A
Select the shortest
edge connected to
that vertex
AB 3
Prim’s Algorithm
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Select the shortest
edge connected to
any vertex already
connected.
AE 4
Prim’s Algorithm
Select the shortest
edge connected to
any vertex already
connected.
ED 2
A
F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Prim’s Algorithm
Select the shortest
edge connected to
any vertex already
connected.
DC 4
A
F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Prim’s Algorithm
Select the shortest
edge connected to
any vertex already
connected.
CB 5 – forms a cycle
EF 5
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Prim’s Algorithm
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
All vertices have been
connected.
The solution is
AB 3
AE 4
ED 2
CD 4
EF 5
Total weight of tree: 18
Prim’s Algorithm
Kruskal’s
ED 2
AB 3
CD 4
AE 4
EF 5
Total weight of tree: 18
A F
B C
D
E
2
7
4 5
8 6 4
5
3
8
Prim’s
AB 3
AE 4
ED 2
CD 4
EF 5
Minimum Spanning Tree
A B C D E F
A - 3 - - 4 7
B 3 - 5 - - 8
C - 5 - 4 - 6
D - - 4 - 2 8
E 4 - - 2 - 5
F 7 8 6 8 5 -
First put the information from the network into a
distance matrix
Prim’s Algorithm on a Table
A B C D E F
A - 3 - - 4 7
B 3 - 5 - - 8
C - 5 - 4 - 6
D - - 4 - 2 8
E 4 - - 2 - 5
F 7 8 6 8 5 -
•Start at vertex A. Label column A “1” .
•Delete row A
•Select the smallest entry in column A (AB,
length 3)
1
Avenford
Brinleigh
3
A B C D E F
A - 3 - - 4 7
B 3 - 5 - - 8
C - 5 - 4 - 6
D - - 4 - 2 8
E 4 - - 2 - 5
F 7 8 6 8 5 -
1 •Label column B “2”
•Delete row B
•Select the smallest uncovered entry
in either column A or column B (AE,
length 4)
2
Avenford
Brinleigh
3
Edan
4
A B C D E F
A - 3 - - 4 7
B 3 - 5 - - 8
C - 5 - 4 - 6
D - - 4 - 2 8
E 4 - - 2 - 5
F 7 8 6 8 5 -
1 2 •Label column E “3”
•Delete row E
•Select the smallest uncovered
entry in either column A, B or E
(ED, length 2)
3
Avenford
Brinleigh
3
Edan
4
Donster
2
A B C D E F
A - 3 - - 4 7
B 3 - 5 - - 8
C - 5 - 4 - 6
D - - 4 - 2 8
E 4 - - 2 - 5
F 7 8 6 8 5 -
1 2 3 •Label column D “4”
•Delete row D
•Select the smallest uncovered
entry in either column A, B, D or E
(DC, length 4)
4
Avenford
Brinleigh
3
Edan
4
Donster
2
Cornwell
4
A B C D E F
A - 3 - - 4 7
B 3 - 5 - - 8
C - 5 - 4 - 6
D - - 4 - 2 8
E 4 - - 2 - 5
F 7 8 6 8 5 -
1 2 3 •Label column C “5”
•Delete row C
•Select the smallest uncovered
entry in either column A, B, D, E or
C (EF, length 5)
4 5
Avenford
Brinleigh
3
Edan
4
Donster
2
Cornwell
4 Fingley
5
A B C D E F
A - 3 - - 4 7
B 3 - 5 - - 8
C - 5 - 4 - 6
D - - 4 - 2 8
E 4 - - 2 - 5
F 7 8 6 8 5 -
1 2 3 4 5 FINALLY
•Label column F “6”
•Delete row F
6
Avenford
Brinleigh
3
Edan
4
Donster
2
Cornwell
4 Fingley
5 The spanning tree is shown
in the diagram
Length
3 + 4 + 4 + 2 + 5 = 18Km
•Both algorithms will always give solutions with the same
length.
•They will usually select edges in a different order – you
must show this in your workings.
•Occasionally they will use different edges – this may
happen when you have to choose between edges with the
same length. In this case there is more than one minimum
connector for the network.
Some points to note
Shortest Path
Problems
Networks Be able to model and solve problems using networks
Shortest Path – Dijkstra’s algorithm
Dijkstra’s Algorithm
4
3
7
1
4
2 4
7
2 5
3 2
A
C
D
B F
E
G
finds the shortest path from the start vertex to every other vertex
in the network. Find the shortest path from A to G
Order in which vertices are labelled.
Distance from A to vertex
Working
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
1 0
Label vertex A
1 as it is the first
vertex labelled
Dijkstra’s Algorithm
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
4
3
7
Update each vertex adjacent to A with a
‘working value’ for its distance from A.
1 0
Dijkstra’s Algorithm
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
4
3
7
2 3
Vertex C is closest
to A so we give it a
permanent label 3.
C is the 2nd vertex
to be permanently
labelled.
1 0
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
6 < 7 so
replace the
t-label here
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
The vertex with the smallest temporary label is B,
so make this label permanent. B is the 3rd vertex
to be permanently labelled. 3 4
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8 5 < 6 so
replace the
t-label here
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8
4 5
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8
4 5 7 < 8 so
replace the
t-label here
12
7 7 < 8 so
replace
the t-label
here
7
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8
4 5
12
7
7
5 7
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8
4 5
12
7
7
5 7
9 < 12 so
replace the
t-label here
9
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8
4 5
12
7
7
5 7 9
6 7
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8
4 5
12
7
7
5 7 9
6 7
11 > 9 so do
not replace
the t-label
here
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8
4 5
12
7
7
5 7 9
6 7
7 9
Dijkstra’s Algorithm
6
8
1 0
4
7
2 3
3
A
C
D
B F
E
G
4
3
7
1
4
2 4
7
2 5
3 2
3 4
5
8
4 5
12
7
7
5 7 9
6 7
7 9
The shortest path is ABDEG, with length 9.
Dijkstra’s Algorithm
1. Understand that a network is a graph with weighted arcs
2. Be able to model appropriate problems by using
networks
• Use in modelling ‘geographical’ problems and other problems
• e.g. translating a book, e.g. the knapsack problem.
3. The minimum connector problem
• Know and be able to use Kruskal's and Prim's algorithms
• Kruskal’s algorithm in graphical form only
• Prim’s algorithm in graphical or tabular form.
4. The shortest path from a given node to other nodes.
• Know and be able to apply Dijkstra's algorithm
Networks
MEI D1 January 2010 question 5
Link to the examination paper
Link to FMSP revision recording
MEI D1 January 2010 question 5
MEI D1 January 2010 question 5
12
10
22
11
6 26
5
13
MEI D1 January 2010 question 5
12
10
22
11
6 26
5
13
MEI D1 January 2010 question 5
12
10
22
11
6 26
5
13
Jeff Trim
Central Coordinator
& Area Coordinator, SE Region
Further Mathematics Support Programme