What is a Graph? · Basic Graphs
Lesson 12
Another important class is bipartite graphs. An undirected graph is called bipartite if its set of nodes \(V\) can be partitioned into two sets \(V_{1}\) and \(V_{2}\) such that every edge joins a node from \(V_{1}\) and a node from \(V_{2}\). (In other words, there are no edges within one part.) In many applications, a graph is given together with a partition and is denoted by \(G(V_{1} \sqcup V_{2}, E)\). Sometimes, \(V_{1}\) and \(V_{2}\) are called \(L\) and \(R\) and a graph is drawn with the nodes from \(L\) on the left and nodes from \(R\) on the right. Here is an example where it is visually clear that every edge joins two nodes from different parts.

In applications, the two parts may have different “physical meaning”:
- boys and girls;
- students and dormitories;
- hospitals and patients;
- servers and requests;
- customers and products.
At the same time, it is not always the case that a graph is given together with a partition of the set of nodes into two parts. For example, the following \(7 \times 4\) grid graph is bipartite though it may not be immediate from its drawing.


from networkx import grid_2d_graph, is_bipartite
print(is_bipartite(grid_2d_graph(7, 4)))True