Concept Flow - Connected Components Using BFS
Start with graph
Initialize visited set
For each node in graph
If node not visited?
No→Skip
Yes
Start BFS from node
Add node to queue and visited
While queue not empty
Dequeue node
For each neighbor
If neighbor not visited
Add neighbor to queue and visited
Repeat until queue empty
One connected component found
Repeat for next unvisited node
All nodes visited, done
We visit each node in the graph. If not visited, we run BFS to find all nodes in its connected component, marking them visited. Repeat until all nodes are visited.
