Basic graph theory: bipartite graphs, colorability and connectedness (CSCI 2824, Spring 2015)In this lecture, we will look at the following topics:
We will start by revising walks, paths and give examples. WalksLet Definition: Walk
A walk over where
In other words, a walk over a digraph is simply a sequence of visits to nodes and arcs of the graph wherein
Example-1Take the graph:
Here are some walks
PathsGiven an undirected graph, a path from a vertex
Example 1Take the graph:
There are two paths between
The following are not paths:
Example 2Consider the undirected graph
There are at least five paths from
Are there any more paths between Note that even though the graph is undirected, the path itself is from This is not always true in a directed graph. In the previous example there is a path from CycleA cycle in a graph is a “path” from a vertex back to itself. I place “path” under quotes because we just defined paths so that vertices cannot repeat. Definition: Cycle
Formally, a cycle is a sequence of nodes and edges of the form where other than The length of a cycle is the number of edges in it. The choice of a starting point in a cycle is arbitrary in the following sense. We could have written the same cycle above as Example 3Take the graph:
Examples of cycles in this graph include:
Example 4Consider the following undirected graph instead:
Note that The direction of a cycle does not matter in an undirected graph. The same cycle may be written as
Important Note Connected ComponentsWe now discuss the concept of strongly connected components (resp. connected components) in digraph (resp. undirected graphs). Basic idea (on undirected graphs)Let us start with the following example over the set of vertices:
The graph has two “islands”: We say that a subset of vertices By the same token, the set Also the set Connected Component: definition
Let
Example 5Consider the graph
Strongly connected components in digraphsStrongly connected components
Given a digraph
A digraph is said to be strongly connected if Example 6The digraph Bipartite GraphsBipartite comes from bi meaning two and partite meaning partitioned into. Definition
A graph
In other words, there can be no edges between vertices in Two colorability and chromatic numberOften, we think of bipartite graphs as two colorable graphs. I.e, it is possible to assign one of two different colors to the vertices of the graph so that every pair of adjacent vertices have different colors. It is easy to see that any bipartite graph is two colorable and
vice-versa. Simply take the set In general, the chromatic number of a graph is the minimum number of vertex coloring so that every pair of adjacent vertices have different vertex colors. It is known (via the Brook theorem) that the chromatic number of a graph is at most the maximum degree of the graph. Example 7Here is an example bipartite graph
The subset
Bipartite Graphs and CyclesWe now state the key results involving bipartite graphs. Theorem
A graph The theorem has two parts to it:
Odd Length Cycles
|
![]() |
An interesting pattern emerges:
n | Bipartite? |
2 | Yes |
3 | No |
4 | Yes |
5 | No |
6 | Yes |
7 | No |
2k | Yes |
2k+1 | No |
All odd cycles cannot be two colored, whereas even cycles can. Therefore, we note a key observation.
If a graph has an odd cycle someplace inside it, no assignment of two colors will work. This is because the odd cycle cannot be two colored.
This proves that a bipartite graph cannot have an odd length cycle inside.
This direction is slightly more complex.
Assume the graph is connected. Otherwise, will prove this separately for each maximally connected component of the graph.
Choose an arbitrary start node and make two sets
and
It is easy to prove that if the graph is bipartite, then , and coloring every node in
as 'White’ and
coloring every node in
as black will provide a partition of the graph.
Otherwise, if the graph is not bipartite, then . Therefore, there exists a node
that is reachable from
by an even length path and an odd length path.
Therefore, there is a walk of odd length starting at and ending
in
obtained by combining the odd and even length paths from
to
.
We can use a well known result that any walk of odd length from to
in a graph
has an odd length cycle.
We will write a simple program that performs a depth-first search, and will try to color the nodes of a graph black and white in an alternating fashion, while performing a depth first search.
# Main function that visits a node v and seeks to color it with colorID # It perfoms a depth first search starting from v to color successors with the opposite color. # If it finds a that a node has been colored white and then black, then it reports a CONFLICT def colorNode(G,v,colorID): # Have I already seen node v before? if (alreadyVisitedNode(v)): if (colorNode(v) is not colorID): raise 'CONFLICT' # EXIT: the graph is NOT bipartite else: return # Nothing else to be done. # Mark that node v has been visited markVisited(v) succColor = complement(colorID) # Iterate through all outgoing nodes and # color them with opposite (complement) color foreach u in adjacency(v): colorNode(G,v, succColor) #MAIN LOOP # just start off by coloring every node that has not been # already visited with the White color. # foreach vetex v in G: if (not alreadyVisitedNode(v)): colorNode(G,v,'White')
A graph is not bipartite if and only if the function 'colorNode’ returns a 'CONFLICT’. Otherwise, the procedure will color the graph successfully with two colors showing that it is bipartite.
You should be able to use your data structures know-how to easily write code that given a graph says whether or not it is bipartite.