Codacoda
Back to Academy

graphs

Connected Components

Connected Components identifies all groups of vertices in an undirected graph where every vertex is reachable from every other vertex in the same group. It uses DFS or BFS to traverse each unvisited vertex, marking all reachable nodes as part of the same component. This is fundamental for understanding graph structure and connectivity.

Use Cases

  • Social network analysis to find friend clusters
  • Image processing for identifying distinct regions
  • Network reliability analysis to detect isolated subnetworks

Complexity Analysis

MetricBestAverageWorst
TimeO(V + E)O(V + E)O(V + E)
SpaceO(V)

Visualization

4251810263ABCDEF
Speed:1x
Graph readyStep 1 / 8

Implementation

Output

Click "Run Code" to see output...