graph structures
Bipartite Graphs
You should know: graph basics
Overview
A bipartite graph is a graph whose vertices can be split into two disjoint sets, X and Y, such that every edge connects a vertex in X to a vertex in Y — no edge ever joins two vertices within the same set. Bipartite graphs naturally model matching problems between two distinct kinds of objects: job applicants and job openings, students and schools, or buyers and sellers. A fundamental theorem states that a graph is bipartite if and only if it contains no odd-length cycle, giving an easy algorithmic test via a two-coloring attempt during BFS or DFS.
Intuition
Picture a school dance where boys must be paired only with girls, never boy-with-boy or girl-with-girl — every dance pairing (edge) crosses between the two groups. That's the essence of bipartiteness: two 'teams' of vertices where all the action happens between teams, never within one. This structure shows up whenever you're matching two different kinds of things: workers to tasks, courses to time slots, or organs to transplant recipients.
Formal Definition
A graph G = (V, E) is bipartite if V can be partitioned into two sets X and Y with:
Worked Examples
Try to 2-color: put A and B in set X, and see if all their neighbors can go in set Y.
A's neighbors are C, D; B's neighbor is C. All of C, D can be placed in Y without conflict.
Check every edge crosses X-Y: A-C (X-Y ✓), A-D (X-Y ✓), B-C (X-Y ✓). No edge is within X or within Y.
Answer: Yes, bipartite with X = {A, B}, Y = {C, D}.
Practice Problems
A graph is a single cycle of length 6 (a hexagon). Is it bipartite?
5 applicants and 4 job openings are connected by an edge whenever an applicant is qualified for that job. What kind of graph models this, and why is it always bipartite regardless of which edges exist?
A graph has a triangle (3-cycle) A-B-C-A as a subgraph. Can the overall graph be bipartite?
Quiz
Summary
- A bipartite graph splits its vertices into two sets X, Y where every edge connects X to Y, never within a set.
- A graph is bipartite if and only if it contains no odd-length cycle — testable via a 2-coloring attempt with BFS/DFS.
- Bipartite structure is the natural model for matching problems: applicants-to-jobs, students-to-schools, tasks-to-workers.
References
- WebsiteWikipedia — Bipartite graph
Mathematics