Graph Theory: Week 1
Introduction to Graph Theory
John Quinn
August 30, 2010
John Quinn
Graph Theory: Week 1
The Tokyo subway
John Quinn
Graph Theory: Week 1
Week 1 overview
I
What are graphs?
I
Why study graph theory?
I
Examples of graphs in the real world
I
Different types of graphs
I
Example problem: finding the shortest path
John Quinn
Graph Theory: Week 1
What is a graph?
C
B
A
F
D
E
I
A graph G consists of a set of vertices and a set of edges.
G = {V,E}
in this example,
V = {A,B,C,D,E,F},
E = {AB, BC, BD, CD, DF, DE,EF}.
I
Any graph can be drawn on paper in many ways – the
important thing is which vertices are connected (adjacent)
to each other.
John Quinn
Graph Theory: Week 1
Why study graph theory?
I
Useful set of techniques for solving real-world problems –
particularly for different kinds of optimisation.
I
Graph theory is useful for analysing “things that are
connected to other things”, which applies almost
everywhere.
I
Some difficult problems become easy when represented
using a graph.
I
There are lots of unsolved questions in graph theory: solve
one and become rich and famous1 .
1
maybe
John Quinn
Graph Theory: Week 1
Graph example: Gnucleus peer connections
Source: cybergeography.org
John Quinn
Graph Theory: Week 1
Graph example: Structure of the internet
Source: Internet Mapping Project
John Quinn
Graph Theory: Week 1
Weighted graphs
C
2
1
1
B
4
1
2
A
I
I
F
D
2
E
Can extend graphs by associating a weight with each edge.
Might represent e.g. the cost of travelling between two
points.
John Quinn
Graph Theory: Week 1
Directed graphs (digraphs)
C
2
1
1
B
4
1
2
A
I
I
F
D
2
E
Can also make edges directional.
This might now represent, for example, a network of
one-way streets.
John Quinn
Graph Theory: Week 1
Bipartite graphs
I
In this type of graph, the vertices are divided into two sets
V = A ∪ B.
I
There are no edges between vertices in the same set.
John Quinn
Graph Theory: Week 1
Shortest path problems
I
How would you go about finding the shortest path from one
place to another on a graph?
I
A useful algorithm for doing this is Dijkstra’s algorithm.
Extra terminology:
Walk An alternating, connected, sequence of
vertices and edges.
Path A walk in which all the vertices are
unique.
Cycle A path which starts and ends in the
same place.
John Quinn
Graph Theory: Week 1
Dijkstra’s algorithm to find shortest distance from
vertex 1 to all other vertices
Start with a weighted graph G={V,E}, where a(i, j) is the
distance from vertex i to vertex j.
L(i) is the shortest distance from vertex 1 to vertex i. L’(i) is a
temporary upper bound on L(i).
P ∈ V is the set of permanently labelled vertices. T is the
complement of P. Initially, P={1}, L(1)=0 and L’(j)=a(1,j).
I
Step 1: Find a vertex k in T with the smallest upper bound
L’(k ). Add k to P, and set L(k ) = L’(k ).
I
Step 2: Set L’(j) = min[L’(j), L(k )+a(j, k )]
I
Stop when P=V.
John Quinn
Graph Theory: Week 1
I
How could you prove that this algorithm always gives the
shortest path?
I
What is the complexity of this algorithm? If you tried it on a
computer and it took one second to find a shortest path in
a graph with a million vertices, how long would it take for a
graph with two million vertices?
John Quinn
Graph Theory: Week 1
Another shortest path problem
C
2
1
1
B
4
1
2
A
I
F
D
2
E
What’s the shortest path between A and F, using Dijkstra’s
algorithm?
John Quinn
Graph Theory: Week 1
Facility location problems
Given a map of a town, where should town planners put a new
school or police station?
In the case of a school, it might be best to put it such that the
average distance from all buildings or houses is minimised
(minsum). In the case of a police station, it might be best to put
it such that the maximum distance to any building is minised
(minimax).
I
We can calculate both of these from the shortest distance
matrix (a matrix for which d(i, j) is the shortest distance
from i to j).
John Quinn
Graph Theory: Week 1
New concepts this week
I
Graphs as sets of edges and vertices
I
Different types of graphs: directed, undirected, bipartite
I
Dijkstra’s algorithm to find shortest paths
I
Facility location
John Quinn
Graph Theory: Week 1
Programming exercises
We’ll be using the Python language to work on applications of
graph theory.
Windows installation files for Python and other required libraries
are on muele. Install Python, then the NetworkX and Matplotlib
libraries.
On Linux, installation is even easier as Python should already
be installed. To set up the extra libraries on Ubuntu:
sudo apt-get install python-networkx python-matplotlib
John Quinn
Graph Theory: Week 1
© Copyright 2026 Paperzz