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?
A graph is built from vertices, drawn as dots, and edges, drawn as lines joining pairs of vertices. Each vertex has a degree: the number of edge ends that meet it. The handshake lemma links the two: the degrees always add to twice the number of edges. A square with one diagonal has 5 edges, and its vertices have degrees 3, 2, 3 and 2, so 3 + 2 + 3 + 2 = 10 = 2 × 5. The lemma holds because every edge has two ends, and each end adds 1 to one degree. A loop, an edge from a vertex back to itself, adds 2 to that vertex's degree. One consequence: the number of odd-degree vertices is always even, because the total is even. So a group in which exactly three people each shake an odd number of hands is impossible. Check a drawing by counting its edges twice, once directly and once as half the degree total.
each edge contributes 1 to two vertices, so Σ deg(v) = 2|E|
Add edges until the sum of degrees is 10
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 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 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.
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?
A network is stored as an adjacency matrix: a square table with one row and one column for each vertex. Write 1 in row A, column B when an edge joins A and B, and 0 when none does. For a triangle ABC with a vertex D joined only to C, the rows read A: 0 1 1 0, B: 1 0 1 0, C: 1 1 0 1 and D: 0 0 1 0. See The Adjacency Matrix. It is symmetric across the main diagonal, since every edge joins its two vertices both ways, and each row total is a degree: row C gives 1 + 1 + 0 + 1 = 3. In a directed graph, row A, column B records only arrows from A to B, so symmetry is lost. Check the table by adding the row totals: 2 + 2 + 3 + 1 = 8, twice the 4 edges.
each edge sets aᵢⱼ = aⱼᵢ = 1, so A equals its own transpose
Add edges until the table holds six 1s
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 counts the walks of length n. See 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.
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 route word says what a route may repeat. A walk is any sequence of edges, each starting where the last ended, and it may repeat anything. A trail repeats no edge. A path repeats no vertex, and so no edge either. Circuits are trails that end where they began, and a cycle is a circuit that repeats no vertex except the start. See Walks, Trails, Paths, Circuits and Cycles. On a square ABCD with the diagonal AC, the route A-B-C-A-D is a trail but not a path, because it returns to A. The words matter because route questions depend on what may be reused: covering every street is about edges, and visiting every town is about vertices. Two triangles sharing a vertex A show the gap between a circuit and a cycle: A-B-C-A-D-E-A uses every edge once but passes through A midway, so it is not a cycle. Its length, the number of edges, is 3 + 3 = 6.
odd vertices = 2, so an Euler trail exists, but it must run from one odd vertex to the other
Add edges until you can trace every edge once and finish where you started
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.
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?
The cheapest way to connect every vertex is a minimum spanning tree: edges that join all the vertices, contain no cycle, and have the least total weight. Kruskal's algorithm finds one by taking edges cheapest first and skipping any that would close a cycle. Take four towns with roads AB = 2, BC = 3, AC = 4, CD = 5 and BD = 6. Kruskal takes AB and BC, rejects AC because A, B and C are already joined, then takes CD, for a total of 2 + 3 + 5 = 10. A tree on 4 vertices needs 4 − 1 = 3 edges, so it stops there. The greedy choice is safe because the cheapest edge across any split of the vertices into two groups belongs to some minimum tree. Equal weights may be taken in either order, which can give different trees with the same total. To confirm, swapping CD for BD costs 2 + 3 + 6 = 11.
2 roads taken so far, none closing a loop: a tree on V towns needs exactly V − 1 = 5
Take the roads in cost order until all six towns are joined
See 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.
Now you
Which edge does Kruskal add last?
How many edges does the minimum spanning tree of these five towns have?
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.
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.
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.
How does a Voronoi diagram answer "what is nearest"?
A Voronoi diagram divides the plane into cells, one per site, and every point in a cell is nearer to that site than to any other. The nearest site to any point is then read from its cell, with no distances to compare. The border between sites A and B lies on the perpendicular bisector of AB, because that line holds exactly the points equally far from both. For A at (0, 0) and B at (6, 0), the bisector is the vertical line x = 3. A point at (2, 5) is on A's side: its squared distances are to A and to B. With three or more sites, each cell is cut down by the bisectors with its neighbors, and cell edges meet at vertices equally far from three sites. Test a point on the border: (3, 4) is 5 from both sites, since .
each wall of P's cell is the perpendicular bisector of P and one tower — |x − P| = |x − S| on it, |x − P| < |x − S| inside — and the cell touches 4 of the 4
Drag P until it is the same distance from its two nearest towers
With more sites, draw the bisector of every pair and keep, for each site, the piece of the plane where it is nearest. See 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 , 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, every corner and every point where a cell edge meets the border, and keep the largest circle that contains no site: its center is the answer. See 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 . What is the gradient of the Voronoi edge?
The mistakes worth naming
- Mixing up Eulerian and Hamiltonian. Eulerian is about edges and Hamiltonian is about vertices.
- Counting a loop once. A loop adds 2 to the degree, one for each end.
- Taking one edge too many in Kruskal's algorithm. A spanning tree on n vertices has n − 1 edges.
- Treating the nearest-neighbor tour as the best tour. It is an upper bound, and often not a close one.
- Drawing Voronoi edges by eye. Each edge is a perpendicular bisector, so find the midpoint and the perpendicular gradient.
- Trusting the drawing. Two drawings of the same graph can look nothing alike. Only the connections count.
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.
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
Questions and answers
- What is the difference between an Eulerian and a Hamiltonian path?
- An Eulerian trail uses every edge exactly once, and a Hamiltonian path visits every vertex exactly once. The difference matters enormously in practice: whether a graph has an Eulerian trail is settled by counting odd-degree vertices, which takes seconds, while deciding whether a Hamiltonian cycle exists has no known efficient test at all. Two questions that sound like mirror images have completely different difficulty.
- When can a network be drawn without lifting your pen?
- When it is connected and has either zero or exactly two vertices of odd degree. With no odd vertices you can start anywhere and return to your start, giving a closed circuit. With exactly two, you must start at one odd vertex and finish at the other. Any other number of odd vertices makes it impossible, because every visit to a vertex uses one edge in and one out.
- What is a minimum spanning tree used for?
- It is the cheapest set of connections that links every point in a network with no redundancy, so it is the answer to questions about laying cable, pipe or road to reach every site at the least total cost. It has one fewer edge than it has vertices and contains no cycles. Kruskal's and Prim's algorithms both find one, and both are greedy, meaning each step takes the cheapest option available without looking ahead.
- What is the Chinese postman problem?
- It asks for the shortest closed route that travels along every edge of a network at least once, which is the problem faced by a postal round, a gritting lorry or a street inspector. If every vertex has even degree the answer is an Eulerian circuit with no repetition. Otherwise the odd vertices must be paired up and the shortest paths between each pair repeated, so the extra distance is the smallest total of such pairings.
- What is a Voronoi diagram?
- A Voronoi diagram divides a plane into regions, one per site, so that every point in a region is closer to that site than to any other. The boundary between two neighboring cells is the perpendicular bisector of the segment joining them, because that is precisely the set of points equidistant from both. It answers nearest-facility questions directly: which hospital, which transmitter, which shop.
- How do you solve the toxic waste dump problem?
- You look at the vertices of the Voronoi diagram, where three cells meet. The point furthest from all sites must be equidistant from three of them, or lie on the boundary of the region under consideration, so checking each Voronoi vertex and the boundary gives the answer. It is called the largest empty circle problem: find the biggest circle containing no site, and its center is the location as far as possible from every one of them.