How to Determine a Bipartite Graph
Note
Now all the plugins has supported English. I'm still improving the website...
This article will resolve
LeetCode | Difficulty |
---|---|
785. Is Graph Bipartite? | 🟠 |
886. Possible Bipartition | 🟠 |
Prerequisite Knowledge
Before reading this article, you should first learn:
Today, we will discuss a classic graph theory algorithm: bipartite graph detection.
Introduction to Bipartite Graphs
First, let's look at the definition of a bipartite graph
The vertex set of a bipartite graph can be divided into two disjoint subsets. Each edge in the graph connects vertices from these two subsets, and vertices within each subset are not adjacent.
In fact, many graph theory terms have definitions that are quite complex and hard to understand. Let's skip the rigid definition and play a game instead:
Given a "graph," try to color all vertices using two colors such that the endpoints of every edge have different colors. Can you do it?
This is the "two-color problem" of graphs, which is equivalent to the bipartite graph detection problem. If you can successfully color the graph, then it is a bipartite graph; otherwise, it is not:
Before diving into the specifics of the bipartite graph detection algorithm, let's discuss why computing experts originally tackled the two-color problem.