Connected Components
Run BFS or DFS from every unvisited vertex. Each run colours one component.
BFS and DFS: Three components
Vertex 0 has no component number yet, so it starts component 1. Traverse from it.
Cost
- Best
- O(V + E)
- Average
- O(V + E)
- Worst
- O(V + E)
- Space
- O(V)
Before this
Related
Leads to
Topics that need this one first.
Taught by the same lesson
BFS and DFS covers these too, in the same run.