Algorithm Search⌘K

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 G=(V,E)G = (V, E) be a simple undirected graph with V={0,…,n−1}V = \{0, \dots, n-1\}, and k≥1k \ge 1. For S⊆VS \subseteq V, let N(S)={u∉S:u has a neighbour in S}N(S) = \{u \notin S : u \text{ has a neighbour in } S\} and N[S]=S∪N(S)N[S] = S \cup N(S). A call is a call EXTEND(subsub, extext, vv); for a call made at line L10 inside a call cc, we say it is a child of cc. The calls made at line L3 are the roots. Line L8 may remove the vertices of extext in any order; the proof holds for every order.

Lemma 1 (invariants). Every call EXTEND(subsub, extext, vv) satisfies: (a) G[sub]G[sub] is connected, v∈subv \in sub, and every other vertex of subsub is larger than vv; (b) ext⊆N(sub)ext \subseteq N(sub), and every vertex of extext is larger than vv; (c) ∣sub∣|sub| is one more than the depth of the call, where a root has depth 0.

Proof. At line L3, sub={v}sub = \{v\} and ext={u∈N(v):u>v}⊆N({v})ext = \{u \in N(v) : u > v\} \subseteq N(\{v\}), so (a), (b) and (c) hold. Let a call with (sub,ext)(sub, ext) satisfy them, and let it make a child at line L10 with the vertex ww removed at line L8. Write RR for the set extext after the removal, so R⊆ext∖{w}R \subseteq ext \setminus \{w\}, and X={u∈N(w):u>v, u∉N[sub]}X = \{u \in N(w) : u > v,\ u \notin N[sub]\}; the child has sub′=sub∪{w}sub' = sub \cup \{w\} and ext′=R∪Xext' = R \cup X. (a) w∈ext⊆N(sub)w \in ext \subseteq N(sub), so w∉subw \notin sub and ww has a neighbour in subsub, so G[sub′]G[sub'] is connected; w>vw > v by (b). (b) A vertex of RR is in N(sub)N(sub), so it is outside subsub, differs from ww, and has a neighbour in sub⊆sub′sub \subseteq sub'; so it is in N(sub′)N(sub'). A vertex u∈Xu \in X is adjacent to w∈sub′w \in sub', is not in subsub since u∉N[sub]u \notin N[sub], and is not ww since GG has no loops; so u∈N(sub′)u \in N(sub'). Both kinds are larger than vv. (c) ∣sub′∣=∣sub∣+1|sub'| = |sub| + 1. □\square

Lemma 2 (termination). The run stops, and every output is a connected set of exactly kk vertices whose smallest vertex is the vv of its call.

Proof. By Lemma 1(c), a call at depth k−1k - 1 has ∣sub∣=k|sub| = k and returns at line L6 without making children, so the depth is at most k−1k - 1. Each call makes one child per pass of its loop, and each pass removes one vertex from the finite set extext 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. □\square

Lemma 3 (excluded vertices stay out). Let a call cc with (sub,ext)(sub, ext) remove the vertex wjw_j at line L8, and later, in the same call, remove wiw_i. Then no call in the subtree of the child of wiw_i (that child included) has wjw_j in its subsub.

Proof. We show that every call dd in that subtree, with (subd,extd)(sub_d, ext_d), has sub⊆subdsub \subseteq sub_d, wj∉subdw_j \notin sub_d and wj∉extdw_j \notin ext_d. For the child of wiw_i: subd=sub∪{wi}sub_d = sub \cup \{w_i\} and wi≠wjw_i \ne w_j, and wj∉subw_j \notin sub since wj∈ext⊆N(sub)w_j \in ext \subseteq N(sub). Its extd=R∪Xext_d = R \cup X, where RR is what is left of extext after wiw_i was removed; wjw_j was removed earlier, so wj∉Rw_j \notin R; and wj∈N(sub)⊆N[sub]w_j \in N(sub) \subseteq N[sub], so wj∉Xw_j \notin X. Now let dd satisfy the claim and let d′d' be a child of dd with the vertex ww removed from extdext_d. Then w≠wjw \ne w_j because wj∉extdw_j \notin ext_d, so wj∉subd′=subd∪{w}w_j \notin sub_{d'} = sub_d \cup \{w\}. The set extd′ext_{d'} is a part of extdext_d, which does not hold wjw_j, together with vertices outside N[subd]N[sub_d]. Since sub⊆subdsub \subseteq sub_d and wj∈N(sub)w_j \in N(sub), either wj∈subdw_j \in sub_d, which is excluded, or wj∈N(subd)w_j \in N(sub_d); in both cases wj∈N[subd]w_j \in N[sub_d], so wj∉extd′w_j \notin ext_{d'}. By induction on depth the claim holds in the whole subtree. □\square

Lemma 4 (at most once). No two distinct calls have the same subsub. In particular, no set is output twice.

Proof. Take two distinct calls d1d_1 and d2d_2. If they lie under different roots {v1}\{v_1\} and {v2}\{v_2\} with v1≠v2v_1 \ne v_2, their sets have the different smallest vertices v1v_1 and v2v_2 by Lemma 1(a). If one is an ancestor of the other, their sets have different sizes by Lemma 1(c). Otherwise let cc be their last common ancestor, and let d1d_1 lie under the child of cc made with wjw_j and d2d_2 under the child made with wiw_i, where wjw_j was removed first. By Lemma 1, the set of every call under the child of wjw_j contains subc∪{wj}sub_c \cup \{w_j\}, since sets only grow along a branch; so wj∈subd1w_j \in sub_{d_1}. By Lemma 3, wj∉subd2w_j \notin sub_{d_2}. So subd1≠subd2sub_{d_1} \ne sub_{d_2}. □\square

Lemma 5 (at least once). Every set S⊆VS \subseteq V with ∣S∣=k|S| = k and G[S]G[S] connected is output.

Proof. Let v=min⁡Sv = \min S. Call a call with (sub,ext)(sub, ext) and root vv good if sub⊆Ssub \subseteq S and (S∖sub)∩N(sub)⊆ext(S \setminus sub) \cap N(sub) \subseteq ext. The root {v}\{v\} is good: every vertex of S∖{v}S \setminus \{v\} is larger than vv, so each one adjacent to vv is in extext by line L2.

Let a call with (sub,ext)(sub, ext) be good and ∣sub∣<k|sub| < k. Since G[S]G[S] is connected and ∅≠sub⊊S\emptyset \ne sub \subsetneq S, some edge of G[S]G[S] joins subsub to S∖subS \setminus sub, so (S∖sub)∩N(sub)(S \setminus sub) \cap N(sub) is not empty, and it is a part of extext. So the loop of lines L7 to L10 removes at least one vertex of SS. Let w1,…,wrw_1, \dots, w_r be the vertices removed, in order, and wiw_i the first one in SS. Its child has sub′=sub∪{wi}⊆Ssub' = sub \cup \{w_i\} \subseteq S and ext′={wi+1,…,wr}∪Xext' = \{w_{i+1}, \dots, w_r\} \cup X with XX as in Lemma 1. Let x∈(S∖sub′)∩N(sub′)x \in (S \setminus sub') \cap N(sub').

  • If x∈N(sub)x \in N(sub), then x∈extx \in ext because the call is good, so xx is some wlw_l. It is not wiw_i since x∉sub′x \notin sub', and not wlw_l with l<il < i since those are not in SS. So l>il > i and x∈ext′x \in ext'.
  • If x∉N(sub)x \notin N(sub), then x∉subx \notin sub, so x∉N[sub]x \notin N[sub]; and xx has a neighbour in sub′sub' but not in subsub, so xx is adjacent to wiw_i. Also x∈S∖{v}x \in S \setminus \{v\}, so x>vx > v. Hence x∈X⊆ext′x \in X \subseteq ext'.

So the child is good and its subsub has one more vertex. Starting from the root and repeating, we reach a good call with ∣sub∣=k|sub| = k and sub⊆Ssub \subseteq S, so sub=Ssub = S, and line L6 outputs SS. □\square

Theorem. ESU(GG, kk) stops and outputs exactly the sets S⊆VS \subseteq V with ∣S∣=k|S| = k and G[S]G[S] 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. □\square

Corollary (the size of the tree). By Lemma 4 and Lemma 1(a), the calls of EXTEND have distinct connected sets subsub of at most kk vertices, so there are at most ss of them, where ss is the number of such sets in GG. Each pass of line L8 makes one call, so the number of passes is also at most ss.

∎

Back to ESU algorithm