A Bit of History
Václav Havel established the reduction behind this algorithm in 1955, and S. Louis Hakimi independently published the same characterization in 1962. Their result answers a basic inverse problem: instead of reading degrees from a graph, start with desired degrees and ask whether any simple graph could have produced them.
The result is more than a yes-or-no theorem. If labels are retained during each reduction, the choices themselves construct a graph whose degree sequence is the input.
What Makes a Degree Sequence Graphical?
A finite sequence $(d_1,\ldots,d_n)$ is graphical if there exists a simple undirected graph on $n$ vertices whose vertex degrees are exactly those numbers. “Simple” imposes two constraints that shape the algorithm: no vertex can connect to itself, and no pair can receive more than one edge.
Labels are irrelevant for deciding graphicality but essential for construction. The sequences $(3,3,2,2,2)$ and any permutation of it pose the same decision problem; attaching labels $A,B,C,D,E$ lets us record which realization was built.
Fast Necessary Checks
Simple-graph range
No degree may be negative or exceed the number of other vertices.
Handshake parity
Every edge contributes two degree units, so an odd total is impossible.
Edge budget
A successful realization must contain exactly half the requested degree sum in edges.
These checks can reject many inputs immediately, but they are not sufficient. For example, $(3,3,1,1)$ stays within range and sums to $8$, yet it is not graphical. Havel–Hakimi detects the structural contradiction.
The Havel–Hakimi Reduction
Sort the sequence as $d_1\ge d_2\ge\cdots\ge d_n$. Then
$$ (d_1,d_2,\ldots,d_n)\text{ is graphical} $$
if and only if
$$ (d_2-1,\ldots,d_{d_1+1}-1,d_{d_1+2},\ldots,d_n)\text{ is graphical}. $$
- Sort by remaining degree. Keep original vertex labels attached.
- Remove the largest request $d$. That vertex must receive $d$ distinct neighbors.
- Choose the next $d$ vertices. Record those edges and subtract one from each chosen residual degree.
- Reject an impossible reduction. Fail if $d$ exceeds the number of remaining vertices or any chosen residual degree is already zero.
- Repeat. All zeros certify a realization; every recorded edge belongs to it.
Residual-degree interpretation: after each step, a number is not the vertex's final degree. It is how many more incident edges that vertex still needs.
Visual Walkthrough
Label the sequence $(3,3,2,2,2)$ as $A{:}3,B{:}3,C{:}2,D{:}2,E{:}2$. Ties are broken alphabetically only to make the trace deterministic.
The Constructed Graph Is a Certificate
The recorded edges can be checked independently: they contain no loops or duplicates, and the incident-edge count at every labeled vertex matches the requested degree. A valid edge list is therefore a compact certificate that the sequence is graphical.
Why Connecting to the Largest Degrees Is Safe
One direction is immediate: if the reduced sequence has a realization, add a new vertex and connect it to the $d_1$ decremented vertices. Their degrees return to the original values.
The other direction uses an edge-switching argument. Suppose the original sequence has some realization, but the highest-degree vertex $v$ is adjacent to a lower-degree vertex $y$ and not to a higher-or-equal-degree vertex $x$ that the greedy rule prefers. Because $x$ has at least as many neighbors as $y$, there is a vertex $z$ adjacent to $x$ but not to $y$. Replace edges $vy$ and $xz$ by $vx$ and $yz$. No loop or duplicate edge is created, and all four degrees stay unchanged.
Repeating this two-edge switch transforms a valid realization until $v$ is connected to the desired $d_1$ highest-degree vertices. Deleting $v$ then realizes exactly the reduced sequence. Thus the greedy reduction is equivalent to the original problem, not merely a heuristic.
Complexity Analysis
The straightforward implementations below sort up to $n$ residual vertices in each of up to $n$ rounds:
$$\text{Time: }O(n^2\log n) \qquad \text{Space: }O(n+m),$$
where $m=\tfrac12\sum_i d_i$ is the number of constructed edges. A heap-based constructive version performs roughly one update per edge and costs $O((n+m)\log n)$. Degree buckets can improve performance when degrees are bounded. If only the decision is needed, the Erdős–Gallai inequalities can be checked in $O(n\log n)$ time after sorting, or faster with specialized implementations.
Implementation
Each version returns a decision, a realizing edge list when successful, and a short diagnostic when unsuccessful. Input labels are original indices; sorting never loses their identity.
Related Degree-Sequence Tools
| Tool | Question | Output | Best use |
|---|---|---|---|
| Havel–Hakimi | Is an undirected simple sequence graphical? | Decision and a constructive realization | When actual edges or an intuitive reduction are useful |
| Erdős–Gallai | Do sorted degrees satisfy all graphicality inequalities? | Decision | Fast validation without constructing edges |
| Gale–Ryser | Can two degree lists form a simple bipartite graph? | Characterization and constructive variants | Bipartite row/column degree constraints |
| Configuration model | Can we generate a graph from degree “stubs”? | Usually a random multigraph | Network models where loops or parallel edges may be allowed or later repaired |
Directed graphs require separate in-degree and out-degree criteria, while bipartite graphs require two degree sequences. Do not silently apply the simple undirected theorem to either setting.
Where the Algorithm Helps
Input validation
Reject impossible degree specifications before graph generation or simulation begins.
Graph construction
Produce a concrete simple graph matching an exact undirected degree list.
Test fixtures
Build deterministic graphs with controlled degree profiles for algorithm tests.
Network science
Check whether an observed or synthetic distribution can be realized without loops or parallel edges.
Constructive proofs
Turn an existence claim into an independently verifiable edge-list certificate.
Sampling pipelines
Confirm graphicality before using edge-switching methods to explore other realizations.
Limitations and Common Pitfalls
| Mistake | Consequence | Defensive practice |
|---|---|---|
| Not re-sorting residual degrees | The next greedy step may target the wrong vertices. | Sort after every reduction or maintain an equivalent ordered structure. |
| Dropping original labels | The decision works, but constructed edges cannot be mapped back. | Store each residual degree together with its stable vertex ID. |
| Subtracting from $d$ arbitrary entries | A valid sequence can be rejected. | Subtract from the $d$ largest remaining residual degrees. |
| Accepting range and parity as sufficient | Sequences such as $(3,3,1,1)$ are misclassified. | Run the full reduction or Erdős–Gallai inequalities. |
| Mutating the caller's sequence | Later code sees residual rather than requested degrees. | Work on labeled copies, as the examples do. |
| Applying the theorem to directed or bipartite data | The wrong graphicality criterion is used. | Choose a criterion that matches the graph model. |
| Treating one realization as unique | Other valid structures are overlooked. | Use degree-preserving two-edge switches to explore alternatives. |
| Treating the greedy output as a uniform random sample | Simulation results inherit construction bias. | Use an appropriate sampling method after validation. |
Degrees Do Not Determine the Whole Graph
Graphs with the same degree sequence can have different connectivity, triangle counts, diameters, communities, and robustness. Havel–Hakimi satisfies the degree constraints; it does not optimize or randomize those other properties.
Exercises
Turn Reductions into Evidence
- Trace. Run Havel–Hakimi on $(4,3,3,2,2,2)$ with labels and list every chosen edge.
- Reject. Reduce $(3,3,1,1)$ until the first impossible step. Explain why the even-sum test did not catch it.
- Audit. Verify programmatically that the sample edge list is simple and reproduces every requested degree.
- Compare. Check the sample sequence with the Erdős–Gallai inequalities and connect each inequality to an edge-capacity intuition.
- Explore. Find two non-isomorphic realizations of the same degree sequence and transform one into the other using two-edge switches.
- Challenge. Implement the heap-based constructive version without allowing stale heap entries to create duplicate edges.
Hint for 5: if edges $ab$ and $cd$ exist while $ac$ and $bd$ do not, swapping the first pair for the second preserves all four degrees.