 In the previous lecture we defined, g is n partide if the vertices of g can be partitioned into n sets where any edge of g joins vertices in distinct sets and no edge joins vertices in the same set. In the special case where n equals 2, we say the graph is bipartide and sometimes we call it a biograph. We did find that every tree is a bipartide graph where we could form the partition by determining whether a vertex is at an even or an odd distance from some selected starting vertex. We also found that if g is bipartide then every cycle has even length. But we want a way to decide if a graph is bipartide, and so the question you've got to ask yourself is, could the converse be true? Let's find out. So a useful idea in math and in life, reduce, reuse, recycle. The vertices of a tree can be partitioned based on their distance for a chosen starting point. Let's try that here. Let v0 be a point in a connected graph g where all cycles have even length. Form two sets, v1, the set of all points an odd distance from v0, and v2, the set of all points an even distance from v0. And if the graph isn't connected, we could consider each connected component separately. Suppose v and v' are two points in one of these sets, say v1. If an edge between them exists, we can produce an odd cycle as follows. The distance from v0 to v is odd. The distance from v to v' is 1. And the distance from v' back to v0 is odd. So an odd length cycle exists. Or does it? Remember, a cycle has no repeated vertices, but we can't guarantee this happens. However, it is a closed walk of odd length. Can we do anything with walks? So let's consider that p1 be the geodesic from v0 to v, and p2 the geodesic from v0 to v' And suppose this geodesic crosses the first one or more times at u1, u2, and so on, where u1 is our first intersection going from u to v' and uk is the last intersection. Note these adjacent intersections create a cycle that consists of the part of p1 between the two vertices and the part of p2 between the two vertices. By assumption, all cycles are even, so the lengths of these paths are either both even or both odd. So now consider the path from u to vk on our first geodesic, and the path from u to vk on our second geodesic. Because both paths consist of the parts of the geodesics on the different cycles, and the parts always have the same parity, then both paths either have even length or odd length. If both lengths are even, so is the last part of the path from uk to v, as does the last part of the path from uk to v'. And that means we do have this cycle from uk to v to v' to uk again with odd length. Alternatively, if both of these lengths are odd, so is the last part of the path, because remember the total distance was even, and once again the cycle uk to v to v' to vk has odd length. But this can't happen, so no edge can join two vertices in v2. Likewise, if an edge joins two vertices in v1, there will be an odd cycle. Consequently, if all cycles of a graph g have even length, then g is bipartite. Moreover the proof tells us how to split up the vertices. If a graph is bipartite, then given any point v0, we can partition it as v1 and v2, where v1 consists of a point an odd distance from v0, and v1 consists of points an even distance from v0. So if we want to determine if a graph is bipartite, we'll choose some initial point and partition the remaining points into those that are an even distance away and those that are an odd distance away. So maybe we'll pick this point, so let's slide this point over to one side. The adjacent points are at distance 1, which is odd, so we'll slide those over to the other side. The points adjacent to those points are at an even distance from our starting point, so we'll move them off to the other side. The points adjacent to those points are now at an odd distance, we'll move them back, and now notice that there is an edge between two points in the odd distance set, so the graph can't be bipartite. Or we could try something like this, so again we'll select a point, we'll move the adjacent points to one side, move the points adjacent to those to one side, move the points adjacent to those to one side, and now we have all of our points categorized by their distance from our starting point and we see no edge connects points in the same set, so the graph is bipartite. Unfortunately this approach only works if we can see the graph. Now separating the vertices by their distances from V0 is easy, but it seems that we need to check every edge of every vertex to see if it links to another vertex of the same set. Is there a more efficient way to do this? Yes, but we'll need to learn more graph theory, so we'll take a look at that, well later.