2. 88
A matrix (plural: matrices) is simply an ‘array’ of numbers, e.g.
But the power of matrices comes from being able to multiply matrices by vectors
and matrices by matrices and ‘invert’ them: we can:
1. represent linear transformations using matrices (e.g. rotations, reflections
and enlargements)
2. Use them to solve linear simultaneous equations.
The first of these means matrices are particularly useful in 3D
graphics/animation, since they allow us to rotate the camera and project 3D
data onto a 2D viewing plane. But matrices are used everywhere, including
robotics, computer vision, optimisation, classical and quantum mechanics,
electromagnetism, optics, graph theory, statistics, ...
On a simple level, a matrix is simply a way to organise values into rows and columns,
and represent these multiple values as a single structure.
▷ 2 ▷ Introduction to matrices
3. 88
The zero matrix, 𝑍 or 𝟎 is the matrix with zero as each element.
The identity matrix is the matrix with ones on its main diagonal.
The 2x2 identity matrix is 𝐼 =
1 0
0 1
And has the property that 𝐼𝐴 = 𝐴𝐼 = 𝐴
In general, matrix multiplication is not commutative, i.e. 𝐴𝐵 ≠ 𝐵𝐴
It is, however, associative, i.e. 𝐴 𝐵𝐶 = 𝐴𝐵 𝐶
▷ 3 ▷ Introduction to matrices
4. 88
The dimension of a matrix is its size, in terms of its number of rows and columns.
2 3
3 1
1 3
A matrix can have square or curvy brackets*.
Matrix Column Vector
(The vector you know
and love)
Row Vector
So a matrix with one column is simply a vector in the usual sense.
▷ 4 ▷ Introduction to matrices
5. 88
If we wish a variable to represent a matrix, we use bold, capital letters.
𝑨 =
1
6
−3
𝑪 = 𝑷−𝟏𝑻𝑷
Each value within a matrix is known as an element.
If A is a matrix, then we can refer to the element in the ith row and jth
column as 𝑎𝑖,𝑗.
𝑐1,2 = 3 𝑐2,1 = 4 𝑐1,3 = −7
▷ 5 ▷ Introduction to matrices
6. 88
Simply add/subtract the corresponding elements of each matrix.
They must be of the same dimension.
▷ 6 ▷ Adding/Subtracting Matrices
7. 88 ▷ 7 ▷ Vectors
A row vector is a 1 × 𝑛 matrix and a column vector is a
𝑛 × 1 vector. Vectors have similar properties to matrices
(in terms of addition and subtraction) although have their
own form of multiplication.
There are two ways to multiply vectors – dot product and
cross product. We only look at dot product which is (for a
3D vector)
𝑎
𝑏
𝑐
⋅
𝑥
𝑦
𝑧
= 𝑎𝑥 + 𝑏𝑦 + 𝑐𝑧
For example:
1
4
⋅
2
−1
= 1 × 2 + 4 × −1 = 2 − 4 = −2
8. 88
A scalar is a number which can ‘scale’ the elements inside a matrix/vector.
1
2
3
▷ 8 ▷ Scalar Multiplication
9. 88
This is where things get slightly more complicated...
1 0 3 -2
2 8 4 3
7 -1 0 2
5 1
1 7
0 3
8 -3
-11
We start with this row and
column, and sum the products
of each pair.
(1 x 5) + (0 x 1) + (3 x 0) + (-2 x
8) = -11
This is known as finding the
“dot/scalar product” of the two
vectors.
16
Now repeat for the next row of the left matrix...
42 61
50 -6
▷ 9 ▷ Matrix Multiplication
10. 88
=
1 2 3
1
2
3
= 14
1
2
3
1 2 3 =
1 2 3
2 4 6
3 6 9
a
b
c
d
e
f
▷ 10 ▷ Matrix Multiplication
11. 88
Matrix multiplications are not always valid: the dimensions have to agree.
Note that only square matrices (i.e. same width as height) can be raised to a power.
Dimensions of A Dimension of B Dimensions of AB (if valid)
2 3 3 4 2 4
1 3 2 3 Not valid.
6 2 2 4 6 4
1 3 3 1 1 1
7 5 7 5 Not valid.
10 10 10 9 10 9
3 3 3 3 3 3
▷ 11 ▷ Matrix Multiplication
12. 88
The transpose of a matrix is formed by swapping the columns and row.
For example, if 𝐴 =
𝑎 𝑏
𝑐 𝑑
, then 𝐴𝑇
=
𝑎 𝑐
𝑏 𝑑
The determinant of a 2x2 matrix is 𝑎𝑑 − 𝑏𝑐, written as det 𝐴 = 𝑎𝑑 − 𝑏𝑐. The inverse is:
𝐴−1
=
1
𝑎𝑑 − 𝑏𝑐
𝑑 −𝑏
−𝑐 𝑎
We can use this to solve simultaneous equations
i.e.
𝑎𝑥 + 𝑏𝑦 = 𝑒
𝑐𝑥 + 𝑑𝑦 = 𝑓
Becomes 𝐴𝑥 = 𝑏 or
𝑎 𝑏
𝑐 𝑑
𝑥
𝑦 =
𝑒
𝑓
Which means that: 𝑥 = 𝐴−1
𝑏, or
𝑥
𝑦 =
𝑎 𝑏
𝑐 𝑑
−1 𝑒
𝑓
▷ 12 ▷ Matrix transpose / Inverse
15. 88 ▷ 15 ▷ Applications
Graph theory is important to find:
a) Shortest distance between two points
b) Search engine optimisation
c) Communications
d) Travelling salesperson problem
e) Graph colouring (used for parallel computing)
f) Data science
16. 88 ▷ 16 ▷ Introduction
Graph theory is not about the sort of graphs you did at school!
18. 88 ▷ 18 ▷ What is a graph?
1. A graph is a set of vertices (V) and
edges (E)
2. Each edge in E has two endpoints
which connect two elements of V
(Possibly the same element)
3. In an undirected graph, edges have
no specific direction, and can be
considered to connect a to b or b to
a
4. In a directed graph, edges do have a
specific direction
5. The number of endpoints at a vertex
is called the degree of that vertex
19. 88 ▷ 19 ▷ Representing Graphs
We can represent a graph with a
diagram.
The vertices are blobs
Undirected edges are lines
a
b
c
e
d
g
f
20. 88 ▷ 20 ▷ Representing Graphs
We can represent a graph with a
diagram.
The vertices are blobs
Undirected edges are lines
Directed edges are arrows
a
b
c
e
d
g
f
21. 88
Definition
▷ 21 ▷ Terminology
The degree of a vertex in an undirected graph is the
number of edges incident to it, except that a loop
contributes twice to the degree.
The degree of a vertex 𝑣 is denoted by deg(𝑣)
deg 𝑎 = 2
deg 𝑏 = 4
deg 𝑔 = 0
For any graph 𝐺 the sum of the degrees for all vertices equals to the number of edges
multiplied by two.
That is, 2𝑚 = σ𝑣∈𝑉 deg(𝑣) where 𝑚 is the number of edges in the graph 𝐺 = (𝑉, 𝐸)
22. 88
My Turn Your Turn
▷ 22 ▷ Degrees of Vertices Example
Find the number of vertices, the number of edges and
the degree of each vertex in the given undirected
graph. Identify all isolated and pendant vertices.
𝑣 = 6
𝑒 = 6
deg 𝑎 = 2
deg 𝑏 = 4
deg 𝑐 = 1
deg 𝑑 = 0
deg 𝑒 = 2
deg 𝑓 = 3
𝑐 is pendant (vertex has degree 1) and 𝑑
is isolated (vertex has degree 0).
Find the number of vertices, the number of edges and
the degree of each vertex in the given undirected
graph. Identify all isolated and pendant vertices.
𝑣 = 5
𝑒 = 12
deg 𝑎 = 5
deg 𝑏 = 6
deg 𝑐 = 5
deg 𝑑 = 5
deg 𝑒 = 3
There are no isolated or pendent vertices as
none of the vertices have degree 0 or 1
23. 88 ▷ 23 ▷ Handshaking Lemma
Every edge has two endpoints
The sum of all the endpoints in a
graph must be even.
If there are n edges, there must be
2𝑛 endpoints
This is known as the "Handshaking
Theorem"
The sum of all the endpoints in a
graph is equal to the sum of all the
vertex degrees
The sum of all vertex degrees must
be even
𝑣∈𝑉
deg 𝑣 = 2|𝐸|
𝑣∈𝑉
deg 𝑣
= deg 1 + deg 2 + deg 3 + deg 4 + deg 5 + deg(6)
= 2 + 3 + 2 + 3 + 3 + 1 = 14
2 𝐸 = 2 × 7 = 14 (7 edges in the graph)
24. 88
Definition
▷ 24 ▷ Definition of Graph Using Sets
We can represent graphs with sets
G = (V, E)
V = set of vertices, e.g {a,b,c,d,e}
E = set of edges
• e.g. Undirected: E = { {a,b}, {b,c}, {d,e} }
• e.g. Directed: E = { (a,b), (b,c), (d,e) }
25. 88
Definition
▷ 25 ▷ Simple graphs
A graph in which each edge connects two different
vertices and where no two edges connect the same pair of
vertices is called a simple graph
A simple graph: And not simple:
What makes the simple graph different to a non-simple graph?
26. 88
Definition
▷ 26 ▷ Simple Graph
Simple Graph
• Simple graphs are UNDIRECTED
• Edges connect two different vertices
• So no loops on vertices
• Maximum of one edge between any pair of vertices
Simple Directed Graph
• Same – but edges are directed
NOTE: To avoid confusion this
module will standardise on
the common definition of a
simple graph as UNDIRECTED
(as found in Rosen)
27. 88
Definition Characteristics
Examples Non-Examples
▷ 27 ▷ Frayer Diagram
Simple
Graph
a simple graph is an unweighted, undirected graph
containing no loops or multiple edges. It can be either
connected or disconnected
28. 88
• An undirected graph is connected if there is at least one path
between any two vertices
• A directed graph is strongly connected if there is at least one path
between any two vertices that follows all the directions of the edges
• A directed graph is weakly connected is there is at least one path
between any two vertices that ignores all the directions of the edges
29. 88
• A bridge is an edge which, if removed, would cause the graph to
become disconnected
a c
b
d
f
e
30. 88
• A graph that is not connected has two or more connected
components.
• These components are disjoint
• The union of all components is the original graph
a c
b
d
f
e
31. 88
Definition
▷ 31 ▷ Adjacency List
A table with 1 row per vertex, listing its adjacent vertices.
a b
d
c
f
e
Vertex
Adjacent
Vertices
a
b
b, c
a, c, e, f
c a, b, f
d
e b
f c, b
32. 88
Definition
▷ 32 ▷ Adjacency Matrix
A way to represent simple graphs
• possibly with self-loops.
Matrix A=[aij], where aij is 1 if {vi, vj} is an edge of G, and is
0 otherwise.
Can extend to pseudographs by letting each matrix
elements be the number of links (possibly >1) between the
nodes.
37. 88
• The complete graph Kn
• For any nN, a complete graph on n vertices, Kn, is a simple graph
with n nodes in which every node is adjacent to every other node:
u,vV: uv{u,v}E.
• A set of n vertices – all connected to each other
K1 K2
K3
K4
K5 K6
Note that Kn has edges.
2
)
1
(
1
1
−
=
−
=
n
n
i
n
i
38. 88
• The cycle graph Cn
• A set of n vertices (n ≥3) { c1, c2, c3, … , cn }
• A set of edges { {c1,c2}, {c2,c3}, {c3, c4}, …, {cn-1, cn} }
C3 C4 C5 C6 C7
C8
How many edges are there in Cn?
39. 88
• The wheel graph Wn
• A set of n+1 vertices (n ≥4) { v, c1, c2, c3, … , cn }
• A set of edges { {c1,c2}, {c2,c3}, {c3, c4}, …, {cn-1, cn} }
∪
{ {v,c1}, {v,c2}, {v,c3}, …, {v, cn} }
• For any n3, a wheel Wn, is a simple graph obtained by taking the cycle Cn
and adding one extra vertex vhub and n extra edges {{vhub,v1},
{vhub,v2},…,{vhub,vn}}.
W3 W4 W5 W6 W7
W8
How many edges are there in Wn?
40. 88
• The n-cube Qn
• A set of 2n vertices
• Each vertex represents a bit string
• A set of edges
• Each edge connects two vertices that differ by one bit
Q0
Q1 Q2 Q3
Q4
Number of vertices: 2n. Number of edges:Exercise to try!
41. 88
• To draw the n-cube Qn
• Start with Q1
• Duplicate it
• Prefix the original vertices with "0"
• Prefix the duplicate vertices with "1"
• Connect the corresponding vertices
00 01
10 11
42. 88
• To draw the n-cube Qn
• Start with Q2
• Duplicate it
• Prefix the original vertices with "0"
• Prefix the duplicate vertices with "1"
• Connect the corresponding vertices
000 001
010 011
100 101
110 111
43. 88
• A graph is bipartite if its vertices can be divided into two subsets, so
that every edge connects a vertex in one subset to a vertex in the
other.
• Here the subsets are {a,b,c} and {d,e}
a b c
d e
44. 88
• A graph is bipartite if its vertices can be divided into two subsets, so
that every edge connects a vertex in one subset to a vertex in the
other.
• Here the subsets are {a,b,c} and {d,e}
a b c
d e
45. 88
• A bipartite graph is complete if every edge in one subset is connected
to every edge in the other
• The complete bipartite graph of m vertices in one subset and n
vertices in the other is denoted Km,n
a b c
d e
This is the complete
bipartite graph K3,2
K4,3
Km,n has _____ nodes
and _____ edges.
46. 88
• Diagrams can be drawn anyhow
• Vertices can go anywhere
• Lines can cross (and in some cases, must cross)
• With practice, you'll discover how to improve neatness.
47. 88 ▷ 47 ▷ Special simple graphs
A complete graph on 𝑛 vertices 𝐾𝑛
A cycle 𝐶𝑛 𝑛 ≥ 3
A wheel 𝑊
𝑛
48. 88 ▷ 48 ▷ Bipartite graphs
A simple graph 𝐺 is called bipartite if its vertex set 𝑉 can
be partitioned into two disjoint sets 𝑉1 and 𝑉2 such that
every edge in the graph connects a vertex in 𝑉1 and a
vertex in 𝑉2
𝐾𝑚,𝑛: a complete bipartite graph with 𝑉1 = 𝑚 and
𝑉2 = 𝑛
49. 88 ▷ 49 ▷ Graph isomorphism
Informally (you will see a formal definition of graph
isomorphism later during the course):
There is a useful terminology for graphs with the same
structure
50. 88 ▷ 50 ▷ Graph isomorphism
Which graphs are isomorphic?
52. 88
Classification
Simple ?
Connected ?
Directed ?
Multigraph ?
Kn ?
Cn ?
Bipartite ?
Km,n ?
Classification
Simple
Connected ✓Strong
Directed ✓
Multigraph
Kn
Cn
Bipartite
Km,n
a b
NOTE: To avoid confusion this
module will standardise on
the common definition of a
simple graph as UNDIRECTED
(as found in Rosen)