如何证明一个图是二部图?

问题描述

我知道一个理论和引理,如果一个图包含一个奇数长度的循环,那么它不能是二部的,但我如何证明它?

以这个为例 邻接矩阵我如何证明这个图是或不是二部图?

解决方法

这是我将使用的算法。它使用我在上面评论中提到的方法(3):确定两个集合并确认它们满足要求(即每个顶点只连接到另一个集合)

  1) Make two sets,group1 and group2.  
     Mark all of the vertexes as unassigned and incomplete

  2) Assign the first unassigned vertex to group1 and make it the current vertex

  3) For every assigned vertex connected to the current vertex (both to and from):
    a) If the current vertex is unassigned,then assign the current vertex to the other group
    b) If the current vertex is assigned to the same group,then the graph is not bipartite,EXIT

  4) If the current vertex is still unassigned then assign it to group1
  5) For every unassigned vertex connected to the current vertex (both to and from):
    a) assign it to the other group
  6) Mark the current vertex as complete

  7) Make the first incomplete assigned vertex the current vertex
    a) If there are none,then make the first unassigned vertex the current vertex
    b) If there are none,then the graph is bipartite.  EXIT

  8) GoTo (3)

如果您使用邻接矩阵,那么这可能是 O(v^2),其中 v 是顶点数。如果您将其更改为附有 To/From 连接列表的顶点列表,那么我认为它是 O(v+c),其中 c 是连接数。