Algorithm Search⌘K

Proofs: Block-cut tree

These are the human proofs of Block-cut tree, at full length.

The block-cut tree is a forest, and its queries are correct full

This proof shows: correctness.

Let G=(V,E)G = (V, E) be an undirected graph. Parallel edges are allowed; loops are ignored, since they lie in no block with another edge and change no articulation point. Line L1 gives the vertex sets B1,…,BbB_1, \ldots, B_b of the blocks of the non-loop edges (correct by the proof on the Hopcroft-Tarjan page), plus a block {v}\{v\} for each vertex with no non-loop edge, and the set AA of articulation points. We use these facts from the biconnected components page: two blocks share at most one vertex; a vertex lies in two or more blocks if and only if it is in AA; and two edges at a vertex xx that lie in different blocks are not joined by a path that avoids xx (fact 3). We also use that Bi∖{x}B_i \setminus \{x\} is connected in G−xG - x for every block BiB_i and every vertex xx: a block with two vertices becomes one vertex, and a block with three or more vertices is biconnected.

Let T\mathcal{T} be the graph built by lines L2 and L3: a node βi\beta_i for each block, a node γx\gamma_x for each x∈Ax \in A, and an edge {βi,γx}\{\beta_i, \gamma_x\} whenever x∈Bix \in B_i.

Lemma 1. T\mathcal{T} is a forest, and its trees match the components of GG.

Proof. Each node of T\mathcal{T} lies in one component of GG, and two nodes are adjacent only if they share a vertex, so a tree of T\mathcal{T} stays in one component. Within a component, any two blocks are joined in T\mathcal{T}: follow a path of GG from one to the other; each time it moves from one block to the next, it does so at a shared vertex, which is in AA, so the two block nodes have a common neighbour.

We show that each edge {β,γx}\{\beta, \gamma_x\} is a bridge of T\mathcal{T}, so T\mathcal{T} has no cycle. Since x∈Ax \in A, it lies in a second block β′≠β\beta' \neq \beta. Suppose T\mathcal{T} minus the edge still has a path from β\beta to γx\gamma_x. Then it is β=β0,γx1,β1,…,γxk,βk,γx\beta = \beta_0, \gamma_{x_1}, \beta_1, \ldots, \gamma_{x_k}, \beta_k, \gamma_x with βk≠β\beta_k \neq \beta and all xj≠xx_j \neq x. Each βj∖{x}\beta_j \setminus \{x\} is connected in G−xG - x, and consecutive ones share xj≠xx_j \neq x, so G−xG - x has a path from a neighbour yy of xx in β\beta to a neighbour zz of xx in βk\beta_k. The edges xyxy and xzxz lie in different blocks, and this path joins them without xx, which contradicts fact 3. □\square

Line L5 roots each tree of T\mathcal{T} at a block node, and one depth-first search of T\mathcal{T} gives each node aa an interval [tin[a],tout[a]][\mathrm{tin}[a], \mathrm{tout}[a]]. The intervals of a node and of its descendants are nested, and those of two nodes that are not ancestor and descendant are disjoint. So line L6 is the ancestor test, and in line L7 the children of aa are sorted by tin\mathrm{tin}, so the last child whose tin\mathrm{tin} is at most tin[c]\mathrm{tin}[c] is the one whose subtree holds cc.

Line L4 sets node[v]=γv\mathrm{node}[v] = \gamma_v for v∈Av \in A, and otherwise the only block that holds vv. Thus the blocks that hold vv are the tree neighbours of node[v]\mathrm{node}[v] if v∈Av \in A, and {node[v]}\{\mathrm{node}[v]\} if not.

Lemma 2 (SEPARATES). Let u,v,xu, v, x be distinct, with uu and vv in one component. Every uu-vv path of GG passes through xx if and only if x∈Ax \in A and γx\gamma_x lies on the tree path between node[u]\mathrm{node}[u] and node[v]\mathrm{node}[v].

Proof. Let PP be a uu-vv path. Cut PP at each vertex where it passes from an edge of one block to an edge of another block. Each such vertex yy is in AA, and the blocks of PP in order, with the nodes γy\gamma_y between them, form a walk in T\mathcal{T} from a neighbour of (or the node) node[u]\mathrm{node}[u] to the same for node[v]\mathrm{node}[v]. In a tree, every walk between two nodes visits each node of the path between them. So if γx\gamma_x is on that path, γx\gamma_x is on the walk, and PP passes through xx.

Conversely, let γx\gamma_x not be on the tree path node[u]=a0,a1,…,ak=node[v]\mathrm{node}[u] = a_0, a_1, \ldots, a_k = \mathrm{node}[v]. For each block aja_j on it, let sjs_j and tjt_j be the vertices where the path enters and leaves it: the vertex of the cut node before and after it, or uu at the start and vv at the end. None of these is xx, since γx\gamma_x is not on the path and u,v≠xu, v \neq x. Since aj∖{x}a_j \setminus \{x\} is connected in G−xG - x, it has an sjs_j-tjt_j path without xx. Joining these paths gives a uu-vv walk without xx, so some uu-vv path avoids xx. If x∉Ax \notin A, G−xG - x has as many components as GG, and uu, vv stay joined. □\square

The tree path between aa and bb passes through gg if and only if gg is an ancestor of exactly one of them, or gg is an ancestor of both and they lie under different children of gg (or one of them is gg; here a,b≠ga, b \neq g). Lines L9 to L12 compute this test, and line L8 handles x∉Ax \notin A. So SEPARATES is correct.

Lemma 3 (SAME-BLOCK). For distinct uu and vv, lines L13 to L16 return true if and only if some block holds both.

Proof. Let N(u)N(u) be the set of blocks that hold uu, as given above. A common block exists if and only if N(u)∩N(v)≠∅N(u) \cap N(v) \neq \emptyset. If neither vertex is in AA, the sets are {a}\{a\} and {b}\{b\}, so the test is a=ba = b (line L14). If only uu is in AA, the block bb is in N(u)N(u) if and only if bb is adjacent to a=γua = \gamma_u, that is, bb is the parent or a child of aa (line L15). If both are in AA, a common block β\beta is adjacent to both cut nodes. It cannot be a child of both. So it is the parent of both, or the parent of one and a child of the other, which makes the other the grandparent of the first (line L16). Cut nodes are never roots, so their parents exist. ■\blacksquare

Back to Block-cut tree