Proofs: ESU algorithm
These are the human proofs of ESU algorithm, at full length.
ESU outputs every connected induced subgraph of k vertices exactly once, and stops full
This proof shows: correctness, termination.
Let be a simple undirected graph with , and . For , let and . A call is a call EXTEND(, , ); for a call made at line L10 inside a call , we say it is a child of . The calls made at line L3 are the roots. Line L8 may remove the vertices of in any order; the proof holds for every order.
Lemma 1 (invariants). Every call EXTEND(, , ) satisfies: (a) is connected, , and every other vertex of is larger than ; (b) , and every vertex of is larger than ; (c) is one more than the depth of the call, where a root has depth 0.
Proof. At line L3, and , so (a), (b) and (c) hold. Let a call with satisfy them, and let it make a child at line L10 with the vertex removed at line L8. Write for the set after the removal, so , and ; the child has and . (a) , so and has a neighbour in , so is connected; by (b). (b) A vertex of is in , so it is outside , differs from , and has a neighbour in ; so it is in . A vertex is adjacent to , is not in since , and is not since has no loops; so . Both kinds are larger than . (c) .
Lemma 2 (termination). The run stops, and every output is a connected set of exactly vertices whose smallest vertex is the of its call.
Proof. By Lemma 1(c), a call at depth has and returns at line L6 without making children, so the depth is at most . Each call makes one child per pass of its loop, and each pass removes one vertex from the finite set and adds none to it, so each call makes finitely many children. A finitely branching tree of bounded depth is finite. The second part is Lemma 1(a) at line L6.
Lemma 3 (excluded vertices stay out). Let a call with remove the vertex at line L8, and later, in the same call, remove . Then no call in the subtree of the child of (that child included) has in its .
Proof. We show that every call in that subtree, with , has , and . For the child of : and , and since . Its , where is what is left of after was removed; was removed earlier, so ; and , so . Now let satisfy the claim and let be a child of with the vertex removed from . Then because , so . The set is a part of , which does not hold , together with vertices outside . Since and , either , which is excluded, or ; in both cases , so . By induction on depth the claim holds in the whole subtree.
Lemma 4 (at most once). No two distinct calls have the same . In particular, no set is output twice.
Proof. Take two distinct calls and . If they lie under different roots and with , their sets have the different smallest vertices and by Lemma 1(a). If one is an ancestor of the other, their sets have different sizes by Lemma 1(c). Otherwise let be their last common ancestor, and let lie under the child of made with and under the child made with , where was removed first. By Lemma 1, the set of every call under the child of contains , since sets only grow along a branch; so . By Lemma 3, . So .
Lemma 5 (at least once). Every set with and connected is output.
Proof. Let . Call a call with and root good if and . The root is good: every vertex of is larger than , so each one adjacent to is in by line L2.
Let a call with be good and . Since is connected and , some edge of joins to , so is not empty, and it is a part of . So the loop of lines L7 to L10 removes at least one vertex of . Let be the vertices removed, in order, and the first one in . Its child has and with as in Lemma 1. Let .
- If , then because the call is good, so is some . It is not since , and not with since those are not in . So and .
- If , then , so ; and has a neighbour in but not in , so is adjacent to . Also , so . Hence .
So the child is good and its has one more vertex. Starting from the root and repeating, we reach a good call with and , so , and line L6 outputs .
Theorem. ESU(, ) stops and outputs exactly the sets with and connected, each exactly once.
Proof. Lemma 2 gives termination and shows that every output is such a set. Lemma 5 shows that every such set is output, and Lemma 4 that it is output only once.
Corollary (the size of the tree). By Lemma 4 and Lemma 1(a), the calls of EXTEND have distinct connected sets of at most vertices, so there are at most of them, where is the number of such sets in . Each pass of line L8 makes one call, so the number of passes is also at most .
∎