Hall violator

In graph theory, a Hall violator is a set of vertices in a graph, that violate the condition to Hall's marriage theorem.

Formally, given a bipartite graph $G = (X + Y, E)$, a Hall-violator in $X$ is a subset $W$ of $X$, for which $|N_{G}(W)| < |W|$, where $N_{G}(W)$ is the set of neighbors of $W$ in $G$.

If $W$ is a Hall violator, then there is no matching that saturates all vertices of $W$. Therefore, there is also no matching that saturates $X$. Hall's marriage theorem says that the opposite is also true: if there is no Hall violator, then there exists a matching that saturates $X$.

Finding a Hall violator
A Hall violator can be found by an efficient algorithm. The algorithm below uses the following terms:


 * An $M$-alternating path, for some matching $M$, is a path in which the first edge is not an edge of $M$, the second edge is of $M$, the third is not of $M$, etc.
 * A vertex $z$ is $M$-reachable from some vertex $x$, if there is an $M$-alternating path from $x$ to $z$.

As an example, consider the figure at the right, where the vertical (blue) edges denote the matching $M$. The vertex sets $Y_{1}, X_{1},Y_{2}, X_{2}$, are $M$-reachable from $x_{0}$ (or any other vertex of $X_{0}$), but $Y_{3}$ and $X_{3}$ are not $M$-reachable from $x_{0}$.

The algorithm for finding a Hall violator proceeds as follows.


 * 1) Find a maximum matching $M$ (it can be found with the Hopcroft–Karp algorithm).
 * 2) If all vertices of $X$ are matched, then return "There is no Hall violator".
 * 3) Otherwise, let $x_{0}$ be an unmatched vertex.
 * 4) Let $W$ be the set of all vertices of $X$ that are $M$-reachable from $x_{0}$ (it can be found using Breadth-first search; in the figure, $W$ contains $x_{0}$ and $X_{1}$ and $X_{2}$).
 * 5) Return $W$.

This $W$ is indeed a Hall-violator because of the following facts:


 * All vertices of $N_{G}(W)$ are matched by $M$. Suppose by contradiction that some vertex $y$ in $N_{G}(W)$ is unmatched by $M$. Let $x$ be its neighbor in $W$. The path from $x_{0}$ to $x$ to $y$ is an $M$-augmenting path - it is $M$-alternating and it starts and ends with unmatched vertices, so by "inverting" it we can increase $M$, contradicting its maximality.
 * $W$ contains all the matches of $N_{G}(W)$ by $M$. This is because all these matches are $M$-reachable from $x_{0}$.
 * $W$ contains another vertex - $x_{0}$ - that is unmatched by $M$ by definition.
 * Hence, $|W| = |N_{G}(W)| + 1 > |N_{G}(W)|$, so $W$ indeed satisfies the definition of a Hall violator.

Finding minimal and minimum Hall violators
An inclusion-minimal Hall violator is a Hall violator such that each of its subsets is not a Hall violator.

The above algorithm, in fact, finds an inclusion-minimal Hall violator. This is because, if any vertex is removed from $W$, then the remaining vertices can be perfectly matched to the vertices of $N_{G}(W)$ (either by edges of $M$, or by edges of the M-alternating path from $x_{0}$).

The above algorithm does not necessarily find a minimum-cardinality Hall violator. For example, in the above figure, it returns a Hall violator of size 5, while $X_{0}$ is a Hall violator of size 3.

In fact, finding a minimum-cardinality Hall violator is NP-hard. This can be proved by reduction from the Clique problem.

Finding a Hall violator or an augmenting path
The following algorithm takes as input an arbitrary matching $M$ in a graph, and a vertex $x_{0}$ in $X$ that is not saturated by $M$.

It returns as output, either a Hall violator that contains $x_{0}$, or a path that can be used to augment $M$.


 * 1) Set $k = 0$, $W_{k} := {x_{0}}$, $Z_{k} := {}$.
 * 2) Assert:
 * 3) * $W_{k} = {x_{0},...,x_{k}}$ where the $x_{i}$ are distinct vertices of $X$;
 * 4) * $Z_{k} = {y_{1},...,y_{k}}$ where the $y_{i}$ are distinct vertices of $Y$;
 * 5) * For all $i ≥ 1$, $y_{i}$ is matched to $x_{i}$ by $M$.
 * 6) * For all $i ≥ 1$, $y_{i}$ is connected to some $x_{j}_{ k = |Z_{k}| ≥ |N_{G}(W_{k})|$. Return the Hall-violator $W_{k}$.
 * 8) Otherwise, let $y_{k+1}$ be a vertex in $N_{G}(W_{k}) \ Z_{k}.$ Consider the following two cases:
 * 9) Case 1: $y_{k+1}$ is matched by $M$.
 * 10) * Since $x_{0}$ is unmatched, and every $x_{i}$ in $W_{k}$ is matched to $y_{i}$ in $Z_{k}$, the partner of this $y_{k+1}$ must be some vertex of $X$ that is not in $W_{k}$. Denote it by $x_{k+1}$.
 * 11) * Let $W_{k+1} := W_{k} U {x_{k+1}} |undefined$ and $Z_{k+1} := Z_{k} U {y_{k+1}} |undefined$ and $k := k + 1$.
 * 12) * Go back to step 2.
 * 13) Case 2: $y_{k+1}$ is unmatched by $M$.
 * 14) * Since $y_{k+1}$ is in $N_{G}(W_{k})$, it is connected to some $x_{i}$ (for $i < k + 1$) by an edge not in $M$. $x_{i}$ is connected to $y_{i}$ by an edge in $M$. $y_{i}$ is connected to some $x_{j}$ (for $j < i$) by an edge not in $M$, and so on. Following these connections must eventually lead to $x_{0}$, which is unmatched. Hence we have an M-augmenting path. Return the M-augmenting path.

At each iteration, $W_{k}$ and $Z_{k}$ grow by one vertex. Hence, the algorithm must finish after at most $|X|$ iterations.

The procedure can be used iteratively: start with $M$ being an empty matching, call the procedure again and again, until either a Hall violator is found, or the matching $M$ saturates all vertices of $X$. This provides a constructive proof to Hall's theorem.