GTOIgraph theory, redesigned

Chapter 1 · Graphs and Models

A Zoo of Graphs

The named families you should recognise on sight — and the edge counts each one gives you for free.

  • warm-up
  • 1 snippet
  • definitions
  • counting

Competitions rarely ask you to invent a graph; they hand you a shape and expect you to know its invariants. Learn these ten, and half of all "how many edges / what is the degree of…" questions become reflexes.

#The named families

familynotation|E|notes
pathPnn-1connected, exactly two vertices of degree 1
cycleCnn2-regular; exists only for n ≥ 3 (simple graphs)
completeKnC(n, 2)every pair adjacent; Δ = n-1
starSnn-1one vertex of degree n-1; a tree with diameter 2
wheelWn2(n-1)Cn-1 plus a universal hub
complete bipartiteKa,babmax edges with no triangle
hypercubeQnn 2n-1vertices = bitmasks of length n; n-regular, bipartite
grid / latticeGa,b2ab - a - bplanar, max degree 4
complete multipartiteKn1,…,nk(1)/(2)(n2 - ∑ ni2)complement of a disjoint union of cliques
empty / nullKn̄0n isolated vertices
Key ideaCount edges by double counting

Every number in that column comes from the same move: count the same thing twice. Qn has 2n vertices each of degree n, so m = n 2n-1. If you can compute degrees in two ways, you never have to "see" the pattern.

G C C A A C--A C--A D D C--D B B A--B A--B A--D              B--D
Figure 1The graph that started the field: seven bridges of Königsberg, drawn as four land masses and seven edges. Multi-edges are exactly what makes Euler's degree condition the right one.

#Vocabulary that decides algorithm choice

Definition
  • simple: no self-loops, at most one edge per pair. Most of this book assumes simple unless stated.
  • multigraph: parallel edges allowed — the model for "two flights between the same cities".
  • directed: edges are ordered pairs (u,v); see Orientations, In/Out-Degree, Strong vs Weak.
  • weighted: each edge carries a number; only the weights matter for shortest paths, the topology is the same.
  • self-loop (v,v): contributes 2 to deg(v) in the undirected case, 1 to both in- and out-degree when directed.

A k-regular graph has every degree equal to k; the handshaking lemma then forces kn even, which is the standard proof that a 3-regular graph on 9 vertices cannot exist.

Definition

Density is (2m)/(n(n-1)) ∈ [0,1]. A graph with m > C(n-1, 2) must be connected: the maximum number of edges in a disconnected graph is a Kn-1 plus an isolated vertex.

Watch outTwo traps
  1. "Graph with n vertices and n edges is a cycle" — false; it only has exactly one cycle, somewhere, possibly with trees hanging off it (a unicyclic graph).
  2. "Bipartite means the parts have equal size" — no; it means V = A ⊔ B with all edges crossing. K1,7 is bipartite.

#Recognition is an algorithm

Check yourself

Given an adjacency matrix, O(n2) checks settle most of the above: regular (all row sums equal), complete (all off-diagonal ones), tree (connected and m=n-1), bipartite (no odd cycle — BFS colouring, see Bipartite Graphs and 2-Colouring).

cpprecognise.cpp
int n; cin >> n;
vector<string> a(n);
for (auto& s : a) cin >> s;
long long m = 0; bool simple = true;
vector<int> deg(n);
for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) if (a[i][j] == '1') {
        if (i == j) simple = false;          // self-loop
        m += (j > i); deg[i]++;
    }
int d0 = deg[0];
bool regular = all_of(deg.begin(), deg.end(), [&](int d) { return d == d0; });
bool complete = m == 1LL * n * (n - 1) / 2;
bool tree = m == n - 1 && connected(a);     // connectivity is the other half