Algorithm Search⌘K

Proofs: Ullmann's algorithm

These are the human proofs of Ullmann's algorithm, at full length.

Ullmann's algorithm outputs every embedding exactly once full

This proof shows: correctness, termination.

Setting. G1=(V1,E1)G_1 = (V_1, E_1) with V1={0,…,k−1}V_1 = \{0, \ldots, k-1\} is the pattern and G2=(V2,E2)G_2 = (V_2, E_2) with ∣V2∣=n|V_2| = n the host, both simple and undirected, with labels ℓ1,ℓ2\ell_1, \ell_2. An embedding is an injective f:V1→V2f : V_1 \to V_2 with ℓ2(f(a))=ℓ1(a)\ell_2(f(a)) = \ell_1(a) for all aa and {a,b}∈E1  ⟹  {f(a),f(b)}∈E2\{a, b\} \in E_1 \implies \{f(a), f(b)\} \in E_2; in the induced mode also the converse. A matrix MM admits ff when M[r][f(r)]=1M[r][f(r)] = 1 for every row rr.

Lemma 1 (L1 admits every embedding). The initial matrix admits every embedding.

Proof. An embedding keeps labels, and it maps the deg⁡1(a)\deg_1(a) neighbors of aa injectively to neighbors of f(a)f(a), so deg⁡1(a)≤deg⁡2(f(a))\deg_1(a) \le \deg_2(f(a)). □\square

Lemma 2 (REFINE keeps admitted embeddings and terminates). If MM admits ff, then after REFINE(MM) the matrix still admits ff. REFINE stops after at most kn+1kn + 1 passes.

Proof. Consider the first entry M[i][j]M[i][j] cleared by L10 at a moment when the current matrix admits ff, and suppose j=f(i)j = f(i). L10 found a neighbor xx of ii with M[x][y]=0M[x][y] = 0 for all y∈N2(j)y \in N_2(j). But f(x)∈N2(f(i))=N2(j)f(x) \in N_2(f(i)) = N_2(j) since ff is an embedding, and M[x][f(x)]=1M[x][f(x)] = 1 because the matrix admits ff. Contradiction; so no entry M[i][f(i)]M[i][f(i)] is ever cleared. Every pass that does not stop clears at least one of at most knkn entries, and entries are never set back to 1, so there are at most knkn changing passes and one final pass. □\square

Lemma 3 (L5 keeps the embeddings of the branch). Let MM admit ff and let f(i)=jf(i) = j. Then the matrix M′M' of L5 admits ff.

Proof. Row ii of M′M' has its 1 at j=f(i)j = f(i). In a row r>ir > i, only column jj is cleared, and f(r)≠jf(r) \ne j because ff is injective. Rows above ii are unchanged. □\square

Lemma 4 (the rows above the current one are fixed and distinct). At a node of the search at row ii, with matrix MM, every row r<ir < i has exactly one 1, in a column crc_r, and the crc_r are pairwise distinct.

Proof. By induction on ii. For i=0i = 0 there is nothing to show. Going from row ii to row i+1i + 1, L5 sets row ii to a single 1 at ci=jc_i = j and clears column jj in all rows below ii, so no later row can hold jj. REFINE only clears entries, and L6 discards the matrix when a row becomes empty, so the single 1 of each fixed row survives. Earlier fixed columns crc_r, r<ir < i, were cleared from row ii before jj was chosen, so j≠crj \ne c_r. □\square

Theorem. The search terminates and outputs exactly the embeddings of G1G_1 into G2G_2, each once.

Proof. Termination. Each node at row ii has at most nn children, all at row i+1i + 1, and REFINE terminates by Lemma 2, so the search tree is finite and depth-first search visits it once.

Soundness. An output happens at row k−1k - 1 after REFINE succeeded. By Lemma 4 applied with i=ki = k (the row k−1k - 1 is fixed in L5 in the same way), every row has exactly one 1, in distinct columns, so f(r)=crf(r) = c_r is injective. L1 and the fact that entries are only cleared give equal labels. L7 checks every edge of G1G_1, and in the induced mode every non-edge, before it outputs. So every output is an embedding.

Completeness. Let ff be an embedding. By Lemmas 1 and 2 the root matrix admits ff, so no row is empty and the search starts. Suppose the search reaches a node at row ii whose matrix MM admits ff and whose fixed columns are cr=f(r)c_r = f(r) for r<ir < i. Then M[i][f(i)]=1M[i][f(i)] = 1, so L4 tries j=f(i)j = f(i). By Lemmas 3 and 2 the refined M′M' admits ff, so no row is empty and L6 does not reject. If i<k−1i < k - 1, the search goes on at row i+1i + 1 with the same two properties. If i=k−1i = k - 1, the single 1 of each row rr is at f(r)f(r), and the edge check of L7 passes because ff is an embedding, so ff is output.

Uniqueness. Two different leaves differ at the first row where their paths choose different columns, so they output different maps. ■\blacksquare

Back to Ullmann's algorithm