简体   繁体   English

证明图是二部图

[英]Prove that a graph is bipartite

Given a graph G in which every edge connects an even degree node with an odd degree node. 给定图G,其中每个边将偶数度数节点与奇数度数节点连接。 How can i prove that the graph is bipartite? 我如何证明该图是二部图?

Thanks in advance 提前致谢

Because by definition you already have two disjoint sets of vertices such that the only edges go between a vertex in one set and a vertex in the other set. 因为根据定义,您已经有两套不相交的顶点,因此,只有边在一组的顶点与另一组的顶点之间。

The even degree nodes are one set, and the odd degree nodes are the other set. 偶数度数节点是一组,奇数度数节点是另一组。

Pick any node, put it in set A. Take all the nodes that link to it, put them in set B. Now for every node added, add all it's neighbors to the opposite set, and check for the ones that already belong to one of the sets that they are in the right set. 选择任何节点,将其放在集合A中。取出所有链接到它的节点,将它们放入集合B中。现在,对于每个添加的节点,将其所有邻居添加到相反的集合中,并检查是否已经属于一个节点在正确的集合中。 If you get a contradiction then the graph is not bipartite. 如果您有矛盾,则该图不是二分图。

If you run out of neighbors but there are still nodes left, pick again any node and continue the algorithm until you either have no nodes or you found a contradiction. 如果邻居用完了,但仍然有节点,请再次选择任何节点并继续算法,直到您没有节点或发现矛盾为止。

This is the Welsh-Powell graph colouring algorithm: 这是威尔士-鲍威尔图着色算法:

  1. All vertices are sorted according to the decreasing value of their degree in a list V 所有顶点根据列表V中度的递减值进行排序

  2. Colours are ordered in a list C 颜色在列表C中排序

  3. The first non-coloured vertex v in V is coloured with the first available colour in C. "Available" means a colour that has not previously used by this algorithm V中的第一个非着色顶点v用C中的第一个可用颜色着色。“可用”表示该算法先前未使用的颜色

  4. The remaining part of the ordered list V is traversed and the same colour is allocated to every vertex for which no adjacent vertex has the same colour 遍历有序列表V的其余部分,并且将相同的颜色分配给每个相邻顶点都不具有相同颜色的顶点

  5. Steps 3 and 4 are applied iteratively until all the vertices have been coloured 重复应用步骤3和4,直到所有顶点都已着色

A graph is bipartite if it is 2-colourable. 如果图是2色的,则该图是二部图。 This intuitive fact is proven in Cambridge Tracts in Mathematics 131. 这个直观的事实在《剑桥丛书》第131章中得到了证明。


This is, of course, the cannon with which to shoot a mosquito. 当然,这是用来发射蚊子的大炮。 A graph is bipartite iff its vertices can be divided into two sets, such that every edge connects a vertex from set 1 to one in set 2. You already have such a division: each edge connects a vertex from the set of odd-degree vertices, to a vertex in the set of even-degree vertices. 一个图是二分图的,因为它的顶点可以分为两组,这样每个边都将一组1中的一个顶点连接到一组2中的一个顶点。您已经有了这样的划分:每个边都将一组奇数顶点连接到一个顶点上到偶数度顶点集中的一个顶点。

If by "prove", you mean "find out", the complete solution is here 如果用“证明”来表示“查找”,则完整的解决方案在这里

Bipartite.java Bipartite.java

It works by keeping two boolean arrays. 它通过保留两个布尔数组来工作。 A marked array to check if a node has been visited, and another colored array. 用于检查是否已访问节点的标记数组,以及另一个彩色数组。 It then does a depth first search, marking neighbors with alternate colors. 然后,它会进行深度优先搜索,并用其他颜色标记邻居。 If a neighbor is marked with same color, graph is not bipartite. 如果邻居用相同的颜色标记,则图不是二分图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM