3.5.17 · D5Graphs

Question bank — Bipartite graphs — 2-coloring test, bipartite matching — Hopcroft-Karp

1,325 words6 min readBack to topic

True or false — justify

A graph with no triangle is bipartite
False — any odd cycle blocks bipartiteness. The pentagon is triangle-free yet cannot be 2-colored, so "no triangle" is weaker than "no odd cycle".
Every tree is bipartite
True — a tree has no cycles at all, so certainly no odd cycle; you can 2-color it by parity of depth (see BFS / DFS traversal).
A graph is bipartite if and only if it has no odd-length cycle
True — this is the defining theorem. Even cycles alternate colors and close consistently; an odd cycle forces the start vertex to be both colors.
Adding one edge to a bipartite graph keeps it bipartite
False — an edge inside one side ( or ) creates a same-color edge, i.e. an odd cycle, breaking bipartiteness.
A disconnected graph can still be bipartite
True — bipartiteness is checked per component; if every component is 2-colorable the whole graph is bipartite (color each component independently).
The empty graph (vertices, no edges) is bipartite
True — with no edges there is no constraint to violate; you may put all vertices in and empty, and every edge (none) trivially crosses.
A maximum matching is unique for every bipartite graph
False — the size is unique, but many different edge sets can achieve it (e.g. a 4-cycle has two distinct perfect matchings).
Hopcroft–Karp always finds a perfect matching
False — it finds a maximum matching. If no perfect matching exists (e.g. more left vertices than can be covered), it returns the largest possible, which may leave vertices unmatched.
By König's theorem, max matching = min vertex cover in any graph
False — König's Theorem holds only for bipartite graphs. For general graphs min vertex cover can exceed max matching (a triangle has matching 1, cover 2).
Greedy matching (grab any free edge) can equal a maximum matching, sometimes
True — it sometimes does, but not reliably; greedy gives a maximal matching (no free edge addable) which can be strictly smaller than maximum.
The number of Hopcroft–Karp phases is at most about
True — the shortest augmenting-path length strictly increases each phase, and a counting argument bounds the total phases by .

Spot the error

"I ran one BFS from vertex 1 and colored everything reachable — the graph is bipartite."
Error: you only tested one component. You must loop over all uncolored vertices and restart BFS/DFS for each, or unreached components go unchecked.
"color[v] = color[u] whenever we cross edge (u,v)."
Error: the rule is (opposite). Copying the color would put same colors on an edge — the exact thing bipartiteness forbids.
"An augmenting path starts and ends at matched vertices."
Error: it starts and ends at unmatched (free) vertices; that's what lets a flip increase the matching by exactly one.
"To grow the matching I flip only the unmatched edges on the augmenting path."
Error: you flip every edge on the path — matched become unmatched and vice versa. Since there is one extra unmatched edge, the net gain is .
"Hopcroft–Karp finds every augmenting path in a single phase."
Error: one phase finds a maximal set of shortest, vertex-disjoint augmenting paths only. Longer paths are handled in later phases as the shortest length grows.
"Kuhn's algorithm and Hopcroft–Karp give different maximum matching sizes."
Error: both compute the same maximum size (guaranteed by Berge's Theorem); they only differ in speed — versus .
"A matching of size 3 that can't be extended by any single edge is maximum."
Error: that is maximal, not maximum. An augmenting path may re-route existing edges to reach size 4 without simply "adding" an edge.

Why questions

Why does an odd cycle make 2-coloring impossible?
Colors must alternate B,W,B,W,… along the cycle. Returning to the start after an odd number of steps demands the opposite of the start color, contradicting the start's own color.
Why must an augmenting path have odd length?
It alternates unmatched, matched, unmatched, … starting and ending with unmatched edges, so it has matched and unmatched edges — total , always odd.
Why does Hopcroft–Karp achieve instead of ?
It batches many shortest augmenting paths per phase, forcing the shortest length to strictly increase, which caps phases at ; each phase is one BFS+DFS sweep.
Why do we use BFS (not just DFS) at the start of each Hopcroft–Karp phase?
BFS builds the layered graph of shortest augmenting distances; DFS alone finds some path but not the shortest, losing the length-increase guarantee that gives the bound.
Why is bipartite matching easier than general matching?
Alternating paths never form odd "blossoms" in bipartite graphs, so plain BFS/DFS augmentation works; general graphs need the Blossom Algorithm to contract odd cycles.
Why can bipartite matching be solved with max-flow?
Add a source into and a sink out of , all capacities 1; an integer max flow saturates a maximum set of disjoint edges, which is exactly a maximum matching (see Maximum Flow).
Why does König's theorem let us read off a max independent set for free?
Because max independent set (max matching) in bipartite graphs; once Hopcroft–Karp gives the matching size, subtraction gives the answer instantly.

Edge cases

A single vertex with no edges — bipartite?
Yes — put it in (or ); with no edges there is nothing to violate. Its maximum matching is size 0.
A graph that is one long even cycle — bipartite?
Yes — even cycles alternate colors and close consistently. Its two color classes are the alternating vertices.
A self-loop (edge from a vertex to itself) — bipartite?
No — the loop's two endpoints are the same vertex, so it can never straddle and ; it acts like a length-1 odd cycle.
Two left vertices both connected only to one right vertex — maximum matching size?
Size 1 — the shared right vertex can be matched to at most one of them (matchings share no endpoints), leaving the other left vertex unmatched.
More left vertices than right vertices — can a perfect matching exist?
No — a perfect matching would need every vertex matched, but the smaller side runs out; the max matching size is capped by (and possibly less).
A graph where every left vertex has degree 0 — matching size?
Size 0 — with no edges there is nothing to match; Hopcroft–Karp's first BFS finds no augmenting path and stops immediately.
Comparing bipartite 2-coloring to general Graph Coloring — how many colors needed?
Exactly 2 if and only if the graph is bipartite (and has at least one edge); non-bipartite graphs need 3 or more, so 2-coloring is the special easy case.