@above Many ways to do this problem One will be to find the bfs (there will be many and this will lead to a forest ) This , in turn can be done in O(e+v) , using adjancy list or matrix . Whenever , we cannot go further , start from any new uncovered node , and keep exploring recursively .Keep a boolean flag array for the elements you have already covered .
Also , this looks like a union find problem .So one can also do this using disjoint set data structure . http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=disjointDataStructure -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
