Concept units

Connected pieces of a graph

Basic

Read these first if they are new to you

The idea in one paragraph

A graph often falls into separate pieces, with no edge from one piece to another. Each piece is a connected component: a group of nodes you can travel between along edges. A program finds the pieces by starting at any node and spreading out to neighbors, then neighbors of neighbors, until nothing new turns up. Cutting an edge can split a piece in two, but only if there was no other route around it.

A connected component is everything you can reach from a node

A path in a graph is a walk from node to node along edges. Two nodes are connected if some path joins them. A connected component, or piece, is a largest group of nodes that are all connected to each other. Every node belongs to exactly one piece; a node with no edges is a piece by itself.

Click an edge to cut it; each piece keeps its own color
2 pieces
Try this. Before you click, predict which single edges split the big piece when cut. Click each edge to check; click a cut edge again to restore it. Then, starting from all edges, find the fewest cuts inside the four-node loop (4, 5, 6, 7) that separate 5 from 7.

Some edges are the only route between two parts of a piece. Cutting such an edge, called a bridge, splits the piece in two. An edge that lies on a loop, called a cycle, is never a bridge: after the cut, the walk the other way around the loop still joins its two ends.

Check yourself

  1. A graph has 10 nodes and no edges. How many pieces does it have?

    Answer

    10. Each node is a piece by itself.

  2. Five nodes are joined in a line: 1–2, 2–3, 3–4, 4–5. You cut one edge. How many pieces are there now? What if the line were closed into a ring with the edge 5–1?

    Answer

    Two, whichever edge you cut: every edge of a line is a bridge. In a ring, one cut leaves a single piece, because every edge lies on the loop.

  3. A shape is stored as points, with an edge between any two points closer than 1 unit. The graph has two pieces. What does that say about the shape?

    Answer

    The points form two separate clusters: no point of one lies within 1 unit of any point of the other.

Go further

Optional background, for readers who want more than this page.

Where this shows up

No unit or explanation builds on this one yet.