Multiple choice

Which of the following algorithms solves the Connected components problem?

  1. Greedy

  2. Depth-first search

  3. Dynamic programming

  4. Divide and conquer

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Depth-first search (DFS) can find connected components by traversing all reachable vertices from a starting point. Each DFS call identifies one connected component; repeat DFS from unvisited vertices to find all components.