Advanced Graph Yu-Fang Chen (陳郁⽅) Department of Information Management Algorithms National Taiwan University Biconnected Components

Definition An undirected graph is connected if there is a path from every to every other vertex.

Definition An undirected graph is biconnected if there are at least two vertex disjoint paths from every vertex to every other vertex.

By convention, a graph with one edge is biconnected.

Definition An undirected graph is k-connected if there are at least k vertex disjoint paths from every vertex to every other vertex. Biconnected Components (cont.)

Menger’s Theorem Let G be an undirected graph and u, v be two nonadjacent vertices in G. The minimal number of vertices whose removal from G disconnects u from v is equal to the maximal number of vertex disjoint paths from u to v.

u v

❖ A graph is not biconnected iff there is a vertex whose removal disconnects the graph. Such a vertex is called an articulation point. Biconnected Components (cont.)

Definition A (BCC) is a maximal subset of the edges such that its induced subgraph is biconnected.

Is this a BCC? Biconnected Components (cont.)

The set of edges can be partitioned into biconnected components in a unique way.

Lemma Two edges e and f belong to the same BCC iff there is a cycle containing both of them.

A cycle is always entirely contained in one BCC. If it has edges from two BCCs, adding the entire cycle still forms a BCC. This contradicts the maximality requirement.

If the two edges belong to the same BCC, we add two new vertices ve and vf to the “middle” of e and f. The component is still biconnected because it does not introduce new articulation points (remove them cannot disconnect the BCC). So by Menger’s theorem, there are two

vertex disjoint paths between ve and vf, which forms a cycle. Biconnected Components (cont.)

The set of edges can be partitioned into biconnected components in a unique way.

Lemma Each edge belongs to exactly one biconnected component. Biconnected Components (cont.)

Algorithm design:

Induction Hypothesis We know how to find the biconnected components of connected graphs with < m edges.

A graph with one edge is biconnected.

Pick and remove arbitrary edge x from graph with m edges. Find the BCCs.

(1) x is in one BCC

(2) x disconnects the graph

(3) x connects two BCCs to form a larger one

how to find the involved BCCs? Biconnected Components (cont.)

Complexity? Finding a cycle in a “tree”: O(|V|) We need to find a cycle for each edge: O(|E|)

So O(|V|*|E|) (not a precise analysis) Biconnected Components (cont.)

The complexity can be improved by using a better order (DFS) of edge picking We want to find the highest articulation points in each BCC.

All descendants cannot connect to vertexes higher than b Define High(v) as the highest vertex that v or its descendant can reach via a back edge Biconnected Components (cont.)

High(v) is the highest vertex that v or its descendant can reach via a back edge

High(v) = highest among High(wi) and all back edges from v

v is an articulation point iff there is a child wi of v s.t. High(wi) ≤ High(v) Induction Hypothesis

When we visit the k-th vertex by DFS, we know how to find the High values of vertexes that have already been visited and are below this vertex.

We can at the same time update High(v) and detect if v is an articulation point Exception: root is an articulation point iff it has more than one child Biconnected Components (cont.)

to remember the BCC is tree edge

is articulation point

is back edge Strongly Connected Components

Definition A is strongly connected if there is a path from from every vertex to every other vertex.

Definition A strongly connected component (SCC) is a maximal subset of the vertices s.t. its induced subgraph is strongly connected. Strongly Connected Components (cont.)

The set of vertices can be partitioned into strongly connected components in a unique way.

Lemma Two vertices e and f belong to the same SCC iff there is a circuit containing both of them.

Lemma Each vertex belongs to exactly one SCC. Strongly Connected Components (cont.)

SCC graphs Strongly Connected Components (cont.)

Algorithm design:

Induction Hypothesis We know how to find the strongly connected components of connected graphs with < m edges and their SCC graphs.

A graph with one edge has two SCCs.

Pick and remove arbitrary edge x from graph with m edges.

Find the SCCs.

(1) x is in one SCC

(2) x connects two SCCs ❖ x disconnects the graph ? Strongly Connected Components (cont.)

Finding a cycle: O(|V|+|E|) We need to find a cycle for each edge: O(|E|)

So O((|V|+|E|)*|E|) (not a precise analysis) Strongly Connected Components (cont.)

Root of the component Improved algorithm design using DFS:

All vertices in one SCC must belong to one connected subtree of the DFS tree Strongly Connected Components (cont.)

Improved algorithm design using DFS:

Main difference to the BCC algorithm: DFS tree of a directed graph has cross edge.

g has lower DFS number, but there is no cycle containing both i and g Strongly Connected Components (cont.)

Improved algorithm design using DFS:

Induction Hypothesis We know how to find one strongly connected component and its root of connected graphs with < m edges.

Main idea: (1) find an SCC using an algorithm similar to the one for BCC (2) remove that SCC from the graph (3) apply the induction hypothesis Strongly Connected Components (cont.) to remember the SCC

to remember if a vertex is a tree edge already belong to a SCC

is a back edge

is a root Strongly Connected Components (cont.) Even Length Cycles

Problem Given a connected undirected graph G = (V , E ), determine whether it contains a cycle of even length.

First, compute the BCCs

Theorem Every biconnected graph that has more than one edge and is not merely an odd-length cycle contains an even length cycle. Even Length Cycles

Theorem Every biconnected graph that has more than one edge and is not merely an odd-length cycle contains an even length cycle. Odd Length Cycles

Problem Given a directed graph G = (V , E ), determine whether it contains a (directed) cycle of odd length.

❖ First, compute the SCCs ❖ A cycle must reside completely within a SCC, so we exam each SCC separately. ❖ Mark the nodes of an SCC with “even” or “odd” using DFS. ❖ If we have to mark a node that is already marked in the opposite, then we have found an odd-length cycle.