AlgoBazaAlgoBaza
Back to algorithms

Connected Components

Algorithm for finding connected components in an undirected graph. Uses DFS with an outer loop over all vertices — each unvisited vertex starts a new component, and DFS visits all vertices in that component.

Sredni
O(V+E)O(V)OIJOI
Select programming language
Choose the language to see the connected components implementation.
Select example
Small, Medium, and Large show recursion code generation. Very large shows only the call stack.

Connected Components (Python): Small graph (5 vertices, undirected)

1/0
1.0x