How to find if a graph is bipartite?

前端 未结 7 1808
一生所求
一生所求 2020-12-25 14:16

I have been trying to understand the bipartite graph. To my understanding it is a graph G which can be divided into two subgraphs U and V.So that intersection of U and V is

7条回答
  •  离开以前
    2020-12-25 14:58

    From Carnegie Mellon University:

    "Recall that a graph G = (V, E) is said to be bipartite if its vertex set V can be partitioned into two disjoint sets V1, V2 such that all edges in E. have one endpoint in V1 and one endpoint in V2.

    (source: http://www.cs.cmu.edu/~15251/homework/hw5.pdf)

    Are you sure that you need to use BFS? Determining if a graph if bipartite requires detecting cycle lengths, and DFS is probably better for cycle detection than BFS.

    Anyway, a graph if bipartite if and only if it has no cycles of odd length. If you're allowed to use DFS, you can DFS on the graph and check for back-edges to detect the presence of cycles and use DFS timestamps to compute the size of each cycle.

提交回复
热议问题