Learn

Graph Theory, Networks and Voronoi Diagrams

Contents

In graph theory a graph is not a chart. It is a set of points, called vertices, and a set of connections between them, called edges. A road map is a graph once you keep only which places are joined.

The subject began in 1736, when Euler showed that no walk could cross each of the seven bridges of Königsberg exactly once. His argument used only the connections, never the shape of the town.

What are the parts of a graph?

Vertices, drawn as dots, and edges, drawn as lines. The degree of a vertex is the number of edge ends that meet it.

The degree of a vertex counts the edges meeting it, so B has degree 3. Full lesson: Vertices, Edges and Degree

Add up every degree and the total is twice the number of edges, because each edge adds 1 at each of its two ends. So the number of odd-degree vertices is always even. See Vertices, Edges and Degree.

A simple graph has no loop and at most one edge between any pair of vertices. A complete graph joins every pair, so on n vertices it has n(n − 1)/2 edges. A bipartite graph splits the vertices into two sets, and every edge runs from one set to the other. See Simple, Complete and Bipartite Graphs.

A complete graph joins every pair. Four vertices give 6 edges, and every degree is 3. Full lesson: Simple, Complete and Bipartite Graphs

A graph is connected when a route joins every pair of vertices. A tree is a connected graph with no cycle, and a tree on n vertices has exactly n − 1 edges: each new vertex needs one edge to join the tree, and a second edge would close a cycle. See Subgraphs, Connectedness and Trees.

There are six vertices and five edges. A tree always has one fewer edge than vertices. Full lesson: Subgraphs, Connectedness and Trees

A directed graph gives every edge an arrow. Arrows arriving give the in-degree and arrows leaving give the out-degree, and the graph is strongly connected when the arrows lead from any vertex to any other. See Directed Graphs and Strong Connectedness.

Now you

These are the degrees of a graph. How many edges does it have?

What is the degree of vertex D?

How do you store a network as numbers?

In a table with one row and one column for each vertex. Write 1 in row A, column B when an edge joins A to B, and 0 when none does. Without the labels, the numbers are the adjacency matrix. It is symmetric across the main diagonal, and each row total is a degree. See The Adjacency Matrix.

Take the labels off and the numbers stand alone: the adjacency matrix. Full lesson: The Adjacency Matrix

Multiply the matrix by itself. Row i, column j of counts the walks of length 2 from i to j, because the product adds up, over every middle vertex k, the ways of going from i to k and then to j. In the same way Aⁿ counts the walks of length n. See Counting Walks with Matrix Powers.

Multiply the matrix by itself. Row A, column D holds 1: one walk of length 2. Full lesson: Counting Walks with Matrix Powers

A weighted graph carries a number on each edge: a distance, a cost or a time. The table holds that weight in place of the 1. See The Weighted Adjacency Table.

A route costs the sum of the weights along it, so A to B to D costs 4 + 6 = 10. Full lesson: The Weighted Adjacency Table

Now you

What is the degree of vertex C?

What goes in row A, column B of the adjacency matrix?

What do the route words actually mean?

Each word says what may repeat. A walk is any sequence of edges, each one starting where the last ended. A trail uses no edge twice. A path uses no vertex twice. A circuit is a trail that ends where it began, and a cycle is a circuit that repeats no vertex except the one at both ends. See Walks, Trails, Paths, Circuits and Cycles.

A circuit is a trail that ends where it began: A-B-C-D-E-C-A. Full lesson: Walks, Trails, Paths, Circuits and Cycles

An Eulerian circuit is a closed trail that uses every edge exactly once. A connected graph has one exactly when every vertex has even degree. With exactly two odd vertices the graph has an Eulerian trail instead, from one odd vertex to the other.

The reason is a count. Each time a trail passes through a vertex it uses one edge to arrive and one to leave, so every vertex except the start and the finish needs an even degree, and those two each have one unpaired edge. Any other number of odd vertices allows neither, and Königsberg had four. See Eulerian Trails and Circuits.

One edge arrives and one leaves at each visit, so passing through needs an even degree. Full lesson: Eulerian Trails and Circuits
With four odd vertices no trail can cover every edge: the bridges of Königsberg. Full lesson: Eulerian Trails and Circuits

A Hamiltonian cycle visits every vertex exactly once and returns to the start. There is no degree test for it, so routes have to be tried one by one. See Hamiltonian Paths and Cycles.

Now you

Does this graph have an Eulerian circuit?

A connected graph has exactly two vertices of odd degree. What follows?

What is the cheapest way to connect everything?

With a minimum spanning tree: a set of edges that joins every vertex, has no cycle, and has the least total weight. Two greedy algorithms find one, meaning each step takes the cheapest edge available without looking ahead.

Kruskal's algorithm sorts the edges by weight and works down the list. Take each edge unless it would close a cycle, and stop when n − 1 edges are in. See Kruskal's Algorithm for a Spanning Tree.

B to C, weight 5, would close the cycle A-B-C. Reject it and move on. Full lesson: Kruskal’s Algorithm for a Spanning Tree

Prim's algorithm grows one tree from a starting vertex: at each step take the cheapest edge that leaves the tree and reaches a new vertex. The matrix method runs it on the weighted table. Cross out the column of each vertex in the tree, find the smallest entry left in the rows of those vertices, circle it, and that vertex joins. See Prim's Algorithm and the Matrix Method.

The smallest entry in row A is 2, in column C. Circle it, and C joins the tree. Full lesson: Prim’s Algorithm and the Matrix Method

Now you

Which edge does Kruskal add last?

Which of these edges does Kruskal reject?

Routes that must cover everything

The Chinese postman problem asks for the shortest closed route that uses every edge at least once. If every vertex has even degree, an Eulerian circuit does it. Otherwise pair up the odd vertices, find the shortest route between each pair, and walk those edges twice. With four odd vertices there are three ways to pair them, so cost all three and take the cheapest. See The Chinese Postman Problem.

B to C direct costs 4, and going around by D costs 6 + 2 = 8, so take the direct street. Full lesson: The Chinese Postman Problem

The traveling salesman problem asks for the cheapest cycle that visits every vertex once. No efficient exact method is known, so the answer is trapped between an upper bound and a lower bound. See The Traveling Salesman Problem.

The nearest-neighbor algorithm builds a tour: start at a vertex, always move to the nearest vertex not yet visited, and return home at the end. The best tour cannot cost more than a tour already in hand, so this cost is an upper bound. See The Nearest-Neighbor Upper Bound.

Another tour costs only 22, so 28 is an upper bound and not the cheapest tour. Full lesson: The Nearest-Neighbor Upper Bound

For a lower bound, delete one vertex and every edge that touches it, find a minimum spanning tree of what is left, and add back the two cheapest deleted edges. Every tour uses two edges at the deleted vertex and at least a spanning tree of the rest, so no tour can cost less. See The Deleted-Vertex Lower Bound.

Every tour uses two roads at A, and its other roads join B, C, D and E, which costs at least 11, so no tour can cost under 20. Full lesson: The Deleted-Vertex Lower Bound

How does a Voronoi diagram answer "what is nearest"?

By dividing the plane before the question is asked. The points equally far from two sites A and B lie on the perpendicular bisector of AB, and that line splits the plane into the side nearer A and the side nearer B.

The points equally far from A and B make the perpendicular bisector of AB. Full lesson: Voronoi Diagrams

With more sites, draw the bisector of every pair and keep, for each site, the piece of the plane where it is nearest. Each piece is a cell, so the nearest site to any point is read off from the cell it lies in. See Voronoi Diagrams.

Each piece is a cell: every point in it is nearer to that site than to any other. Full lesson: Voronoi Diagrams

To find the equation of the edge between A at (1, 2) and B at (5, 4), first find the midpoint of AB, which is (3, 3). The gradient of AB is (4 − 2) ÷ (5 − 1) = 1/2, so the perpendicular gradient is the negative reciprocal, −2. The edge is the line through (3, 3) with gradient −2: y − 3 = −2(x − 3), which rearranges to y = −2x + 9. See The Equation of a Voronoi Edge.

Adding a new site cuts a new cell out of its neighbors, so the cells around it can only shrink. See Finding the Nearest Site.

The toxic waste dump problem asks for the point farthest from every site. Inside a cell you can always step farther from the nearest site, so the answer is at a Voronoi vertex, where three sites are equally near, or on the border of the region. Test every vertex and every corner and keep the largest circle that contains no site: its center is the answer. See The Toxic Waste Dump Problem.

The circle through those three towns holds no town inside it: an empty circle. Full lesson: The Toxic Waste Dump Problem

A Voronoi cell is a polygon, so its area comes from its corners by ordinary mensuration. See The Area of a Voronoi Cell.

Now you

What is the equation of the Voronoi edge between A and B?

The gradient of AB is 1/2. What is the gradient of the Voronoi edge?

The mistakes worth naming

Where this leads next

Matrix powers count walks here in the same way they track probabilities in the matrices and Markov chains guide. A Voronoi edge is found with the midpoint and gradient methods of the coordinate geometry guide. The degree count and the Königsberg argument are counting proofs of the kind set out in the logic and proof guide.

Learn this properly in the app

Math Challenge teaches each of these as an illustrated lesson, with the network drawn and the algorithm run one step at a time, followed by practice questions with worked explanations.

Your turn

Three to try — tap what you get.

A triangle graph has how many edges?

A walk that uses every edge exactly once is

A Voronoi cell holds the points nearest to

Math ChallengePractice that adapts to you, the whole lesson ladder, and your progress saved.
Start with Math Challenge

Mr. Chalk Practice this lesson in the app