77

How can we prove that a graph is bipartite if and only if all of its cycles have even order? Also, does this theorem have a common name? I found it in a maths Olympiad toolbox.

Asinomás
  • 107,565

6 Answers6

116

One direction is very easy: if $G$ is bipartite with vertex sets $V_1$ and $V_2$, every step along a walk takes you either from $V_1$ to $V_2$ or from $V_2$ to $V_1$. To end up where you started, therefore, you must take an even number of steps.

Conversely, suppose that every cycle of $G$ is even. Let $v_0$ be any vertex. For each vertex $v$ in the same component $C_0$ as $v_0$ let $d(v)$ be the length of the shortest path from $v_0$ to $v$. Color red every vertex in $C_0$ whose distance from $v_0$ is even, and color the other vertices of $C_0$ blue. Do the same for each component of $G$. Check that if $G$ had any edge between two red vertices or between two blue vertices, it would have an odd cycle. Thus, $G$ is bipartite, the red vertices and the blue vertices being the two parts.

Brian M. Scott
  • 631,399
  • genius... thanks a lot Brian! – ILoveMath Nov 28 '13 at 04:58
  • @Atahualpa: You’re welcome! – Brian M. Scott Nov 28 '13 at 16:15
  • @BrianM.Scott I think at the second direction of the proof, we can prove it by a direct proof. i.e. Suppose we have an odd cycle, then you cannot create two independent set. Therefore, you cannot have a bipartite graph. the proof is completed. – YOUSEFY Oct 18 '16 at 17:06
  • 1
    @YOUSEFY: That’s the direction that I proved in the first paragraph. And I gave direct proofs for both directions. – Brian M. Scott Oct 19 '16 at 09:43
  • @BrianM.Scott you mean second paragraph because I mean by second direction is that "if G is even cycle, then G is biparitite" and first paragraph is for the converse. You proof is amazing, but I was thinking that If I use the term 'independent set' it will be so easy to understand and this is the point of using terminology in graph theory, that was my point. – YOUSEFY Oct 19 '16 at 15:31
  • 2
    @YOUSEFY: No, I mean the first paragraph. What you proved in your comment is that if $G$ has an odd cycle, then $G$ is not bipartite, which is the contrapositive of (and logically equivalent to) the statement that if $G$ is bipartite, then it has no odd cycle. What I proved in the second paragraph is that if $G$ does not have an odd cycle, then $G$ is bipartite. This is the converse of what you proved. – Brian M. Scott Oct 19 '16 at 15:34
  • @BrianM.Scott That's right, I didn't notice that. Thanks for pointing this out. Yes, I remember this in a logic (P implies Q is the same as NOT-Q implies NOT-P). – YOUSEFY Oct 19 '16 at 15:59
  • @BrianM.Scott I am not getting your first point "One direction is very easy: if $G$ is bipartite with vertex sets $V1$ and $V2$, every step alone a walk takes you either from $V1$to $V2$ or from $V2$ to $V1$. To end up where you started, therefore, you must take an even number of steps.",can you give a small example ? – sourav_anand Nov 01 '16 at 16:26
  • 1
    @sourav: If you start at a vertex in $V_1$ and take a walk of length $3$, say, your first step goes to a vertex in $V_2$, your second to a vertex in $V_1$, and your third to a vertex in $V_2$; since you started in $V_1$ and are now in $V_2$, you can’t possibly have returned to your starting vertex. The same thing happens for any odd number of steps. – Brian M. Scott Nov 01 '16 at 16:31
  • 1
    @sourav: You’re welcome. – Brian M. Scott Nov 01 '16 at 16:37
  • @BrianM.Scott "if a Graph G contains no odd cycle,then it is bipartite",proving it i encountered a problem ..let Graph G is disconnected containing connected component $C_{1}$ , $C_{2}$ ..now let $C_{1}$,$C_{2}$ contains $\text{odd}$ cycle ...now isn't graph Bipartite? $C_{1}$ $\cap $ $C_{2}$ =$\phi$ My doubt is ..does this theorem don't work for disconnected graph? – sourav_anand Nov 01 '16 at 18:41
  • 1
    @sourav: No, the graph is not bipartite. Being bipartite has nothing to do with how many components the graph has. A graph is bipartite if the vertices can be partitioned into two sets, say $V_1$ and $V_2$, such that every edge is between a vertex in $V_1$ and a vertex in $V_2$, i.e., so that there are no edges between vertices in $V_1$ and no edges between vertices in $V_2$. – Brian M. Scott Nov 01 '16 at 18:45
  • @BrianM.Scott actually i mean that we have two connected components $C_{1}$ containg odd cycle and having vertex set $V_{1}$ and we have another component $C_{2}$ also containing odd cycles containing vertex set $V_{2}$ now we can partition Graph G into two vertex set $V_{1}$ and $V_{2}$ ,also $V_{1}$ $\cap$ $V_{2}$ = $\phi $ making it bipartite graph though containing odd cycle each...there is am i stuck at! – sourav_anand Nov 01 '16 at 18:51
  • 1
    @sourav: No, it is not bipartite. If it were bipartite with parts $V_1$ and $V_2$, all of the edges would be between $V_1$ and $V_2$. Neither would contain any cycles at all. – Brian M. Scott Nov 01 '16 at 18:53
  • okk got it @BrianM.Scott ! sorry for disturbing you again ..now my concept is clear !thank you again! – sourav_anand Nov 01 '16 at 18:54
  • @sourav: You’re welcome! – Brian M. Scott Nov 01 '16 at 18:55
  • I couldn't get the converse part.can you explain a bit more – user471651 May 14 '18 at 05:09
  • Why "if G had any edge between two red vertices or between two blue vertices, it would have an odd cycle"? I don't think it's very obvious. The two shortest paths can overlap in vertices and edges. – Mengfan Ma Nov 04 '19 at 01:17
  • @MengfanMa: Doesn’t matter. Let the two vertices in question be $u$ and $v$, let $P$ be a shortest path from $v_0$ to $u$ together with the edge $uv$, and let $Q$ be a shortest path from $v_0$ to $v$. Remove all edges that are in both $P$ and $Q$, if any. What remains is a collection of disjoint cycles, at least one of which must be odd. (I didn’t say that it was instantly obvious. It is, however, quite easy to check.) – Brian M. Scott Oct 24 '20 at 02:06
  • @BrianM.Scott This is a nice solution, but I just had one question. In the second part, you have assumed that every cycle of $G$ is even, and worked on these even cycles. But, how do we know that all vertices are a part of some even cycle? I mean, there may be vertices that do not form either even or odd cycles as well... – Sayan Dutta Sep 04 '21 at 17:46
  • @SayanDutta: No, I worked on all of the vertices, not just those that are in even cycles. Specifically, I described a way to color all of the vertices red or blue and showed that if this coloring is not a bipartition, then $G$ must have an odd cycle. Since $G$ is assumed not to have an odd cycle, the coloring must be a bipartition of the vertices. To get a better idea of what’s going on, suppose that $G$ is a tree, so that it has no cycles at all. Pick any vertex to be $v_0$, and carry out the coloring procedure that I described. Because $G$ is a tree, there is a unique path from $v_0$ to ... – Brian M. Scott Sep 04 '21 at 19:26
  • ... any vertex $v$ of $G$. If that path has even length, $v$ is red; if that path has odd length, $v$ is blue. If you draw $G$ as a tree with root $v_0$, you’ll see that the blue vertices are those on levels $1,3,5,\ldots$, while the red vertices are those on levels $0,2,4,\ldots$, and you have a bipartition of the vertices. – Brian M. Scott Sep 04 '21 at 19:28
  • @BrianM.Scott Okay, I think I got it. So, the main point is the "shortest path" and not the "same component", right? Brilliant answer by the way (+1)! – Sayan Dutta Sep 04 '21 at 19:37
  • @SayanDutta: Yes, shortest path is the crucial point, but it makes sense only for vertices in the same component. We’re really showing that each component is bipartite, but of course that means that the whole graph is as well. – Brian M. Scott Sep 05 '21 at 19:00
  • @BrianM.Scott but we could have done it without considering the components as well, isn't it? Just fixing a $v_0$ and then playing with the shortest path to $v$... – Sayan Dutta Sep 05 '21 at 19:02
  • @SayanDutta: No, because if $v$ is a vertex of $G$ that is not in the same component as $v_0$, there is no path from $v_0$ to $v$. We have to work in each component separately. – Brian M. Scott Sep 05 '21 at 20:01
  • @BrianM.Scott now, I really understand. The problem was your use of the notation $C$ to represent components. Because you used $C$, I thought, by component you always meant a cycle. I don't know whether it's only my problem, but I would suggest you to add a small clarification. Thanks by the way, now it's really clear. – Sayan Dutta Sep 05 '21 at 20:38
  • This is one of the best arguments I've seen. Probably it would be more than clear if we suppose $G$ is not connected graph, so we get ${A,B}$ in the same component and the path $A-V_0$ joined with $V_0-B$ joined with the edge ${A,B}$ is always an odd cycle. – Blue Tomato Sep 13 '22 at 19:00
13

The following is an expanded version of Brian's answer. Brian's answer is almost perfect, except that there may be a gap between "if G had any edge between two red vertices or between two blue vertices" and "it would have an odd cycle", which is not that obvious, at least to me(since we can only conclude that there exists a closed walk of odd numbers of edges). We first prove a lemma stating that if there is an odd closed walk in a graph, then there is an odd closed cycle.

Lemma 1 If there is an odd closed walk in a graph, then there is an odd closed cycle.

Proof$\;$ We induct on the number of edges $k$ of the odd closed walk. The base case $k=1$, when the closed walk is a loop, holds trivially. Assume that, for some positive integer $r > 1$, Lemma 1 is true for all odd numbers $k\le2r-1$. Let $W=(w_1, \dots, w_{2r+1}, w_1)$ be a closed walk of $2r+1$ edges. If all vertices in $W$ is different except for $w_1$, then we have a cycle of length $2r+1$. If there exists two identical vertices $w_i=w_j$ for $1<i<j\le 2r+1$, then $W$ can be written as $(w_1, \dots,w_i, \dots, w_j,\dots, w_1)$. Thus, we now have two closed walks $W_1=(w_i,w_{i+1} \dots, w_j)$ and $W_2=(w_j,w_{j+1} \dots, w_i)$. The summation of the length of $W_1$ and $W_2$ equals to the length of $W$. Since $W$ is of odd length, one of $W_1$ and $W_2$ must be of odd length $\le 2r-1$. By our assumption, there must be a an odd cycle in $W_1$ or $W_2$, and thus in $W$, which completes our induction. $\square$

Theorem 1 If there are no odd cycles in a graph, then the graph is bipartite.

Proof$\;$ Suppose there is no odd cycles in graph $G=(V,E)$. It is also assumed that, without loss of generality, $G$ is connected. Then $V$ can be partitioned into $(A,B)$, where $$A=\{v\in V|\text{the shortest path between $v$ and $v_0$ is of even length}\}$$ $$B=\{v\in V|\text{the shortest path between $v$ and $v_0$ is of odd length}\}$$ Next we prove that there is no edge between any two vertices in $A$ or $B$. Suppose for contradiction that there exists an edge $(x,y)\in E$ such that $x,y \in A$ or $x,y \in B$ . Then the shortest path from $x$ to $v_0$, the shortest path from $y$ to $v_0$, together with edge $(x,y)$, form a closed walk: $(v_0, \dots,x,y, \dots,v_0)$, which is of odd length. By lemma 1, $G$ contains an odd cycle, which is a contradiction.

Therefore, $G$ is a bipartite graph between $A$ and $B$. $\square$

Mengfan Ma
  • 653
  • 6
  • 21
  • 2
    Is it not sufficient to note that two vertices $u,w$ in the same set of the bipartition cannot share an edge as $d(v_0,u) = d(v_0,w) \pm 1$?. Say $u$ is closer to $v_0$ than $w$. Then one shortest path from $v$ to $w$ is the one passing through $w$. But then the distances to $w$ and $u$ have different parity and so they aren't in the same set. – Sergio Escobar May 04 '20 at 04:11
  • @SescoMath What if $d(v_0, u) = d(v_0, w)$? Then any path from $v_0$ to $u$ passing through $w$ has length $>d(v_0, w)$, and hence is not the shortest. Moreover, I don't think your argument uses the assumption that $G$ contains no odd cycles? – awllower Sep 20 '23 at 11:35
12

does this theorem have a common name?

It is sometimes called König's Theorem (1936), for example in lecture notes here (Wayback Machine).


However, this name is ambiguous.

pundir
  • 121
  • I expanded your answer a bit, as it drew some low-quality flags. –  Jul 01 '15 at 17:45
  • I don't agree with you. in the textbook of Diestel, he mentiond König's theorem in page 30, and he mentiond the question of this site in page 14. he didn't say at all any similiarities between the two. Also, König's talks about general case of r-paritite so if what you're saying is true, then the theorem is just a special case of general case. Right now, I don't have any name for it except it is a proposition (means something that mathematicains do find it interesting but it doesn't come becasue they're thinking on it so much) – YOUSEFY Oct 18 '16 at 17:15
5

The fact that no bipartite graph has any odd cycles is proved in other answers.

Theorem: If a graph $G$ has no odd cycles, $G$ is bipartite.

Proof: Suppose not. Then there is a least $n$ where there is an $n$-node counterexample. Let $G$ be such a counterexample.

Let $v$ be any node of $G$. $G\setminus v$ has $n-1$ nodes, and no odd cycles, and so is bipartite. Two-colour its nodes red and blue. Restore $v$.

If all $v$'s neighbours have the same colour, give $v$ the opposite colour. Then $G$ is bipartite; contradiction.

Suppose $v$ has a red neighbour $u$ and a blue neighbour $w$ in the same component of $G\setminus v$. Then $G\setminus v$ has a path from $w$ to $u$. This path's length is odd (because it alternates red and blue nodes, so it contains an even number of nodes and an odd number of edges). Together with $u\sim v$ and $v\sim w$ this makes an odd cycle in $G$; contradiction.

So all $v$'s red neighbours are in different components of $G\setminus v$ from $v$'s blue neighbours. So swap the colour of every node in every component containing a blue neighbour of $v$. So now all $v$'s neighbours are red. Colour $v$ blue. Thus $G$ is bipartite; contradiction.

Rosie F
  • 3,231
1

(By contradiction) (->) Suppose n is odd. Let X={ui such that i is odd} and Y={ui such that i is even} as the bipartition formed in the graph. Consider cycle C=u1 u2 u3 u4...un u1 as the cycle in G. If u1 is odd, un can not be odd because there will be no bipartite formed. Therefore, n should be even.

Mishel
  • 81
0

One direction is clear. For the other direction you can show this by induction on the number of vertices of $G$.

Suppose $G$ is a graph on $n$ vertices and that it does not contain any odd cycle. Pick a vertex $v$ in $G$ and consider the graph $G\setminus v$. This has $n-1$ vertices and doesn't contain any odd cycle because $G$ doesn't, so it's bipartite by induction hypothesis.

Now let $A$ and $B$ give partition of the bipartite graph $G\setminus v$ and consider where $v$ should go. If all of the neighbours of $v$ are in $A$ (respectively $B$) then put $v$ in $B$ (respectively $A$) to get that $G$ is bipartite. Otherwise let $u \in A $ and $w \in B$ be neighbours of $v$. But then $u$ and $w$ are joined by a path of odd length in $G\setminus v$ by choice of $A$ and $B$ so this path together with the edges $vu$ and $wv$ gives an odd cycle, which is a contradiction.

banana
  • 19