Examples#
This gallery walks through every public feature of mathematicskit.graph_theory:
shortest paths, minimum spanning trees, maximum flow/minimum cut, graph
coloring, and spectral graph theory.
See also the narrative tutorial:
Each script in this gallery is self-contained and can be run directly with
python examples/graph_theory/<section>/<script>.py.
Sections#
eulerian – Euler’s Seven Bridges of Königsberg and the odd-degree criterion.
shortest_paths – Dijkstra, Bellman-Ford, and Floyd-Warshall.
spanning_tree – Kruskal’s (scipy) vs. Prim’s (hand-rolled) MST.
max_flow – maximum flow and the corresponding minimum cut.
coloring – the four color theorem on a planar map, greedy vs. exact backtracking coloring.
spectral – the graph Laplacian, algebraic connectivity, and spectral bipartition.
Assignment#
Kuhn’s Hungarian method for optimal one-to-one assignments.
Graph coloring#
The four color theorem on a planar map: exact backtracking vs. greedy coloring.
Connected components#
Components of graphs, and the giant component of random graphs.
Eulerian paths#
Euler’s Seven Bridges of Königsberg and the odd-degree criterion.
Extremal graph theory#
Turán’s theorem: the most edges a graph can have without a large clique.
Hamiltonian cycles#
Cycles that visit every vertex exactly once.
Bipartite matching#
Maximum matchings and König’s minimum vertex covers.
Maximum flow#
Maximum flow and the corresponding minimum cut.
Ranking#
PageRank: ranking the vertices of a directed graph by a random walk.
Heuristic search#
A* search: shortest paths guided by an estimate of the remaining distance.
Shortest paths#
Dijkstra, Bellman-Ford, and Floyd-Warshall.
Dijkstra’s shortest-path algorithm (and when Bellman-Ford is needed)
Minimum spanning tree#
Kruskal’s (scipy) vs. Prim’s (hand-rolled) MST.
Spectral graph theory#
The graph Laplacian, algebraic connectivity, and spectral bipartition.
Fiedler’s spectral bipartition of a “barbell” graph