algorithm - Finding Connected Components -
i want find connected components of directed acyclic graph using set of nodes. efficient way solve problem?
connected component: if 1 of nodes predecessor or successors of node, in same connected component.
for example, let's have following graph , vector = [2,4,5,6,3]
. vector, there 2 connected component below.
c1 = [2,4,5,6] c2 = [3]
my solution:
- sort nodes using depth value
- pick node
- check other nodes if successors or not. if so, keep looking. if not, stop , go step 2.
what think?
i hope understand definition of connected component...if that's case
i agree @anonymous, can make graph undirected , find connected components using simple dfs...
i not quite understand original thought, @ least think implementation bit complicated, edges {1-->2, 2-->4, 3-->4}, node #1 , #3 sorted @ beginning of list, , how can know {1,2,3,4} single connected component?
anyhow, complexity same simple dfs method, @ best, o(v)
(if think answer correct, please give credits @anonymous!)
Comments
Post a Comment