You just need to run DFS once. It will give you all the connected
components. So it is indeed O(n+e)

On Tue, Nov 24, 2009 at 2:43 PM, Rohit Saraf <rohit.kumar.sa...@gmail.com>wrote:

> Isnt it running DFS on every node?
> 1) Pick any node in the graph say n
> 2) With n as root, run DFS. While running DFS, if you visit node x, mark
> M[n,x]=1 and M[x,n]=1 .
> The running time is O(k+E) [not k, you are forgetting the case when E !=
> O(n)] .Also have a hash finished[n]=true.
>  3) Repeat steps 1-2 for each node until finished[node] = true for all of
> them.
>
> So overall time is not O(n^2). A proof of O(n^2) is also reqd. with the
> solution
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

--

You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.


Reply via email to