Graph Theory: Week 1 - Introduction to Graph Theory

17
Graph Theory: Week 1 Introduction to Graph Theory John Quinn August 30, 2010 John Quinn Graph Theory: Week 1

Transcript of Graph Theory: Week 1 - Introduction to Graph Theory

Page 1: Graph Theory: Week 1 - Introduction to Graph Theory

Graph Theory: Week 1

Introduction to Graph Theory

John Quinn

August 30, 2010

John Quinn Graph Theory: Week 1

Page 2: Graph Theory: Week 1 - Introduction to Graph Theory

The Tokyo subway

John Quinn Graph Theory: Week 1

Page 3: Graph Theory: Week 1 - Introduction to Graph Theory

Week 1 overview

I What are graphs?I Why study graph theory?I Examples of graphs in the real worldI Different types of graphsI Example problem: finding the shortest path

John Quinn Graph Theory: Week 1

Page 4: Graph Theory: Week 1 - Introduction to Graph Theory

What is a graph?

A

B

C

D F

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 – theimportant thing is which vertices are connected (adjacent)to each other.

John Quinn Graph Theory: Week 1

Page 5: Graph Theory: Week 1 - Introduction to Graph Theory

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 areconnected to other things”, which applies almosteverywhere.

I Some difficult problems become easy when representedusing a graph.

I There are lots of unsolved questions in graph theory: solveone and become rich and famous1.

1maybeJohn Quinn Graph Theory: Week 1

Page 6: Graph Theory: Week 1 - Introduction to Graph Theory

Graph example: Gnucleus peer connections

Source: cybergeography.org

John Quinn Graph Theory: Week 1

Page 7: Graph Theory: Week 1 - Introduction to Graph Theory

Graph example: Structure of the internet

Source: Internet Mapping Project

John Quinn Graph Theory: Week 1

Page 8: Graph Theory: Week 1 - Introduction to Graph Theory

Weighted graphs

A

B

C

D F

E

2

1

1

21

4

2

I Can extend graphs by associating a weight with each edge.I Might represent e.g. the cost of travelling between two

points.

John Quinn Graph Theory: Week 1

Page 9: Graph Theory: Week 1 - Introduction to Graph Theory

Directed graphs (digraphs)

A

B

C

D F

E

2

1

1

21

4

2

I Can also make edges directional.I This might now represent, for example, a network of

one-way streets.

John Quinn Graph Theory: Week 1

Page 10: Graph Theory: Week 1 - Introduction to Graph Theory

Bipartite graphs

I In this type of graph, the vertices are divided into two setsV = A ∪ B.

I There are no edges between vertices in the same set.

John Quinn Graph Theory: Week 1

Page 11: Graph Theory: Week 1 - Introduction to Graph Theory

Shortest path problems

I How would you go about finding the shortest path from oneplace 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

Page 12: Graph Theory: Week 1 - Introduction to Graph Theory

Dijkstra’s algorithm to find shortest distance fromvertex 1 to all other vertices

Start with a weighted graph G={V,E}, where a(i , j) is thedistance from vertex i to vertex j .

L(i) is the shortest distance from vertex 1 to vertex i . L’(i) is atemporary upper bound on L(i).

P ∈ V is the set of permanently labelled vertices. T is thecomplement 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 boundL’(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

Page 13: Graph Theory: Week 1 - Introduction to Graph Theory

I How could you prove that this algorithm always gives theshortest path?

I What is the complexity of this algorithm? If you tried it on acomputer and it took one second to find a shortest path ina graph with a million vertices, how long would it take for agraph with two million vertices?

John Quinn Graph Theory: Week 1

Page 14: Graph Theory: Week 1 - Introduction to Graph Theory

Another shortest path problem

A

B

C

D F

E

2

1

1

21

4

2

I What’s the shortest path between A and F, using Dijkstra’salgorithm?

John Quinn Graph Theory: Week 1

Page 15: Graph Theory: Week 1 - Introduction to Graph Theory

Facility location problemsGiven a map of a town, where should town planners put a newschool or police station?

In the case of a school, it might be best to put it such that theaverage distance from all buildings or houses is minimised(minsum). In the case of a police station, it might be best to putit such that the maximum distance to any building is minised(minimax).

I We can calculate both of these from the shortest distancematrix (a matrix for which d(i , j) is the shortest distancefrom i to j).

John Quinn Graph Theory: Week 1

Page 16: Graph Theory: Week 1 - Introduction to Graph Theory

New concepts this week

I Graphs as sets of edges and verticesI Different types of graphs: directed, undirected, bipartiteI Dijkstra’s algorithm to find shortest pathsI Facility location

John Quinn Graph Theory: Week 1

Page 17: Graph Theory: Week 1 - Introduction to Graph Theory

Programming exercises

We’ll be using the Python language to work on applications ofgraph theory.

Windows installation files for Python and other required librariesare on muele. Install Python, then the NetworkX and Matplotliblibraries.

On Linux, installation is even easier as Python should alreadybe installed. To set up the extra libraries on Ubuntu:sudo apt-get install python-networkx python-matplotlib

John Quinn Graph Theory: Week 1