Either BFS or DFS both can do it in $\theta(m+n)$ time.

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+13 votes

The most efficient algorithm for finding the number of connected components in an undirected graph on $n$ vertices and $m$ edges has time complexity

- $\Theta(n)$
- $\Theta(m)$
- $\Theta(m+n)$
- $\Theta(mn)$

+19 votes

Best answer

+11 votes

–1 vote

+2

Question asks for connected components in an undirected graph, you have given reference for finding strongly connected components in a directed graph.

+1

ok... but is it really effect ? i mean we cant use for undirected graph ...

see this ...

http://www.geeksforgeeks.org/strongly-connected-components/

see this ...

http://www.geeksforgeeks.org/strongly-connected-components/

- All categories
- General Aptitude 1.3k
- Engineering Mathematics 5.2k
- Digital Logic 2k
- Programming & DS 3.7k
- Algorithms 3.2k
- Theory of Computation 4k
- Compiler Design 1.6k
- Databases 3k
- CO & Architecture 2.6k
- Computer Networks 3k
- Non GATE 1k
- Others 1.3k
- Admissions 488
- Exam Queries 436
- Tier 1 Placement Questions 18
- Job Queries 56
- Projects 9

36,204 questions

43,662 answers

124,118 comments

42,948 users