For the complete documentation index, see llms.txt. This page is also available as Markdown.

20. Elementary Graph Algorithms

Exercises

20.1-1

Available in the latest revision of the IM.

20.1-2

Available in the latest revision of the IM.

20.1-3

Available in the latest revision of the IM.

20.1-4

Available in the latest revision of the IM.

20.1-5

Available in the latest revision of the IM.

20.1-6 🌟

Available in the latest revision of the IM.

20.1-7

Available in the latest revision of the IM.

20.1-8

Available in the latest revision of the IM.

20.2-1

Available in the latest revision of the IM.

20.2-2

Available in the latest revision of the IM.

20.2-3

Available in the latest revision of the IM.

20.2-4

Available in the latest revision of the IM.

20.2-5

Available in the latest revision of the IM.

20.2-6

Available in the latest revision of the IM.

20.2-7

Available in the latest revision of the IM.

★ 20.2-8

Available in the latest revision of the IM.

20.3-1

Available in the latest revision of the IM.

20.3-2

Available in the latest revision of the IM.

20.3-3

Available in the latest revision of the IM.

20.3-4

Available in the latest revision of the IM.

20.3-5

Available in the latest revision of the IM.

20.3-6

Available in the latest revision of the IM.

20.3-7 🌟

Available in the latest revision of the IM.

20.3-8

Available in the latest revision of the IM.

20.3-9

Available in the latest revision of the IM.

20.3-10

Available in the latest revision of the IM.

20.3-11

Available in the latest revision of the IM.

20.3-12

Available in the latest revision of the IM.

★ 20.3-13

Available in the latest revision of the IM.

20.4-1

Available in the latest revision of the IM.

20.4-2 🌟

Available in the latest revision of the IM.

20.4-3

Available in the latest revision of the IM.

20.4-4

Available in the latest revision of the IM.

20.4-5

Available in the latest revision of the IM.

20.5-1

Available in the latest revision of the IM.

20.5-2

Available in the latest revision of the IM.

20.5-3

Available in the latest revision of the IM.

20.5-4

Available in the latest revision of the IM.

20.5-5

Available in the latest revision of the IM.

20.5-6

Available in the latest revision of the IM.

20.5-7

Available in the latest revision of the IM.

20.5-8

Available in the latest revision of the IM.

Problems

Available in the latest revision of the IM.

20-2 Articulation points, bridges, and biconnected components

Theorem 20.10 says that in a DFS tree of an undirected graph, there are no cross edges (edges between two subtrees that do not have an ancestor-descendant relationship). We use this fact throughout this exercise.

a.

If the root of GπG_\pi has only one child, all other nodes are descendants of this single child. Removing the root simply removes the root itself, leaving the rest of the tree completely connected through that single child. Therefore, it cannot be an articulation point of GG. Of course, if GG has only a single vertex, removing it creates an empty graph, which is assumed to be connected.

If the root of GπG_\pi has two or more children, these children are roots of disconnected subtrees in the DFS forest. The only path between these subtrees is through the root. Therefore, removing the root disconnects the graph, making it an articulation point.

Proving the other direction is virtually the same.

b.

Suppose there is a child ss of vv whose subtree has no back edges reaching above vv. This means the only way to reach the rest of the graph from ss's subtree is by traveling up the tree edges, which inevitably passes through vv. If you remove vv, you isolate sss subtree from the rest of the graph, proving vv is an articulation point.

Proving the other direction is virtually the same.

c.

We can compute v.lowv.low during the DFS traversal in O(E)O(E) time.

  1. Initialize v.low=v.dv.low = v.d (discovery time) when a vertex is first visited.

  2. For every adjacent vertex ww of vv:

    1. If ww is not visited (it becomes a child in the DFS tree), recursively call DFS on ww. After the recursive call returns, update v.low=min(v.low,w.low)v.low = \min(v.low, w.low).

    2. If ww is visited and is not the parent of vv (meaning (v,w)(v, w) is a back edge), update v.low=min(v.low,w.d)v.low = \min(v.low, w.d).

d.

Run the modified DFS from part (c).

  • Track the number of children for the root. If children > 1, mark the root as an articulation point (using part (a)).

  • For any non-root vertex vv, examine the lowlow values of its children. Based on part (b), vv is an articulation point if it has a child ss such that s.lowv.ds.low \ge v.d. This mathematically represents that no node in ss's subtree has a back edge jumping strictly higher than vv.

These checks add O(1)O(1) time per edge, maintaining the O(E)O(E) time complexity.

e.

If an edge e=(u,v)e=(u,v) is a bridge, its removal disconnects the graph. If it were on a simple cycle, removing it would just force the path between uu and vv to go the "long way" around the rest of the cycle, meaning the graph would stay connected. Hence, a bridge cannot be on a simple cycle.

If e=(u,v)e=(u,v) does not lie on any simple cycle, then it is the only simple path between uu and vv. Removing this edge eliminates all paths between uu and vv, disconnecting the graph. Thus, it is a bridge.

f.

In a DFS tree, back edges always form cycles with the tree edges. Therefore, a back edge is never a bridge. We only need to check tree edges.

A tree edge (v,s)(v, s), where ss is a child of vv, is a bridge if and only if there is no back edge from ss's subtree pointing to vv or any ancestor of vv. Mathematically, this means s.low>v.ds.low > v.d. By simply checking this condition during our DFS traversal, we can flag all bridges.

g.

The definition states a BCC is a maximal set of edges where any two edges lie on a common simple cycle. "Lying on a common simple cycle" is an equivalence relation for nonbridge edges (it is reflexive, symmetric, and transitive).

Because it is an equivalence relation, it naturally divides the set of all nonbridge edges into disjoint equivalence classes. These maximal equivalence classes are exactly the biconnected components. Because bridges don't lie on simple cycles (from part (e)), they are excluded from this partition.

h.

The main part executes as follows:

  1. Maintain a stack of edges during the DFS.

  2. When you traverse an edge (either a tree edge or a back edge), push it onto the stack.

  3. When you finish processing a child ss of node vv and discover that s.lowv.ds.low \ge v.d (meaning vv is an articulation point separating ss's BCC), pop edges from the stack until you hit the tree edge (v,s)(v, s). Assign a new, unique bccbcc positive integer label to all the edges you just popped. These edges form one complete biconnected component.

    1. When the popped group consists of exactly one edge, we identify it as a bridge and simply discard it from the stack without assigning it a BCC label.

After the main DFS traversal concludes, the algorithm must simply execute one last step:

  1. While the stack is not empty, pop the remaining edges. They form the final biconnected component.

Because each edge is pushed onto the stack exactly once and popped exactly once, the entire labeling process runs in O(E)O(E) time.

20-3 Euler tour

Available in the latest revision of the IM.

20-4 Reachability

Available in the latest revision of the IM.

20-5 Inserting and querying vertices in planar graphs

Available in the latest revision of the IM.

Last updated