The connected components of a graph are its separate islands — maximal groups of nodes reachable from each other. Counting them answers “how many separate networks are here?”: distinct social circles, disconnected clusters, isolated regions of a map. Union-find makes it a one-liner: merge every edge, then count the distinct roots — each root is one island. (DFS/BFS do it too, starting a new search from each unvisited node.) A graph with edges 0-1, 1-2, and 3-4 has two components: {0, 1, 2} and {3, 4}.
The demo unions the edges 0-1, 1-2, 3-4 and counts the components — 2 islands: live demo
“A graph is one connected thing.” — often it is several islands; counting the union-find roots tells you how many. cited
A graph’s separate islands counted by the roots that remain — how many networks in one picture. resource
On the canonical compiler, edges 0-1, 1-2, 3-4 give 2 components ({0,1,2} and {3,4}):