AlgoScope

Connected Components

AlgorithmbeginnerGraph Traversal

Run BFS or DFS from every unvisited vertex; each run colours one component.

Decision · step 2 of 13BFS and DFS: Three components
011234567u

Vertex 0 has no component number yet, so it starts component 1. Traverse from it.

Open in the player →or start at step 2

What you will see

Each traversal floods one island with a component number.

How bfs and dfs works →

Cost

BestO(V + E)
AverageO(V + E)
WorstO(V + E)
SpaceO(V)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.

Screen readers: Vertices announce name, neighbours and state (in queue, visited, current); each step announces which vertex is processed and which neighbours are discovered.

Reduced motion: Frontier and visited changes are crossfades; the traversal edge is emphasized without a travelling token.

Leads to

Topics that need this one first.

Taught by the same lesson

BFS and DFS covers these too, in the same run.