Decision 1:: Graphs and
Networks
[email protected]
Last modified: 2nd October 2020
Decision 1 Overview
1:: Algorithms 2:: Graphs and networks
Sorting and bin What is a graph and how they 3:: Algorithms on graphs
packing. represent things. What algorithms do I need to
be able to apply?
4:: Route inspection
5:: The Travelling Salesman
Find the shortest route 6:: Linear Programming
Find the shortest route
which travels along all How to find an optimal
which visits all places.
roads solution graphically
7:: The simplex algorithm
8:: Critical path analysis
How to find an optimal
solution algebraically. How to plan a project.
2.1 Modelling with graphs
A graph consists of points (called vertices or nodes) which are connected
by lines (edges or arcs).
If a graph has a number associated with each edge (usually called its
weight), then the graph is known as a weighted graph or network.
These are both graphs, for both say…
1) Why is it a graph?
2) What do
(a) the vertices,
(b) the edges represent?
2.1 Modelling with graphs
150 E 60
A Watch out – a weighted
30 80 100 F
B graph is not normally
60 50 D 90 drawn to scale.
Server
80
100 C
The network shows the length of time (in ms)
for a ping between different computers on a
network.
a) Write down the time it would take for 50ms
computer B to ping computer D.
b) Write a list of the computers which are A, B and F
directly connected to computer E.
c) List some of the routes a signal could take Server-A-E-F
from the server to computer F. Server-B-D-F
Server-B-A-E-F
Server-C-D-B-E-F
Exercise 2A
Pearson Decision 1, Page 31 – probably just talk through this.
2.2 Graph theory terminology
B
A
F
D E
The vertices, or nodes are A, B, C, D, E and F, this list is sometimes called
the vertex set.
The edges, or arcs are AB, AC, AF, BC, BD, CE, CE and DE this list is
sometimes called the edge set.
Subgraphs
B
A
F
D E
A subgraph of G is a graph , each of whose vertices belongs to G and each of
whose edges belongs to G. It is simply a part of the original graph.
B B
A
C
F
D E D E
Two possible subgraphs of the graph above. Draw another subgraph in here
Degree or valency
B
A
F
D E
The degree or valency or order of a vertex is the number of edges incident to it.
Vertex Degree
If a vertex has even degree we
A 3
say it is even, similarly if the
B 3 vertex has odd degree we say
C 3 it is an odd vertex.
D 2
E 2
F 1 An odd vertex.
Test you understanding
B
A
The degree or valency or order of a vertex is the number of edges incident to it.
Vertex Degree
A 2
B 4
C 5
D 3
Walks, paths, trails and cycles
B
An example of a …
A Walk is FAEDFAB
Path is FAEC
C Trail is FABCEA
Cycle is FAEDF
F
Hamiltonian cycle
D E is FABCEDF
A walk is a route through a graph along edges from one vertex to the next.
A path is a walk in which no vertex is visited more than once.
A trail is a walk in which no edge is visited more than once.
A cycle is a walk in which the end vertex is the same as the start vertex and no
other vertex is visited more than once.
A Hamiltonian cycle is a cycle which includes every vertex.
LEARN ALL THESE DEFINITIONS!!!
Do not click this box. YOU WILL BE TESTED ON THESE NEXT LESSON!!!!
Test your understanding
B
A Walk is ABCDC
Path is ABCD
Trail is ABCDBFDB
Cycle is ADFA
F
Hamiltonian cycle
D C is ABCDF
A walk is a route through a graph along edges from one vertex to the next.
A path is a walk in which no vertex is visited more than once.
A trail is a walk in which no edge is visited more than once.
A cycle is a walk in which the end vertex is the same as the start vertex and no
other vertex is visited more than once.
A Hamiltonian cycle is a cycle which includes every vertex.
Do not click this box before you complete this slide…
Connected graphs
Two vertices are connected if there is a path between them. A graph is
connected if all its vertices are connected.
B
In this network A is connected
C to C but the network is not
connected because E is not
connected to the server.
A
If E were connected to any
other node the network would
E D
be said to be connected.
Make the graph connected…
Is the Great Britain mainland road network connected? Think then click.
Test your understanding
Which of these graphs are connected?
Connected Not connected
B
A
B
A
F
F D E
D C
Connected Not connected
B
A
F D
Loops and multiple edges
A loop is an edge which starts and finishes at the same vertex.
B
A
D
A loop
If a graph represented a
telephone network, why would
you want multiple edges?
Multiple edges So an organisation can make
multiple phone calls
simultaneously.
Simple graphs
A simple graph is one in which there are no loops and there is at most
one edge connecting any pair of vertices.
B
A
Two examples of simple graphs
C
F D
Source
Directed Graphs
A directed graph is one in which the edges of the graph have a
direction associated with them, the edges are known as directed
edges. Directed graph is often abbreviated to digraph.
A B
F D
Two examples of directed graphs
The Handshake Lemma
In any undirected graph, the sum of the degrees of the vertices is equal
to the number of edges, as a consequence, the number of odd vertices
must be even. This result is known as the handshake lemma.
B
A
On this graph there are 2
C odd vertices
B On this graph there are 4
A
odd vertices
C
Try and draw a graph with an
F odd number of odd vertices
D E and see what happens.
Test your understanding
Graham is attempting to draw a graph which has vertices of the
following orders.
State a restriction on the value of n which would make the graph
constructible?
must be odd, as if it was even there are three odd vertices.
Given that there are a total of 5 edges on the graph, draw it.
5 edges so the vertex sum is
10, trial and improvement
quickly leads to , with vertex
degrees
Exercise 2B
Pearson Decision 1, Page 37
Key words from this chapter – learn the definitions of all of them.
Cycle Nodes
Hamiltonian Cycle Vertices
Circuit Arcs
Degree Path
Valency Vertices
Order Walk
Weighted Graph Simple Graph
Digraph Sub Graph
Loop Connected graph
Edges Handshaking Lemma
2.3 Special types of graph
A tree is a connected graph with no cycles.
Bush Not a tree – contains a cycle
B B
A A
Tree C
F
D C D
Not a tree – not connected
B B
A
Tree C C
D E F D
2.3 Spanning trees
A spanning tree is a subgraph, which
includes all the vertices and is a tree.
Graph G Draw all the possible spanning trees of G
B B
A A
C
C
D
A B
D
C
B D
A B A
C C
A B
D B D
A C
C
D
D
2.3 Complete graphs
A complete graph is a graph in which every vertex is directly
connected by a single edge to each of the other vertices.
𝐾1 𝐾2 𝐾3
𝐾4 𝐾5 𝐾6
Test your understanding
How many edges are required to draw
There are 10 vertices each of which has degree 9, to the
degree sum of the graph is however you are counting
every edge twice, so there are 45 edges required in
How many edges are required to draw
Generalising the above, there are vertices each with
degree giving a total of edges.
Test your understanding
A table tennis tournament is designed so that every player plays each of the others. If there are 15 players,
how many games would be required?, How many tables would be required to play the tournament in the
minimum possible number of rounds?
The graph of represents this tournament which has edges, so 105 games.
Each player has 14 games to play, so if there were 7 tables all games could be played in 15 rounds.
Next round
Isomorphic graphs
Isomorphic graphs are graphs which show the same information
but may be drawn differently.
Is isomorphic to
B and B
A A E
Is isomorphic to
E C
F D F
C D
Test your understanding
Identify the two isomorphic graphs below and justify why they
are isomorphic.
A
B
A 1 B
3 C
D C
B
Graph 1 is isomorphic to graph 2.
On both graphs
C • Vertex A is directly connected to B and D
A
2 • Vertex B is directly connected to A, B
and with a double edge to C
D
• Vertex D is directly connected to A, B,
and with a double edge to C
• Vertex C is directly connected to with a
double edge to D and B and a loop
Exercise 2C
Pearson Decision 1, Page 40
Key words from this chapter – learn the definitions of all of them.
Tree
Spanning Tree
Complete Graph
Isomorphic
2.4 Representing graphs using matrices
An adjacency matrix represents a graph or network.
• In a non-weighted graph each entry describes the number of
arcs joining the corresponding vertices.
A B C
B
A 0 2 1
B 2 0 0 C
A
A B C D
C 1 0 0
A 0 2 1 1
B D
B 2 0 0 1
C 1 0 2 0
C
A
D 1 1 0 0
2.4 Representing graphs using matrices
An adjacency matrix represents a graph or network.
• In a distance matrix the entries represent the weight of each
arc, not the number of arcs.
A B C 23
A B
A - 23 10
10 14
B 23 - 14
C
C 10 14 - A B C D
A - 8 10 -
14 D
Notice – the matrix is B
B 8 - 23 14
symmetrical about the 7
8 23
leading diagonal this will be C 10 23 5 7
C
the case for any non-directed A
10
network. D - 14 7 -
5
2.4 Representing graphs using matrices
In a directed distance network, the matrix will not be
symmetrical.
• You must read the matrix along the rows, not down the
columns.
A B C D E 14
A B 8
A - 14 - - 2
2 C
B - - 8 - -
C - 8 - - - 12
E D
D - - 12 - -
6
E 2 - - 6 - A B C D
A - 2 - 11
2
A B
B - - 3 5
11 5 3
C - 3 - -
D C
7 D 11 5 7 -
Exercise 2D
Pearson Decision 1, Page 42
2.5 The Planarity Algorithm (A Level Only)
A planar graph is one that can be drawn in a plane such that no
two edges meet except at a vertex.
Before we go any further….
https://www.jasondavies.com/planarity/ ‘Tangled’ on the App Store,
𝐾4 𝐾5
𝐾3
Planar
Planar Looks non-planar
2.5 The Planarity Algorithm (A Level Only)
The planarity algorithm can be applied to graphs that contain a Hamiltonian
cycle:
1) Identify a Hamiltonian cycle.
2) Draw a polygon with vertices labelled to match the ones in the Hamiltonian
cycle.
3) Draw edges inside the polygon to match the edges of the original graph not
already represented.
4) Make a list of all the edges ‘inside’ the polygon.
5) Choose any unlabelled edge in your list and label it ‘I’. If all edges are now
labelled then the graph is planar.
6) Look at any unlabelled edges that cross the edge(s) just labelled.
• If there are none, then go back to (5)
• If any of these edges cross each other, then the graph is non-planar.
• If none of these edges cross each other, give them the opposite (I or O)
label to the edges just labelled.
• If all edges are now labelled, the graph is planar. Otherwise go back to
step 6.
Example
B 4) Make a list of all the inside edges
A
Edge
Edge I/O
I/O
H AF I 5) Choose AF and label it I.
G 6) Look at BC, BD, BH – None
BC O
C BD O cross each other, label them O.
F BH O 6) Look at BC, BD, BH – no
DH I unlabelled edges cross these so
E D
DG I go back to 5.
1) A Hamiltonian cycle is ABFCDEGHA
EH O
2) & 3) 5) Choose DH and label it I.
B
A B
F 6) No unlabelled edges
A
cross DH so go back to 5. F
H 5) Choose DG and label it I. H
C C
6) Look at EH – Label it (O),
G all labelled Planar G
D D
E
E
Test your understanding
Edge I/O Edge
Edge I/O
AE I BE O
FB O BD I All edges labelled, therefore graph is
planar.
AD I CE O
Exercise 2E
Pearson Decision 1, Page 46-47