Havel–Hakimi algorithm


The Havel–Hakimi algorithm is an algorithm in graph theory solving the graph realization problem. That is, it answers the following question: Given a finite list of nonnegative integers, is there a simple graph such that its degree sequence is exactly this list. Here, the "degree sequence" is a list of numbers that for each vertex of the graph states how many neighbors it has. For a positive answer the list of integers is called graphic. The algorithm constructs a special solution if one exists or proves that one cannot find a positive answer. This construction is based on a recursive algorithm. The algorithm was published by, and later by.

The algorithm

The algorithm is based on the following theorem.
Let be a finite list of nonnegative integers that is nonincreasing. List is graphic if and only if the finite list has nonnegative integers and is graphic.
If the given list is graphic then the theorem will be applied at most times setting in each further step. Note that it can be necessary to sort this list again. This process ends when the whole list consists of zeros. In each step of the algorithm one constructs the edges of a graph with vertices, i.e. if it is possible to reduce the list to, then we add edges. When the list cannot be reduced to a list of nonnegative integers in any step of this approach, the theorem proves that the list from the beginning is not graphic.