Question DSA-GRAPH-0078
HardHow do you count connected components in an undirected graph in O(V + E)?
- A.
Run BFS/DFS from each unvisited vertex and count the runs
- B.
Count edges
- C.
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Graphs question
How do you count connected components in an undirected graph in O(V + E)?
Run BFS/DFS from each unvisited vertex and count the runs
Count edges
Sign up free to see the answer and a step-by-step explanation.
Sort the edges
Use Floyd–Warshall