Algorithmic Graph Theory

Finally, there are several invariants of graphs which are of particular interest because of the algorithms that compute them.

The shortest­path spanning tree of a grid graph is defined in terms of Manhattan distance, where the distance between points with coordinates (x, y) and (u, v) is |x - u| + |y - v|.

ShowGraph[
ShortestPathSpanningTree[
GridGraph[5,5],1] ];
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr159.gif]

In an unweighted graph there can be many different shortest paths between any pair of vertices. This path between two opposing corners goes all the way to the right, then all the way to the top.

ShortestPath[GridGraph[5,5],1,25]
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr160.gif]

A minimum spanning tree of a weighted graph is a set of n - 1 edges of minimum total weight which form a spanning tree of the graph. Any spanning tree is a minimum spanning tree when the graphs are unweighted.

ShowGraph[ MinimumSpanningTree[ CompleteGraph[6,6,6] ] ];
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr162.gif]

The number of spanning trees of a complete graph is n^{n - 2}, as was proved by Cayley.

NumberOfSpanningTrees[CompleteGraph[10]]
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr164.gif]

The maximum flow through an unweighted complete bipartite graph G is the minimum degree δ(G).

NetworkFlow[ CompleteGraph[4,4], 1, 8]
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr167.gif]

A matching in a graph G is a set of edges of G such that no two of them share a vertex in common. A perfect matching of an even cycle consists of alternating edges in the cycle.

BipartiteMatching[ Cycle[8] ]
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr170.gif]

Any maximal matching of a K_n is a maximum matching, and perfect if n is even.

MaximalMatching[CompleteGraph[8]]
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr173.gif]

Planar graphs are graphs which can be embedded in the plane with no pair of edges crossing. K_{3,3} and K_5 are the basic nonplanar graphs.

PlanarQ[CompleteGraph[5]] || PlanarQ[CompleteGraph[3,3]]
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr176.gif]

Every planar graph on nine vertices has a nonplanar complement.

PlanarQ[ GraphComplement[GridGraph[3,3]] ]
[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr177.gif]

[Graphics:combinatoricagr2.gif][Graphics:combinatoricagr178.gif]

Combinatorica functions for algorithmic graph theory.