Proofs: VF2 algorithm
These are the human proofs of VF2 algorithm, at full length.
VF2 outputs exactly the mappings of the requested kind, each once full
This proof shows: correctness, termination.
Setting. and are simple undirected graphs with vertex labels , and . A target is an injective map with for all and, for all in :
- mode mono: ;
- modes iso and induced: , and in iso mode also .
A state is a partial injective map . For a state, is the set of unmapped vertices of with at least one mapped neighbor and the set of unmapped vertices with none. A state extends to a target when for every mapped by .
Invariant (I). For every state on the search path, any two mapped pattern vertices satisfy the edge condition of the mode for , labels agree on mapped vertices, and is injective.
Proof of (I). It holds for . Let be added in L6. Both are unmapped, since L3 draws from unmapped pattern vertices and from unmapped host vertices, so is injective. L9 checks the label. For a mapped : if , L10 checks . In iso and induced mode, if , then is a mapped neighbor of and L10 checks . Pairs not involving are unchanged.
Lemma 1 (soundness). Every output of L2 is a target.
Proof. At L2, , so is a total injective map , and by (I) it satisfies the labels and the edge condition for every pair. In iso mode the algorithm starts only when .
Lemma 2 (the rules keep every extendable state). Let extend to a target , let be unmapped, and let . Then passes L9 to L12.
Proof. L9: keeps labels. In iso mode is an isomorphism, so . Otherwise maps the neighbors of injectively to neighbors of , so . L10 holds because satisfies the edge condition for and each mapped vertex.
For L11 and L12 let be an unmapped neighbor of . Then is unmapped by , since is injective and agrees with on the mapped vertices, and is a neighbor of .
- If , has a mapped neighbor , so is adjacent to and . Hence maps injectively into , and in every mode.
- In iso and induced mode, if , then has no mapped neighbor: a mapped neighbor of would make a mapped neighbor of . So , and . This proves the induced rule.
- In mono mode, maps injectively into , which proves the second mono rule.
- In iso mode, is a bijection with and : the argument above applied to , which is an isomorphism extending , gives the reverse inclusions. Since maps onto , the counts are equal.
Lemma 3 (the right candidate is present). Let extend to a target with , and let be the pattern vertex chosen in L3. Then is in the candidate list.
Proof. If , then , and by the first point of the proof of Lemma 2, , so and is listed. If , is the smallest unmapped vertex. In mono and induced mode, every unmapped host vertex is listed, including . In iso mode, is a bijection that maps onto , so as well, and all unmapped host vertices are listed.
Theorem. VF2 terminates, and its outputs are exactly the targets, each output once.
Proof. Termination. Each step L6 increases , which is at most , and each state has a finite candidate list that is scanned once from left to right; so the search tree is finite, and the explicit stack visits each node once.
Soundness is Lemma 1.
Completeness. Let be a target. Start at , which extends to . If extends to and , Lemma 3 puts in the list of , and Lemma 2 shows that it passes FEASIBLE; so the search enters , which also extends to . After steps L2 outputs .
Uniqueness. The choice of in L3 depends only on the state, and distinct candidates at one state have distinct host vertices , so distinct children of a node hold different values . Two output leaves with the same map would agree on every pair along the path from the root and so be the same leaf. Hence each target is output once.