The Havel–Hakimi algorithm is a method in graph theory used to determine whether a given finite sequence of non-negative integers can be represented as the degree sequence of a simple graph. Such a sequence is termed "graphical." The algorithm provides a constructive proof of the Erdős–Gallai theorem, which characterizes graphical sequences.
History The algorithm is named after mathematicians Václav Havel (1955) and S. Louis Hakimi (1962), who independently published the criterion. Havel's work appeared in Czech, while Hakimi's publication brought the result to wider attention in the English-language literature.
Algorithm Description Given a non-increasing sequence of non-negative integers $d_1 \ge d_2 \ge \dots \ge d_n$:
- If the sequence consists entirely of zeros, it is graphical. Terminate.
- If the sequence contains a negative number, or if $d_1 \ge n$ (a vertex cannot have more neighbors than the total number of other vertices), the sequence is not graphical. Terminate.
- Remove the first element $d_1$ from the sequence.
- Subtract 1 from the next $d_1$ elements in the remaining sequence.
- Re-sort the resulting sequence into non-increasing order.
- Return to step 1 with the new sequence.
Correctness The algorithm relies on the fact that a sequence $S$ is graphical if and only if the sequence $S'$ obtained by the reduction step (removing the maximum degree $d$ and subtracting 1 from the next $d$ degrees) is graphical. This corresponds to connecting the highest-degree vertex to the $d$ vertices with the next highest degrees in any realization of the graph.
Complexity A naive implementation sorting at each step runs in $O(n^2 \log n)$ time. Using efficient data structures (such as a priority queue or counting sort due to the bounded degree values), the complexity can be reduced to $O(n \log n)$ or $O(n + m)$ where $m$ is the sum of degrees.
Applications Beyond theoretical characterization, the algorithm is used in network modeling, the generation of random graphs with prescribed degree sequences (often as a basis for the configuration model), and the study of graph realizations.