Finding connected components of adjacency matrix graph

前端 未结 3 1019
终归单人心
终归单人心 2020-12-05 03:40

I have a random graph represented by an adjacency matrix in Java, how can I find the connected components (sub-graphs) within this graph?

I have found BFS and DFS bu

3条回答
  •  再見小時候
    2020-12-05 03:50

    You can implement DFS iteratively with a stack, to eliminate the problems of recursive calls and call stack overflow. The implementation is very similar to BFS with queue - you just have to mark vertices when you pop them, not when you push them in the stack.

提交回复
热议问题