Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 如何证明图是二部图?_Algorithm_Graph_Bipartite - Fatal编程技术网

Algorithm 如何证明图是二部图?

Algorithm 如何证明图是二部图?,algorithm,graph,bipartite,Algorithm,Graph,Bipartite,我知道一个理论和引理,它说如果一个图包含一个奇数长度的圈,那么它就不可能是二部的,但是我怎么能证明它呢 以此为例, 邻接矩阵如何证明这个图是或不是二部图?下面是我将使用的算法。它使用我在上面的评论中提到的方法(3):确定两个集合并确认它们满足要求(即,每个顶点仅连接到另一个集合) 如果使用邻接矩阵,则这可能是O(v^2),其中v是顶点数。如果你把它改成一个顶点列表,并附加了to/From连接列表,那么我认为它是O(v+c)其中c是连接数。我不认为这个图是二部图,是吗?是的,但我不能证明这两个组

我知道一个理论和引理,它说如果一个图包含一个奇数长度的圈,那么它就不可能是二部的,但是我怎么能证明它呢

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

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


如果使用邻接矩阵,则这可能是
O(v^2)
,其中
v
是顶点数。如果你把它改成一个顶点列表,并附加了to/From连接列表,那么我认为它是
O(v+c)
其中
c
是连接数。

我不认为这个图是二部图,是吗?是的,但我不能证明这两个组是{2,5}和{1,3,4,6},这有用吗?有很多方法可以做到这一点,您可以1)找到每个循环,并检查是否没有奇数循环长度。或2)尝试应用两种颜色,看看是否失败,或3)确定两组颜色,然后确认它们符合要求(即,仅连接到另一组)。我个人认为3是最简单的。嗯,虽然我猜(2)和(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)