Document 10489475

advertisement
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.
Königsberg bridges
Simplify the problem
Model it as a graph
where the edges
represent the bridges
and the vertices
represent the
islands.
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.
A
G
E
M
L
F
R
K
H
S
Q
P
T
N
O
J
D
I
C
B
Graphs
 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.
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
minimum connector algorithms
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
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?
5
Brinleigh
Cornwell
3
4
6
8
8
Avonford
7
Donster
Fingley
5
4
2
Edan
We model the situation as a network, then the
problem is to find the minimum connector for the
network
5
B
C
3
4
6
8
8
A
D
F
7
5
4
2
E
Kruskal’s Algorithm
B
List the edges in
order of size:
5
C
3
4
6
8
8
A
D
F
7
5
4
2
E
ED
AB
AE
CD
BC
EF
CF
AF
BF
CF
2
3
4
4
5
5
6
7
8
8
Kruskal’s Algorithm
B
Select the shortest
edge in the network
5
C
ED 2
3
4
6
8
8
A
D
F
7
5
4
2
E
Kruskal’s Algorithm
B
5
Select the next shortest
edge which does not
create a cycle
C
3
4
6
8
ED 2
AB 3
8
A
D
F
7
5
4
2
E
Kruskal’s Algorithm
B
5
Select the next shortest
edge which does not
create a cycle
C
3
4
6
8
ED 2
AB 3
CD 4 (or AE 4)
8
A
D
F
7
5
4
2
E
Kruskal’s Algorithm
B
5
Select the next shortest
edge which does not
create a cycle
C
3
4
6
8
ED
AB
CD
AE
8
A
D
F
7
5
4
2
E
2
3
4
4
Kruskal’s Algorithm
B
5
Select the next shortest
edge which does not
create a cycle
C
3
4
6
8
8
A
D
F
7
5
4
2
E
ED
AB
CD
AE
BC
EF
2
3
4
4
5 – forms a cycle
5
Kruskal’s Algorithm
B
All vertices have been
connected.
5
C
3
4
6
8
The solution is
8
A
D
F
7
5
4
2
E
ED
AB
CD
AE
EF
2
3
4
4
5
Total weight of tree: 18
Prim’s Algorithm
B
Select any vertex
5
A
C
3
4
6
8
Select the shortest
edge connected to
that vertex
8
A
D
F
7
5
4
2
E
AB 3
Prim’s Algorithm
B
5
Select the shortest
edge connected to
any vertex already
connected.
C
3
6
8
AE 4
4
8
A
D
F
7
5
4
2
E
Prim’s Algorithm
B
5
Select the shortest
edge connected to
any vertex already
connected.
C
3
6
8
ED 2
4
8
A
D
F
7
5
4
2
E
Prim’s Algorithm
B
5
Select the shortest
edge connected to
any vertex already
connected.
C
3
6
8
DC 4
4
8
A
D
F
7
5
4
2
E
Prim’s Algorithm
B
5
Select the shortest
edge connected to
any vertex already
connected.
C
3
6
8
CB 5 – forms a cycle
4
EF 5
8
A
D
F
7
5
4
2
E
Prim’s Algorithm
B
All vertices have been
connected.
5
C
3
4
6
8
The solution is
8
A
D
F
7
5
4
2
E
AB
AE
ED
CD
EF
3
4
2
4
5
Total weight of tree: 18
Minimum Spanning Tree
B
5
3
6
8
8
A
C
F
5
7
4
2
E
Kruskal’s
4
ED
AB
D CD
AE
EF
2
3
4
4
5
Prim’s
AB
AE
ED
CD
EF
3
4
2
4
5
Total weight of tree: 18
Prim’s Algorithm on a Table
First put the information from the network into a
distance matrix
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
A
B
C
D
E
F
A
-
3
-
-
4
7
•Select the smallest entry in column A (AB, B
length 3)
C
3
-
5
-
-
8
-
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
Brinleigh
3
Avenford
•Label column B “2”
1
2
•Delete row B
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
-
•Select the smallest uncovered entry
in either column A or column B (AE,
length 4)
Brinleigh
3
Avenford
4
Edan
1
•Label column E “3”
•Delete row E
•Select the smallest uncovered
entry in either column A, B or E
(ED, length 2)
Brinleigh
3
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
-
Donster
2
Edan
3
A
Avenford
4
2
•Label column D “4”
1
2
4
3
A
B
C
D
E
F
•Delete row D
A
-
3
-
-
4
7
•Select the smallest uncovered
entry in either column A, B, D or E
(DC, length 4)
Cornwell
Brinleigh
B
3
-
5
-
-
8
C
-
5
-
4
-
6
D
-
-
4
-
2
8
E
4
-
-
2
-
5
F
7
8
6
8
5
-
3
4
Avenford
Donster
4
2
Edan
•Label column C “5”
1
2
5
4
3
•Delete row C
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
-
•Select the smallest uncovered
entry in either column A, B, D, E or
C (EF, length 5)
Cornwell
Brinleigh
3
4
Fingley
Avenford
Donster
5
4
2
Edan
FINALLY
1
2
5
4
•Label column F “6”
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
-
•Delete row F
3
6
Cornwell
Brinleigh
3
4
Fingley
Avenford
Donster
5
4
2
Edan
The spanning tree is shown
in the diagram
Length
3 + 4 + 4 + 2 + 5 = 18Km
Some points to note
•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.
Shortest Path
Problems
Networks
Be able to model and solve problems using networks
Shortest Path – Dijkstra’s algorithm
Dijkstra’s Algorithm
finds the shortest path from the start vertex to every other vertex
in the network. Find the shortest path from A to G
B
4
F
4
1
2
7
A
4
D
7
3
3
2
G
C
5
E
2
Order in which
vertices are
labelled.
Dijkstra’s Algorithm
B
1
Working
4
4
0
F
1
2
7
A
Distance
from A to
vertex
4
D
7
Label vertex A
1 as it is the first
vertex labelled
3
3
2
G
C
5
E
2
Dijkstra’s Algorithm
Update each vertex adjacent to A with a
‘working value’ for its distance from A.
4
B
1
4
4
0
1
F
2
7
7
A
4
D
7
3
3
2
G
C
3
5
E
2
Dijkstra’s Algorithm
4
B
1
4
4
0
1
F
2
7
7
A
4
D
7
3
3
Vertex C is closest
to A so we give it a
permanent label 3.
C is the 2nd vertex
to be permanently
labelled.
2
G
5
C
2
3
3
E
2
Dijkstra’s Algorithm
4
B
1
4
4
0
1
6 < 7 so
replace the
t-label here
2
7 6
7
A
F
4
D
7
3
3
2
G
5
C
2
3
E
3
8
2
3
4
The vertex with the smallest temporary label is B,
so make this label permanent. B is the 3rd vertex
to be permanently labelled.
4
B
1
4
4
0
1
F
2
7 6
7
A
4
D
7
3
3
2
G
5
C
2
3
E
3
8
2
Dijkstra’s Algorithm
3
4
4
B
1
4
0
5 < 6 so
replace the
t-label here
4
1
2
7 6 5
7
A
F
8
4
D
7
3
3
2
G
5
C
2
3
E
3
8
2
Dijkstra’s Algorithm
3
4
4
B
1
4
4
0
F
4
5
7 6 5
1
7
A
2
8
4
D
7
3
3
2
G
5
C
2
3
E
3
8
2
Dijkstra’s Algorithm
3
4
4
B
1
4
4
0
F
4
5
7 6 5
1
7
A
8 7
7 < 8 so
replace the
4t-label here
2
D
7
3
3
2
G
5
C
2
3
E
3
8 7
2
12
7 < 8 so
replace
the t-label
here
Dijkstra’s Algorithm
3
4
4
B
1
4
4
0
F
4
5
7 6 5
1
7
A
2
8 7
4
D
7
3
3
2
G
5
C
2
3
3
2
E
5
8 7
7
12
Dijkstra’s Algorithm
3
4
4
B
1
4
4
0
F
4
5
7 6 5
1
7
A
2
8 7
4
D
7
3
3
2
G
5
C
2
3
3
2
E
5
8 7
7
12 9
9 < 12 so
replace the
t-label here
Dijkstra’s Algorithm
3
4
4
B
1
4
4
0
F
4
5
7 6 5
1
7
A
2
6
7
8 7
4
D
7
3
3
2
G
5
C
2
3
3
2
E
5
8 7
7
12 9
Dijkstra’s Algorithm
3
4
4
B
1
4
4
0
F
4
5
7 6 5
1
7
A
2
6
7
8 7
4
D
7
3
3
2
G
5
C
2
3
3
2
E
5
8 7
7
12 9
11 > 9 so do
not replace
the t-label
here
Dijkstra’s Algorithm
3
4
4
B
1
4
4
0
F
4
5
7 6 5
1
7
A
2
6
7
8 7
4
D
7
3
3
2
G
5
C
2
3
3
2
E
5
8 7
7
7
9
12 9
Dijkstra’s Algorithm
3
4
4
B
1
4
4
0
F
4
5
7 6 5
1
7
A
2
6
7
8 7
4
D
7
3
3
2
G
5
C
2
3
3
2
E
5
8 7
7
The shortest path is ABDEG, with length 9.
7
9
12 9
Networks
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
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
22
13
12
11
10
6
26
5
MEI D1 January 2010 question 5
22
13
12
11
10
6
26
5
MEI D1 January 2010 question 5
22
13
12
11
10
6
26
5
Jeff Trim
jefftrim@furthermaths.org.uk
Central Coordinator
& Area Coordinator, SE Region
Further Mathematics Support Programme
Download