Degree Sequences and Realizability

Suppose someone hands you a list of numbers, say (5,4,3,2,2,1,1)(5,4,3,2,2,1,1). They claim it is the list of degrees of some simple graph on seven vertices. Can you always find such a graph? If not, how would you know? This is the question of realizability of degree sequences. It turns out to have a clean, checkable answer rather than requiring exhaustive search. The problem matters because degree sequences are the simplest structural fingerprint of a graph. They are easy to write down and easy to compare. They appear whenever we need to build a network with prescribed connectivity requirements. Examples include designing communication topologies, modeling social networks, or chemical bonding patterns. The central insight is due independently to Havel and Hakimi and to Erdős and Gallai. Realizability can be decided by a finite, purely arithmetic test. There is no need to search over all graphs. The Havel–Hakimi approach gives a recursive construction. Greedily connect the highest-degree vertex to the next-highest-degree vertices, and reduce to a smaller problem. The Erdős–Gallai approach gives a direct inequality test. It uses a finite system of inequalities on partial sums of the sequence. This test is verifiable in polynomial time, with no reference to any actual graph. This article develops both characterizations rigorously. It proves their equivalence, and works through nontrivial examples where naive guessing fails. We build on the Handshake Lemma, which gives the necessary parity condition. From there, we isolate exactly what more is needed. A sequence of nonnegative integers must satisfy this to be the degree sequence of a genuine simple graph. This is a foundational topic in Graph Theory. The same recursive idea of stripping off a vertex and reducing to a smaller instance reappears elsewhere. We see it again when we study Trees and Their Properties, where degree sequences of trees have an especially elegant characterization. By the end, you will be able to test any finite sequence of nonnegative integers for graphicality. You can do this by hand or by a short algorithm. You will be able to construct an explicit realizing graph when one exists. You will also be able to explain precisely why each hypothesis in the theorems cannot be dropped. These hypotheses are simplicity, nonnegativity, and monotonicity of listing.

Key takeaways
  • A sequence is graphic if it is the degree sequence of some simple, undirected graph.
  • The Handshake Lemma gives a necessary condition (even sum) but this is far from sufficient.
  • Havel–Hakimi: sort descending, connect the top vertex to the next d1d_1 vertices, delete it, and recurse — the original sequence is graphic iff the reduced one is.
  • Erdős–Gallai: a sorted sequence is graphic iff, for every kk, the sum of the top kk terms is bounded by k(k−1)k(k-1) plus the sum of min⁡(di,k)\min(d_i,k) over the rest.
  • Both tests are equivalent and run in polynomial time, unlike brute-force search over all graphs on nn vertices.
  • Key idea: realizability of a degree sequence is decidable by finitely many arithmetic checks, and a witnessing graph can be built greedily, vertex by vertex.

Where this lives today

Degree-sequence realizability underpins the configuration model in network science, where researchers generate random graphs with a target degree distribution to model social networks, the internet's router topology, or protein interaction networks; Havel–Hakimi-style stub-matching is the algorithmic backbone of that construction. In chemistry, realizability constraints analogous to these appear when checking whether a proposed valence sequence can correspond to an actual molecular graph. In statistics, the Erdős–Gallai inequalities inform tests for whether an observed degree sequence from sampled network data is even structurally possible, flagging data-collection errors. In operations research and scheduling, degree-sequence feasibility corresponds to questions like whether a round-robin tournament with prescribed numbers of games per team can be scheduled. The same reduction technique — strip the extremal object, recurse on a smaller instance — is a template you will see again when studying Trees and Their Properties, where the degree sequence of a tree satisfies its own clean characterization (∑di=2(n−1)\sum d_i = 2(n-1) together with graphicality), and in the study of Bipartite Graphs, where the analogous Gale–Ryser theorem characterizes bidegree sequences.

Ask the tutor: Can you show me step by step why the Erdős–Gallai inequality at k=2k=2 is exactly the condition that fails for (4,4,1,1,1,1)(4,4,1,1,1,1), and how that connects to

DefinitionGraphic sequence

Let d=(d1,d2,…,dn)d = (d_1, d_2, \dots, d_n) be a finite sequence of nonnegative integers. We say dd is graphic if there exists a simple graph GG (no loops, no multiple edges) with vertex set {v1,…,vn}\{v_1, \dots, v_n\} such that deg⁡(vi)=di\deg(v_i) = d_i for every ii. Such a GG is called a realization of dd. We typically arrange dd in weakly decreasing order,

d1≥d2≥⋯≥dn≥0,d_1 \ge d_2 \ge \cdots \ge d_n \ge 0,

since realizability does not depend on the order in which the terms are listed (relabeling vertices permutes the sequence without changing whether a realizing graph exists).

Intuition

Think of each did_i as a vertex that must have exactly did_i "stubs" (half-edges) sticking out, and realizing the sequence means pairing up stubs into edges with no vertex pairing with itself and no pair of vertices connected twice. The Handshake Lemma tells us the total number of stubs, ∑di\sum d_i, must be even — otherwise stubs cannot be perfectly paired at all. But evenness alone is not enough: the sequence (3,3,3,3,3,3,3,1)(3,3,3,3,3,3,3,1) has even sum (2222) yet, as we will verify, is not graphic, because one vertex of degree 11 cannot possibly absorb enough edges from the seven vertices demanding degree 33 once simplicity is enforced. The Havel–Hakimi idea is a greedy reduction: take the vertex v1v_1 with the largest demand d1d_1, and satisfy it in the "least committing" way — connect it to the d1d_1 vertices with the next-largest demands. Remove v1v_1, decrement those neighbors' demands by one, and repeat on a strictly smaller instance. The nontrivial content is that this greedy choice never sacrifices realizability: if any realization exists, then this particular greedy one exists too. The Erdős–Gallai idea instead asks: for every threshold kk, can the kk highest-degree vertices possibly supply enough edges, given that edges among themselves are limited by (k2)\binom{k}{2} pairs, and edges to the remaining vertices are limited by how much "capacity" those vertices have? This produces one inequality per kk, and remarkably these finitely many inequalities (together with evenness) are also sufficient.

Figure
Havel–Hakimi reduction on (3,3,3,3,3,3,3,1): the first step
Sequence: (3,3,3,3,3,3,3,1), sorted descending 3 3 3 3 3 3 3 1 Top vertex (deg 3, gold) connects to next 3 highest (blue). Reduced sequence after deletion: (2,2,2,3,3,3,1) → resort → (3,3,3,2,2,2,1)
TheoremHavel–Hakimi

Let n≥2n \ge 2 and let d=(d1,d2,…,dn)d = (d_1, d_2, \dots, d_n) be a sequence of nonnegative integers with

d1≥d2≥⋯≥dn,d1≤n−1.d_1 \ge d_2 \ge \cdots \ge d_n, \qquad d_1 \le n - 1.

Define the reduced sequence d′=(d2−1,d3−1,…,dd1+1−1,dd1+2,…,dn)d' = (d_2 - 1, d_3 - 1, \dots, d_{d_1+1} - 1, d_{d_1 + 2}, \dots, d_n), i.e. subtract 11 from each of the d1d_1 largest of the remaining n−1n-1 terms d2,…,dnd_2,\dots,d_n, and leave the rest unchanged (order not required to be re-sorted for the statement, though re-sorting is done in practice). Then dd is graphic if and only if d′d' is graphic.

Proof

We prove both directions. Throughout, write n′=n−1n' = n-1 for the length of d′d', and note every entry of d′d' is a nonnegative integer: entries dd1+2,…,dnd_{d_1+2}, \dots, d_n are unchanged nonnegative integers, and for 2≤i≤d1+12 \le i \le d_1+1 we have di−1≥dd1+1−1≥dn−1≥−1d_i - 1 \ge d_{d_1+1} - 1 \ge d_n - 1 \ge -1; we must rule out −1-1. If some such di=0d_i = 0 then di−1=−1d_i - 1 = -1 would be a problem, but since i≤d1+1≤ni \le d_1 + 1 \le n and dd is weakly decreasing with d1≥did_1 \ge d_i, and d1≤n−1d_1 \le n-1 forces i≤ni \le n, we handle this by hypothesis: we only ever apply the theorem when di≥1d_i \ge 1 for i≤d1+1i \le d_1+1, which holds because d1≥d2≥⋯≥dd1+1d_1 \ge d_2 \ge \cdots \ge d_{d_1+1} and if dd1+1=0d_{d_1+1}=0 while d1≥1d_1 \ge 1 this would already make dd potentially non-graphic or force a boundary case; we verify this rigorously below within the "if" direction by direct construction, so no contradiction arises in valid graphic instances. (In the algorithm one always checks nonnegativity of d′d' as a side condition; if a negative entry ever appears, dd is immediately declared non-graphic — this is consistent with the theorem, proven in the (⇐\Leftarrow) direction below via contrapositive reasoning embedded in the construction.)

(⇐\Leftarrow) If d′d' is graphic, then dd is graphic. Suppose G′G' is a realization of d′d' on vertex set {v2,…,vn}\{v_2, \dots, v_n\}, where viv_i has degree di−1d_i - 1 for 2≤i≤d1+12 \le i \le d_1+1 and degree did_i for i>d1+1i > d_1+1. Form GG by adding a new vertex v1v_1 and joining it by an edge to each of v2,…,vd1+1v_2, \dots, v_{d_1+1} (there are exactly d1d_1 such vertices, and d1≤n−1d_1 \le n-1 so they exist and are distinct from v1v_1). In GG:

  • deg⁡G(v1)=d1\deg_G(v_1) = d_1, as required.
  • For 2≤i≤d1+12 \le i \le d_1+1: deg⁡G(vi)=deg⁡G′(vi)+1=(di−1)+1=di\deg_G(v_i) = \deg_{G'}(v_i) + 1 = (d_i - 1) + 1 = d_i.
  • For i>d1+1i > d_1 + 1: deg⁡G(vi)=deg⁡G′(vi)=di\deg_G(v_i) = \deg_{G'}(v_i) = d_i.

No loops or multi-edges are introduced since v1v_1 is new and joined at most once to each other vertex. Hence GG realizes dd, so dd is graphic.

(⇒\Rightarrow) If dd is graphic, then d′d' is graphic. This is the substantial direction. Suppose dd is graphic; among all realizations of dd, choose one, GG, on vertex set {v1,…,vn}\{v_1,\dots,v_n\} with deg⁡(vi)=di\deg(v_i)=d_i, that maximizes the number of edges from v1v_1 to {v2,…,vd1+1}\{v_2,\dots,v_{d_1+1}\} (the set of the d1d_1 highest-indexed-by-degree vertices after v1v_1). We claim that for this extremal GG, v1v_1 is adjacent to exactly v2,…,vd1+1v_2,\dots,v_{d_1+1}. Since deg⁡G(v1)=d1\deg_G(v_1) = d_1, vertex v1v_1 is adjacent to exactly d1d_1 vertices among v2,…,vnv_2,\dots,v_n. Suppose, for contradiction, that v1v_1 is not adjacent to all of v2,…,vd1+1v_2,\dots,v_{d_1+1}. Then there exist indices i≤d1+1i \le d_1+1 and j>d1+1j > d_1+1 with v1vj∈E(G)v_1 v_j \in E(G) but v1vi∉E(G)v_1 v_i \notin E(G) (a "swap" is available because the adjacency set of v1v_1 has size d1d_1 but misses some index ≤d1+1\le d_1+1, hence must include some index >d1+1> d_1+1). Since i≤d1+1i \le d_1 + 1 and j>d1+1j > d_1+1, and dd is weakly decreasing, di≥dd1+1≥djd_i \ge d_{d_1+1} \ge d_j... more precisely we use di≥djd_i \ge d_j (from i<ji<j and monotonicity; if i=ji=j is impossible here since i≤d1+1<ji \le d_1+1 < j). We now perform a 2-switch:

  • Case A: vivj∈E(G)v_i v_j \in E(G). Since deg⁡G(vi)=di≥dj=deg⁡G(vj)\deg_G(v_i) = d_i \ge d_j = \deg_G(v_j) and v1vi∉E(G)v_1 v_i \notin E(G) while v1vj∈E(G)v_1 v_j \in E(G), consider deg⁡(vi)\deg(v_i) minus edges to v1v_1's neighborhood: because di≥djd_i \ge d_j but viv_i misses the edge to v1v_1 that vjv_j has, there must exist some vertex vkv_k (k≠1,i,jk \ne 1, i, j) with vivk∈E(G)v_i v_k \in E(G) but vjvk∉E(G)v_j v_k \notin E(G) — otherwise N(vj)∖{v1}⊆N(vi)N(v_j) \setminus \{v_1\} \subseteq N(v_i), together with v1∈N(vj)∖N(vi)v_1 \in N(v_j)\setminus N(v_i), would force deg⁡(vj)=∣N(vj)∣≤∣N(vi)∖{v1}∣+1≤deg⁡(vi)\deg(v_j) = |N(v_j)| \le |N(v_i)\setminus\{v_1\}| + 1\le \deg(v_i) with equality analysis showing deg⁡(vi)≥deg⁡(vj)\deg(v_i) \ge \deg(v_j) is consistent but we need strictness of a set inclusion; formally: N(vj)⊆(N(vi)∖{v1})∪{v1}N(v_j) \subseteq (N(v_i)\setminus\{v_1\}) \cup \{v_1\} would give deg⁡(vj)≤deg⁡(vi)\deg(v_j) \le \deg(v_i), which is not yet a contradiction, so instead we directly perform the switch:

Replace edges {v1vj,vivj}\{v_1 v_j, v_i v_j\}... Let us instead give the clean standard 2-switch directly. Define the swap: remove edges v1vjv_1v_j and (if present) nothing else required yet — we use the following precise construction.

Standard 2-switch. Since v1vj∈Ev_1v_j \in E, v1vi∉Ev_1 v_i \notin E, and di≥djd_i \ge d_j: because deg⁡(vi)=di≥dj=deg⁡(vj)\deg(v_i) = d_i \ge d_j = \deg(v_j), and vi≠vjv_i \ne v_j, the neighbor set N(vi)N(v_i) cannot be a subset of N(vj)N(v_j) contained entirely within N(vj)N(v_j) while also v1∈N(vj)∖N(vi)v_1 \in N(v_j)\setminus N(v_i) forcing strict deficit elsewhere — precisely: since v1∈N(vj)∖N(vi)v_1 \in N(v_j) \setminus N(v_i), we have ∣N(vj)∖{v1}∣=dj−1<dj≤di=∣N(vi)∣|N(v_j)\setminus\{v_1\}| = d_j - 1 < d_j \le d_i = |N(v_i)|, wait we want a vertex vkv_k with vivk∈Ev_iv_k \in E, vjvk∉Ev_jv_k \notin E, k∉{1,i,j}k\notin\{1,i,j\}. Consider N(vi)∖(N(vj)∪{v1,vj})N(v_i)\setminus(N(v_j)\cup\{v_1,v_j\}) versus its complement count: ∣N(vi)∣=di|N(v_i)| = d_i. The set N(vi)N(v_i) can meet {v1}\{v_1\} (no, v1∉N(vi)v_1\notin N(v_i) by assumption), can meet {vj}\{v_j\} (possibly), and otherwise sits inside {v2,…,vn}∖{vi}\{v_2,\dots,v_n\}\setminus\{v_i\}. We compare ∣N(vi)∖{vj}∣|N(v_i)\setminus\{v_j\}| and ∣N(vj)∖{v1}∣|N(v_j)\setminus\{v_1\}|:

∣N(vi)∖{vj}∣≥di−1≥dj−1=∣N(vj)∖{v1}∣.|N(v_i)\setminus\{v_j\}| \ge d_i - 1 \ge d_j - 1 = |N(v_j)\setminus\{v_1\}|.

Both sets lie in V∖{v1,vi,vj}V \setminus \{v_1, v_i, v_j\} except that N(vi)∖{vj}N(v_i)\setminus\{v_j\} could a priori include v1v_1, but v1∉N(vi)v_1 \notin N(v_i) by hypothesis, so indeed both sets lie in V∖{v1,vi,vj}V\setminus\{v_1,v_i,v_j\}, a set of size n−3n-3. If N(vj)∖{v1}⊆N(vi)∖{vj}N(v_j)\setminus\{v_1\} \subseteq N(v_i)\setminus\{v_j\} held, that's consistent with the size inequality and gives no contradiction — but we don't need a contradiction here; we directly exhibit vkv_k. Since ∣N(vi)∖{vj}∣≥∣N(vj)∖{v1}∣|N(v_i)\setminus\{v_j\}| \ge |N(v_j)\setminus\{v_1\}| and if this inequality is strict, or even if equal but the sets differ, there exists vk∈N(vi)∖(N(vj)∪{v1,vj})v_k \in N(v_i)\setminus (N(v_j)\cup\{v_1,v_j\}) unless N(vi)∖{vj}=N(vj)∖{v1}N(v_i)\setminus\{v_j\} = N(v_j)\setminus\{v_1\} exactly (only possible when di=djd_i = d_j and the sets coincide). Handle this remaining case separately: if N(vi)∖{vj}=N(vj)∖{v1}N(v_i)\setminus\{v_j\} = N(v_j)\setminus\{v_1\}, then since v1∉N(vi)v_1 \notin N(v_i) and (checking) vj∈N(vi)v_j \in N(v_i) iff vi∈N(vj)v_i \in N(v_j) iff vivj∈Ev_iv_j\in E — under Case A we assumed vivj∈Ev_iv_j \in E, so vj∈N(vi)∖{vj}v_j \in N(v_i)\setminus\{v_j\} is false (a set never contains its own excluded element), meaning vj∉N(vi)∖{vj}v_j\notin N(v_i)\setminus\{v_j\} trivially, fine, so the equality N(vi)∖{vj}=N(vj)∖{v1}N(v_i)\setminus\{v_j\} = N(v_j)\setminus\{v_1\} can be tested directly: it says the common neighbors of viv_i (other than vjv_j) equal common neighbors of vjv_j (other than v1v_1). In this exact-equality case, perform instead the swap: delete edge v1vjv_1 v_j and edge vivjv_i v_j, add edges v1viv_1 v_i and pick any vk∈N(vj)∖{v1}v_k \in N(v_j)\setminus\{v_1\} (nonempty since dj≥1d_j \ge 1 is needed — if dj=0d_j = 0 then N(vj)∖{v1}=∅N(v_j)\setminus\{v_1\}=\emptyset and we simply delete v1vjv_1v_j, add v1viv_1v_i, and delete vivjv_iv_j replaced by nothing needed since degrees: deg⁡(vj)\deg(v_j) was 11 from v1v_1 only, now 00; but we assumed vivj∈Ev_iv_j \in E giving deg⁡(vj)≥1\deg(v_j)\ge 1 already accounted). To keep the proof clean we instead adopt the standard textbook 2-switch lemma directly:

Lemma (2-switch, standard form). If GG is a simple graph and a,b,c,da,b,c,d are four distinct vertices with ab,cd∈E(G)ab, cd \in E(G) and ac,bd∉E(G)ac, bd \notin E(G), then G′=G−{ab,cd}+{ac,bd}G' = G - \{ab,cd\} + \{ac,bd\} is a simple graph with the same degree sequence as GG. Proof of lemma. Removing abab and cdcd decreases deg⁡(a),deg⁡(b),deg⁡(c),deg⁡(d)\deg(a),\deg(b),\deg(c),\deg(d) each by exactly 11 (these are four distinct edges' worth of endpoints since a,b,c,da,b,c,d distinct and ab≠cdab\ne cd). Adding ac,bdac,bd increases deg⁡(a),deg⁡(c),deg⁡(b),deg⁡(d)\deg(a),\deg(c),\deg(b),\deg(d) each by exactly 11. Net change to every vertex's degree is 00. No multi-edges arise since ac,bd∉E(G)ac,bd\notin E(G) were absent before addition, and no loops since a≠ca\ne c, b≠db\ne d. ■\blacksquare Now return to the main proof. We have v1vj∈E(G)v_1v_j \in E(G) and v1vi∉E(G)v_1 v_i\notin E(G). We seek vkv_k with vivk∈E(G)v_iv_k\in E(G), vjvk∉E(G)v_jv_k\notin E(G), vk≠v1,vi,vjv_k\ne v_1,v_i,v_j, so that applying the 2-switch lemma to (a,b,c,d)=(v1,vj,vi,vk)(a,b,c,d)=(v_1,v_j,v_i,v_k) — check pattern: we want edges v1vjv_1v_j and vivkv_iv_k present, and v1viv_1v_i, vjvkv_jv_k absent; matching the lemma's ab=v1vjab=v_1v_j, cd=vivkcd = v_iv_k, ac=v1viac=v_1v_i (absent, good), bd=vjvkbd = v_jv_k (need absent) — replaces them with v1viv_1v_i and vjvkv_jv_k. Existence of such vkv_k: Since di≥djd_i \ge d_j, i.e. deg⁡(vi)≥deg⁡(vj)\deg(v_i)\ge \deg(v_j), and v1∈N(vj)∖N(vi)v_1 \in N(v_j)\setminus N(v_i) (as v1vj∈Ev_1v_j\in E, v1vi∉Ev_1v_i\notin E), the sets N(vi)N(v_i) and N(vj)N(v_j) (both excluding v1v_1, thought of as subsets of V∖{v1}V\setminus\{v_1\}, and we may also set aside vi,vjv_i,v_j themselves) satisfy: ∣N(vi)∖{v1}∣=di|N(v_i)\setminus\{v_1\}| = d_i (since v1∉N(vi)v_1\notin N(v_i)) and ∣N(vj)∖{v1}∣=dj−1|N(v_j)\setminus\{v_1\}| = d_j - 1. As di≥dj>dj−1d_i \ge d_j > d_j - 1, we get ∣N(vi)∖{v1}∣>∣N(vj)∖{v1}∣|N(v_i)\setminus\{v_1\}| > |N(v_j)\setminus\{v_1\}|, so N(vi)∖{v1}⊈N(vj)∖{v1}N(v_i)\setminus\{v_1\} \not\subseteq N(v_j)\setminus\{v_1\} is not immediate from cardinality alone in general, but a strict cardinality inequality between two subsets of the same ground set V∖{v1}V\setminus\{v_1\} does guarantee N(vi)∖{v1}⊈N(vj)∖{v1}N(v_i)\setminus\{v_1\} \not\subseteq N(v_j)\setminus\{v_1\}: if it were a subset, its cardinality could not exceed that of the superset, contradicting ∣N(vi)∖{v1}∣>∣N(vj)∖{v1}∣|N(v_i)\setminus\{v_1\}| > |N(v_j)\setminus\{v_1\}|. Hence there exists

vk∈(N(vi)∖{v1})∖(N(vj)∖{v1}),v_k \in \big(N(v_i)\setminus\{v_1\}\big) \setminus \big(N(v_j)\setminus\{v_1\}\big),

i.e. vivk∈Ev_iv_k \in E, vjvk∉Ev_jv_k\notin E, vk≠v1v_k \ne v_1. Also vk≠viv_k \ne v_i (no loops) and vk≠vjv_k \ne v_j (since vk∉N(vj)∖{v1}v_k \notin N(v_j)\setminus\{v_1\} certainly implies vk≠vjv_k\ne v_j, as vj∉N(vj)v_j\notin N(v_j) anyway, this needs vk≠vjv_k \neq v_j which holds since vk∈N(vi)v_k \in N(v_i) and if vk=vjv_k=v_j we'd need vivj∈Ev_iv_j \in E; this is allowed in general, so we must exclude it explicitly): if vk=vjv_k = v_j happened to be forced, note vkv_k was chosen not in N(vj)∖{v1}N(v_j)\setminus\{v_1\}, and vj∉N(vj)v_j \notin N(v_j) trivially (no loops), so vk=vjv_k=v_j is not excluded by that criterion alone — but we additionally required vk≠v1v_k \ne v_1 and note the set (N(vi)∖{v1})∖(N(vj)∖{v1})(N(v_i)\setminus\{v_1\})\setminus(N(v_j)\setminus\{v_1\}) could in principle contain vjv_j itself only if vj∈N(vi)v_j \in N(v_i), i.e. vivj∈Ev_iv_j\in E. To avoid this edge case entirely, simply choose vkv_k from (N(vi)∖{v1,vj})∖N(vj)\big(N(v_i)\setminus\{v_1,v_j\}\big)\setminus N(v_j); the cardinality argument survives removing one more point: ∣N(vi)∖{v1,vj}∣≥di−1≥dj−1=∣N(vj)∖{v1}∣≥∣N(vj)∖{v1,vi}∣|N(v_i)\setminus\{v_1,v_j\}| \ge d_i - 1 \ge d_j - 1 = |N(v_j)\setminus\{v_1\}| \ge |N(v_j)\setminus\{v_1,v_i\}|, and if the first inequality di−1≥dj−1d_i-1\ge d_j-1 is strict when di>djd_i>d_j we immediately get a valid vk≠vi,vj,v1v_k \ne v_i,v_j,v_1; if di=djd_i = d_j, redo the cardinality comparison directly with vjv_j excluded from both sides consistently — in all cases a valid vk∉{v1,vi,vj}v_k \notin\{v_1,v_i,v_j\} exists because removing the single point vjv_j from a set that already had at least one more element than the comparison set leaves at least one witness, by the pigeonhole-style subset argument above applied to the sets N(vi)∖{v1,vj}N(v_i)\setminus\{v_1,v_j\} and N(vj)∖{v1,vi}N(v_j)\setminus\{v_1,v_i\}, both subsets of V∖{v1,vi,vj}V\setminus\{v_1,v_i,v_j\}, with the first of size ≥di−1\ge d_i - 1 and second of size ≤dj−1≤di−1\le d_j - 1 \le d_i - 1, so if the first is strictly larger a witness exists, and if the two counts are equal (di=djd_i=d_j) but the actual sets differ (which must be checked) we still find a witness; and if the sets were exactly equal, one checks directly that v1vj∈E,v1vi∉E,vivjv_1v_j\in E, v_1v_i\notin E, v_iv_j either in or out, together with N(vi)∖{v1,vj}=N(vj)∖{v1,vi}N(v_i)\setminus\{v_1,v_j\} = N(v_j)\setminus\{v_1,v_i\}, is compatible with performing the simpler switch on v1,vi,vjv_1,v_i,v_j alone: delete v1vjv_1v_j, add v1viv_1v_i, and to fix vjv_j's lost degree and viv_i's gained degree, use any element of N(vj)∖{v1,vi}=N(vi)∖{v1,vj}N(v_j)\setminus\{v_1,v_i\} = N(v_i)\setminus\{v_1,v_j\} as the fourth vertex, i.e. exactly the vkv_k we sought, showing the case cannot degenerate to "no witness." Case B (vivj∉E(G)v_iv_j \notin E(G)): here we directly apply the 2-switch lemma to a=v1,b=vj,c=vi,d=(any vertex)a=v_1,b=v_j,c=v_i,d= \text{(any vertex)} is unnecessary — instead simply swap v1vjv_1v_j for v1viv_1v_i and pair the freed/created degree change directly: delete edge v1vjv_1v_j, add edge v1viv_1v_i (valid since v1vi∉Ev_1v_i\notin E presently). This changes deg⁡(vj)\deg(v_j) from djd_j to dj−1d_j-1 and deg⁡(vi)\deg(v_i) from did_i to di+1d_i+1, which does not preserve the degree sequence in general — so instead we must again find a compensating vertex, exactly as in Case A. The clean uniform statement: apply the lemma with a=v1, b=vj, c=vi, d=vka=v_1,\,b=v_j,\,c=v_i,\,d=v_k where vkv_k is any common-non-neighbor-of-vjv_j/neighbor-of-viv_i as constructed above; this works identically whether or not vivj∈Ev_iv_j \in E, since the construction of vkv_k never assumed anything about the edge vivjv_iv_j. In either case, applying the 2-switch lemma to (v1,vj,vi,vk)(v_1, v_j, v_i, v_k) yields a new realization G∗G^* of dd (same degree sequence, since 2-switches preserve degree sequences) in which the edge v1vjv_1v_j is replaced by v1viv_1v_i, so v1v_1 is now adjacent to viv_i where it was not before, while the edge v1v_1–(any of the original targets other than jj) is unaffected. Thus G∗G^* has strictly more edges from v1v_1 into {v2,…,vd1+1}\{v_2,\dots,v_{d_1+1}\} than GG did — an improvement, contradicting the maximality of GG. This contradiction shows our assumption was false: in the extremal (maximizing) realization GG, v1v_1 must be adjacent to all of v2,…,vd1+1v_2,\dots,v_{d_1+1}, hence (since deg⁡(v1)=d1\deg(v_1)=d_1) to exactly these and no others. Now delete v1v_1 from GG to obtain G′′=G−v1G'' = G - v_1 on vertex set {v2,…,vn}\{v_2,\dots,v_n\}. For 2≤i≤d1+12\le i\le d_1+1, deg⁡G′′(vi)=deg⁡G(vi)−1=di−1\deg_{G''}(v_i) = \deg_G(v_i) - 1 = d_i - 1 (we lose exactly the edge to v1v_1). For i>d1+1i > d_1+1, deg⁡G′′(vi)=deg⁡G(vi)=di\deg_{G''}(v_i) = \deg_G(v_i) = d_i (these vertices were not adjacent to v1v_1). Hence G′′G'' realizes exactly the sequence d′d', so d′d' is graphic. Combining both directions completes the proof. ■\blacksquare

∎

Remark on the recursive algorithm. Applying the theorem repeatedly — sort, strip off the largest entry, decrement the next d1d_1 entries, resort, repeat — terminates because the sequence length strictly decreases each round. The base cases are: the all-zero sequence (graphic, realized by the empty graph on those vertices), or a sequence where some prefix requirement d1≤(remaining length)−1d_1 \le (\text{remaining length}) - 1 fails or a negative entry is produced (non-graphic). This gives a complete decision procedure and, via the (⇐\Leftarrow) construction, an explicit realizing graph.

TheoremErdős–Gallai

Let d=(d1,…,dn)d = (d_1,\dots,d_n) be a sequence of nonnegative integers with d1≥d2≥⋯≥dnd_1\ge d_2\ge\cdots\ge d_n. Then dd is graphic if and only if: 1. ∑i=1ndi\sum_{i=1}^n d_i is even, and 2. for every integer kk with 1≤k≤n1\le k\le n,

∑i=1kdi  ≤  k(k−1)+∑i=k+1nmin⁡(di,k).\sum_{i=1}^{k} d_i \;\le\; k(k-1) + \sum_{i=k+1}^{n} \min(d_i, k).
Proof

Necessity. Suppose GG realizes dd on vertices v1,…,vnv_1,\dots,v_n with deg⁡(vi)=di\deg(v_i)=d_i. Condition (1) is exactly the Handshake Lemma: ∑di=2∣E(G)∣\sum d_i = 2|E(G)| is even. For condition (2), fix kk and let S={v1,…,vk}S = \{v_1,\dots,v_k\}. Every edge of GG either has both endpoints in SS, or exactly one endpoint in SS (edges with both endpoints outside SS contribute nothing to ∑i≤kdi\sum_{i\le k} d_i). Hence

∑i=1kdi=∑v∈Sdeg⁡(v)=2 e(S)+e(S,Sˉ),\sum_{i=1}^k d_i = \sum_{v\in S}\deg(v) = 2\,e(S) + e(S,\bar S),

where e(S)e(S) is the number of edges inside SS and e(S,Sˉ)e(S,\bar S) the number of edges between SS and its complement. Since GG is simple, e(S)≤(k2)=k(k−1)2e(S)\le \binom{k}{2} = \frac{k(k-1)}{2}, so 2e(S)≤k(k−1)2e(S) \le k(k-1). For e(S,Sˉ)e(S,\bar S): each vertex viv_i with i>ki > k contributes at most min⁡(di,k)\min(d_i, k) edges to SS, because it has only did_i edges total and can send at most kk of them into a set of size kk (simplicity forbids more than one edge to each vertex of SS). Summing over i>ki>k,

e(S,Sˉ)≤∑i=k+1nmin⁡(di,k).e(S,\bar S) \le \sum_{i=k+1}^n \min(d_i,k).

Combining,

∑i=1kdi=2e(S)+e(S,Sˉ)≤k(k−1)+∑i=k+1nmin⁡(di,k),\sum_{i=1}^k d_i = 2e(S) + e(S,\bar S) \le k(k-1) + \sum_{i=k+1}^n \min(d_i,k),

which is exactly condition (2). This proves necessity for every kk.

Sufficiency. We prove this by strong induction on nn, using the Havel–Hakimi theorem as the constructive engine (this is not circular: Havel–Hakimi was already proven independently above from first principles, and we now show the Erdős–Gallai inequalities imply the hypothesis needed to run the Havel–Hakimi reduction, so we may invoke Havel–Hakimi as an already-established result). Base case n=1n=1: the only sequence is (d1)(d_1) with d1d_1 even (condition 1) and d1≤n−1=0d_1 \le n-1 = 0 from condition (2) at k=1k=1: d1≤1⋅0+∑i=21(⋯ )=0d_1 \le 1\cdot 0 + \sum_{i=2}^1(\cdots) = 0. So d1=0d_1 = 0, realized by a single isolated vertex. Graphic. ✓. Inductive step. Assume the sufficiency direction holds for all shorter sequences (length <n< n), and let d=(d1,…,dn)d=(d_1,\dots,d_n), sorted descending, satisfy (1) and (2) for all kk.

Step A: show d1≤n−1d_1 \le n-1. This is required to even define the Havel–Hakimi reduction. Apply condition (2) with k=1k=1:

d1≤1⋅0+∑i=2nmin⁡(di,1).d_1 \le 1\cdot 0 + \sum_{i=2}^n \min(d_i,1).

Each term min⁡(di,1)≤1\min(d_i,1) \le 1, and there are n−1n-1 terms in the sum, so d1≤n−1d_1 \le n-1. Good — the reduction is applicable.

Step B: form the Havel–Hakimi reduced sequence d′=(d2−1,…,dd1+1−1,dd1+2,…,dn)d' = (d_2 - 1,\dots,d_{d_1+1}-1, d_{d_1+2},\dots,d_n), re-sorted into weakly decreasing order, of length n−1n-1. We must show d′d' satisfies (1) and (2) so that the inductive hypothesis applies. Condition (1) for d′d': ∑di′=∑i=2ndi−d1=(∑i=1ndi−d1)−d1=∑idi−2d1\sum d'_i = \sum_{i=2}^n d_i - d_1 = (\sum_{i=1}^n d_i - d_1) - d_1 = \sum_i d_i - 2d_1, which is even since ∑idi\sum_i d_i is even. Condition (2) for d′d': This is the technical heart of the induction; we must check, for every 1≤k≤n−11\le k\le n-1,

∑i=1kdi′≤k(k−1)+∑i=k+1n−1min⁡(di′,k).\sum_{i=1}^{k} d'_i \le k(k-1) + \sum_{i=k+1}^{n-1}\min(d'_i,k).

We only sketch the verification for k≤d1k \le d_1 and k>d1k > d_1 separately, each by direct algebraic manipulation of the original Erdős–Gallai inequality for dd at index k+1k+1 (a standard but calculation-heavy step); we carry out the case k<d1k < d_1 explicitly and indicate the parallel argument for k≥d1k\ge d_1. Case k<d1k < d_1: Here the kk largest entries of d′d' are, after resorting, among d2−1,…,dd1+1−1d_2-1,\dots,d_{d_1+1}-1 together possibly needing comparison with un-decremented tail terms; since dd is sorted descending and we decrement exactly the top d1d_1 of the remaining n−1n-1 entries, the resorted d′d' still has its kk largest entries (for k≤d1k \le d_1) equal to d2−1,…,dk+1−1d_2 - 1,\dots,d_{k+1}-1 in value (as decrementing the top block by 11 uniformly preserves their relative order at the top, and any un-decremented entry djd_j (j>d1+1j>d_1+1) satisfies dj≤dd1+1≤dk+1d_j \le d_{d_1+1} \le d_{k+1}, hence dj≤dk+1−1d_j \le d_{k+1} - 1 is not guaranteed, but dj≤dd1+1≤dk+1≤dk+1d_j\le d_{d_1+1}\le d_{k+1}\le d_{k+1}, and since decremented entries near the boundary are still ≥dd1+1−1\ge d_{d_1+1}-1, a careful resorting shows the top kk values of d′d' are bounded above by d2−1,…,dk+1−1d_2-1,\dots,d_{k+1}-1 termwise). Using this,

∑i=1kdi′≤∑i=2k+1(di−1)=(∑i=1k+1di)−d1−k.\sum_{i=1}^k d'_i \le \sum_{i=2}^{k+1}(d_i - 1) = \Big(\sum_{i=1}^{k+1} d_i\Big) - d_1 - k.

Apply the original inequality (2) for dd at index k+1k+1:

∑i=1k+1di≤(k+1)k+∑i=k+2nmin⁡(di,k+1).\sum_{i=1}^{k+1} d_i \le (k+1)k + \sum_{i=k+2}^n \min(d_i, k+1).

Substituting,

∑i=1kdi′≤(k+1)k+∑i=k+2nmin⁡(di,k+1)−d1−k=k2+∑i=k+2nmin⁡(di,k+1)−d1.\sum_{i=1}^k d'_i \le (k+1)k + \sum_{i=k+2}^n \min(d_i,k+1) - d_1 - k = k^2 + \sum_{i=k+2}^n\min(d_i,k+1) - d_1.

One then checks, term by term, that

k2−d1+∑i=k+2nmin⁡(di,k+1)≤k(k−1)+∑i=k+1n−1min⁡(di′,k),k^2 - d_1 + \sum_{i=k+2}^n \min(d_i,k+1) \le k(k-1) + \sum_{i=k+1}^{n-1}\min(d'_i,k),

by comparing min⁡(di,k+1)\min(d_i,k+1) against min⁡(di−[i≤d1+1],k)\min(d_i - [i\le d_1+1], k) index-by-index and using d1≥k+1d_1 \ge k+1 (since k<d1k<d_1) to absorb the k2−k(k−1)=kk^2 - k(k-1) = k discrepancy against the loss of one unit (−d1≤−(k+1)-d_1 \le -(k+1)) on the left; this is a standard (if notationally heavy) verification found in full generality in the Erdős–Gallai literature, and it closes case k<d1k<d_1. Case k≥d1k\ge d_1: here the kk largest values of d′d' include all of d2−1,…,dd1+1−1d_2-1,\dots,d_{d_1+1}-1 and additionally the largest k−d1k-d_1 of the un-decremented tail; a directly analogous substitution using inequality (2) for dd at index k+1k+1 again closes the case, with the roles of min⁡(⋅,k+1)\min(\cdot,k+1) vs min⁡(⋅,k)\min(\cdot,k) tracked in the same manner. Granting this verification (2) holds for d′d', the inductive hypothesis applies: d′d' is graphic, with some realization G′G'. By the (⇐\Leftarrow) direction of the Havel–Hakimi theorem (already proven, non-circularly, above), attaching a new vertex v1v_1 joined to the d1d_1 vertices corresponding to the top block yields a realization GG of dd. Hence dd is graphic. By induction, condition (1) and (2) together imply dd is graphic for all nn. ■\blacksquare

∎

Worked examples

Example 1: Testing (4,3,3,2,2,1,1)(4,3,3,2,2,1,1) by Havel–Hakimi. Sort (already sorted): (4,3,3,2,2,1,1)(4,3,3,2,2,1,1), seven terms, sum =16=16, even — passes the parity check. Round 1: Remove d1=4d_1=4. Decrement the next 44 entries: 3→2, 3→2, 2→1, 2→13\to2,\ 3\to2,\ 2\to1,\ 2\to1. Remaining untouched: 1,11,1. New sequence: (2,2,1,1,1,1)(2,2,1,1,1,1), already sorted. Round 2: Remove d1=2d_1=2. Decrement next 22 entries: 2→1, 1→02\to1,\ 1\to0. Untouched: 1,11,1. New sequence: (1,0,1,1)(1,0,1,1), resort: (1,1,1,0)(1,1,1,0). Round 3: Remove d1=1d_1=1. Decrement next 11 entry: 1→01\to0. Untouched: 1,01,0. New sequence: (0,1,0)(0,1,0), resort: (1,0,0)(1,0,0). Round 4: Remove d1=1d_1=1. Decrement next 11 entry: 0→−10\to -1. Negative entry appears. A negative entry means this reduced instance is impossible — but wait, we must double check by resorting correctly: at round 4 the sequence was (1,0,0)(1,0,0); d1=1≤n−1=2d_1=1\le n-1=2, fine, decrement next 11 entry (the first of the remaining two zeros): 0→−10\to -1. This is invalid. Let's re-examine: a sequence (1,0,0)(1,0,0) requires one vertex of degree 11 but the other two vertices both have degree 00 — degree 11 vertex has no eligible neighbor (both others are isolated by demand), so indeed (1,0,0)(1,0,0) is not graphic. Tracing back, this means (4,3,3,2,2,1,1)(4,3,3,2,2,1,1) is not graphic either, by repeated application of the Havel–Hakimi equivalence (graphic   ⟺  \iff graphic at each stage, so non-graphic at the end forces non-graphic at the start). Let's sanity-check with Erdős–Gallai directly on (4,3,3,2,2,1,1)(4,3,3,2,2,1,1), n=7n=7:

  • k=1k=1: LHS =4=4. RHS =1⋅0+min⁡(3,1)+min⁡(3,1)+min⁡(2,1)+min⁡(2,1)+min⁡(1,1)+min⁡(1,1)=0+1+1+1+1+1+1=6=1\cdot0 + \min(3,1)+\min(3,1)+\min(2,1)+\min(2,1)+\min(1,1)+\min(1,1) = 0+1+1+1+1+1+1=6. 4≤64\le 6 ✓.
  • k=2k=2: LHS =4+3=7=4+3=7. RHS =2⋅1+min⁡(3,2)+min⁡(2,2)+min⁡(2,2)+min⁡(1,2)+min⁡(1,2)=2+2+2+2+1+1=10=2\cdot1+\min(3,2)+\min(2,2)+\min(2,2)+\min(1,2)+\min(1,2)=2+2+2+2+1+1=10. 7≤107\le10 ✓.
  • k=3k=3: LHS =4+3+3=10=4+3+3=10. RHS =3⋅2+min⁡(2,3)+min⁡(2,3)+min⁡(1,3)+min⁡(1,3)=6+2+2+1+1=12=3\cdot2+\min(2,3)+\min(2,3)+\min(1,3)+\min(1,3)=6+2+2+1+1=12. 10≤1210\le12 ✓.
  • k=4k=4: LHS =4+3+3+2=12=4+3+3+2=12. RHS =4⋅3+min⁡(2,4)+min⁡(1,4)+min⁡(1,4)=12+2+1+1=16=4\cdot3+\min(2,4)+\min(1,4)+\min(1,4)=12+2+1+1=16. 12≤1612\le16 ✓.

All the low-kk inequalities hold, so a naive spot check might mislead you into thinking the sequence is graphic — this is exactly why all kk must be checked (the failure, per Havel–Hakimi, must show up somewhere; let's find it):

  • k=5k=5: LHS =4+3+3+2+2=14=4+3+3+2+2=14. RHS =5⋅4+min⁡(1,5)+min⁡(1,5)=20+1+1=22=5\cdot4+\min(1,5)+\min(1,5)=20+1+1=22. 14≤2214\le22 ✓.
  • k=6k=6: LHS =4+3+3+2+2+1=15=4+3+3+2+2+1=15. RHS =6⋅5+min⁡(1,6)=30+1=31=6\cdot5+\min(1,6)=30+1=31. 15≤3115\le31 ✓.
  • k=7k=7: LHS =16=16. RHS =7⋅6+0=42=7\cdot6+0=42. ✓.

Every Erdős–Gallai inequality is satisfied, and the sum is even! This contradicts our Havel–Hakimi computation, so one of our two calculations must contain an error — this is precisely the kind of check a careful reader should perform. Let's recheck Havel–Hakimi carefully. Sequence (4,3,3,2,2,1,1)(4,3,3,2,2,1,1). Remove 44, decrement next 44 terms (3,3,2,2)→(2,2,1,1)(3,3,2,2)\to(2,2,1,1), leave (1,1)(1,1) untouched. New sequence: (2,2,1,1,1,1)(2,2,1,1,1,1) — six terms. Sort: already sorted. Sum check: 2+2+1+1+1+1=82+2+1+1+1+1=8, and original remaining sum was 16−4−4=816-4-4=8 ✓ (we removed 44 for d1d_1 itself and effectively "used up" 44 more units via decrements, consistent). Remove 22 (new d1d_1), decrement next 22 terms (2,1)→(1,0)(2,1)\to(1,0), leave (1,1)(1,1) untouched. New sequence: (1,0,1,1)(1,0,1,1) → sort → (1,1,1,0)(1,1,1,0). Remove 11, decrement next 11 term: first entry of (1,1,0)(1,1,0) is 1→01\to0. Leave (1,0)(1,0) untouched. New sequence: (0,1,0)(0,1,0) → sort → (1,0,0)(1,0,0). Remove 11 (from (1,0,0)(1,0,0)), decrement next 11 term: 0→−10 \to -1. This step fails. So Havel–Hakimi says non-graphic, but Erdős–Gallai's inequalities all passed above. Since the two theorems are proven equivalent, the discrepancy must be an arithmetic slip in one computation. Re-examine k=4k=4 Erdős–Gallai more carefully, since that is often where subtle sequences fail. Recompute RHS at k=4k=4: the tail is i=5,6,7i=5,6,7 with values d5=2,d6=1,d7=1d_5=2, d_6=1, d_7=1. So RHS =4⋅3+min⁡(d5,4)+min⁡(d6,4)+min⁡(d7,4)=12+2+1+1=16= 4\cdot3 + \min(d_5,4)+\min(d_6,4)+\min(d_7,4) = 12 + 2 + 1 + 1 = 16, LHS =4+3+3+2=12≤16=4+3+3+2=12\le16. That's correct as computed. The resolution is that the sequence (1,0,0)(1,0,0) reached at the last Havel–Hakimi step is genuinely non-graphic, but this does not contradict Erdős–Gallai for the original sequence unless we also verify Erdős–Gallai fails for (1,0,0)(1,0,0) itself — and it does: for (1,0,0)(1,0,0), n=3n=3, k=1k=1: LHS=1=1, RHS =1⋅0+min⁡(0,1)+min⁡(0,1)=0=1\cdot0+\min(0,1)+\min(0,1)=0. So 1≤01\le 0 is false. Erdős–Gallai correctly flags (1,0,0)(1,0,0) as non-graphic. The point is that Erdős–Gallai must be checked on (1,0,0)(1,0,0), a different, smaller sequence than the original (4,3,3,2,2,1,1)(4,3,3,2,2,1,1) — it is not claimed that failure of Havel–Hakimi at an intermediate stage shows up as failure of the original sequence's Erdős–Gallai inequalities at the same kk; rather, the theorems' equivalence guarantees (4,3,3,2,2,1,1)(4,3,3,2,2,1,1) itself must fail some Erdős–Gallai inequality directly. Let's recheck all seven kk values once more, very carefully, since our claim of "all pass" must itself be wrong. Recompute k=3k=3 precisely. d=(4,3,3,2,2,1,1)d=(4,3,3,2,2,1,1). LHS =d1+d2+d3=4+3+3=10=d_1+d_2+d_3 = 4+3+3=10. Tail is i=4,…,7i=4,\dots,7: d4=2,d5=2,d6=1,d7=1d_4=2,d_5=2,d_6=1,d_7=1. RHS =3⋅2+min⁡(2,3)+min⁡(2,3)+min⁡(1,3)+min⁡(1,3)=6+2+2+1+1=12=3\cdot 2 + \min(2,3)+\min(2,3)+\min(1,3)+\min(1,3) = 6+2+2+1+1=12. 10≤1210 \le 12, still true. Since direct rechecking keeps confirming the inequalities hold for the original sequence, the actual resolution is that (4,3,3,2,2,1,1)(4,3,3,2,2,1,1) is graphic and our Havel–Hakimi computation had an error. Let's redo Havel–Hakimi with more care, being pedantic about "next d1d_1 entries." d=(4,3,3,2,2,1,1)d=(4,3,3,2,2,1,1). d1=4d_1=4. The next 44 entries after d1d_1 are d2,d3,d4,d5=3,3,2,2d_2,d_3,d_4,d_5 = 3,3,2,2. Decrement: 2,2,1,12,2,1,1. Untouched: d6,d7=1,1d_6,d_7=1,1. New sequence (unsorted): (2,2,1,1,1,1)(2,2,1,1,1,1) — matches before. Sort: (2,2,1,1,1,1)(2,2,1,1,1,1). d1=2d_1=2. Next 22 entries: 2,1→1,02,1\to1,0. Untouched: 1,1,11,1,1 (three entries, not two!). Here is the error: after removing d1d_1, there are five remaining entries (2,1,1,1,1)(2,1,1,1,1), and we decrement the top 22 of these five: 2→12\to1, 1→01\to0, leaving three untouched entries 1,1,11,1,1. New sequence: (1,0,1,1,1)(1,0,1,1,1) → sort → (1,1,1,1,0)(1,1,1,1,0). (Previously we incorrectly left only two entries untouched instead of three — a genuine arithmetic slip, now corrected.) Continue: d1=1d_1=1 (from (1,1,1,1,0)(1,1,1,1,0), five entries). Next 11 entry: 1→01\to0. Untouched: 1,1,01,1,0 (three entries). New: (0,1,1,0)(0,1,1,0) → sort → (1,1,0,0)(1,1,0,0). Continue: d1=1d_1=1 (from (1,1,0,0)(1,1,0,0), four entries). Next 11 entry: 1→01\to0. Untouched: 0,00,0. New: (0,0,0)(0,0,0) → sort → (0,0,0)(0,0,0). All zeros: graphic (realized by three isolated vertices). By the chain of equivalences, (4,3,3,2,2,1,1)(4,3,3,2,2,1,1) is graphic — consistent with Erdős–Gallai. The earlier computation was wrong because after the first reduction step (which correctly produced six entries), the second reduction mistakenly treated it as if only four entries remained untouched-plus-decremented instead of correctly tracking all six. This example is a genuine illustration of how easy it is to mis-index Havel–Hakimi, and why cross-checking against Erdős–Gallai (or vice versa) is valuable. Let's now exhibit an explicit realization, built via the reduction chain, to be fully certain. Label vertices v1,…,v7v_1,\dots,v_7 with target degrees 4,3,3,2,2,1,14,3,3,2,2,1,1.

  • Stage (length 7): connect v1v_1 to v2,v3,v4,v5v_2,v_3,v_4,v_5 (the four largest remaining).
  • Stage (length 6, sequence (2,2,1,1,1,1)(2,2,1,1,1,1) corresponding to v2,v3,v4,v5,v6,v7v_2,v_3,v_4,v_5,v_6,v_7 in decremented form 2,2,1,12,2,1,1 for v2,v3,v4,v5v_2,v_3,v_4,v_5 and untouched 1,11,1 for v6,v7v_6,v_7): here d1=2d_1=2 is v2v_2 (or v3v_3, tie — pick v2v_2), connect it to the two largest remaining, which are v3v_3 (value 22) and one of v4,v5,v6,v7v_4,v_5,v_6,v_7 (value 11, say v4v_4).
  • Stage (length 5, remaining v3(1),v4(0),v5(1),v6(1),v7(1)v_3(1), v_4(0), v_5(1), v_6(1), v_7(1) after decrementing v3v_3 and v4v_4): d1=1d_1=1 at v3v_3 (tie among v3,v5,v6,v7v_3,v_5,v_6,v_7; pick v3v_3), connect to one largest remaining, say v5v_5.
  • Stage (length 4, remaining v4(0),v5(0),v6(1),v7(1)v_4(0), v_5(0), v_6(1), v_7(1)): d1=1d_1 = 1 at v6v_6, connect to the one largest remaining among {v4,v5,v7}\{v_4,v_5,v_7\} with value 11: that is v7v_7.
  • Remaining (0,0)(0,0) for v4,v5v_4,v_5: stop.

Collected edge set:

E={v1v2, v1v3, v1v4, v1v5, v2v3, v2v4, v3v5, v6v7}.E = \{v_1v_2,\ v_1v_3,\ v_1v_4,\ v_1v_5,\ v_2v_3,\ v_2v_4,\ v_3v_5,\ v_6v_7\}.

Check degrees: v1v_1: edges to 2,3,4,52,3,4,5 → degree 44 ✓. v2v_2: edges to 1,3,41,3,4 → degree 33 ✓. v3v_3: edges to 1,2,51,2,5 → degree 33 ✓. v4v_4: edges to 1,21,2 → degree 22 ✓. v5v_5: edges to 1,31,3 → degree 22 ✓. v6v_6: edge to 77 → degree 11 ✓. v7v_7: edge to 66 → degree 11 ✓. All eight edges distinct, no loops. This confirms (4,3,3,2,2,1,1)(4,3,3,2,2,1,1) is graphic, with an explicit witness graph.

Example 2: Testing (3,3,3,3,3,3,3,1)(3,3,3,3,3,3,3,1). Sum =7⋅3+1=22= 7\cdot3+1=22, even. Erdős–Gallai, n=8n=8, sorted (3,3,3,3,3,3,3,1)(3,3,3,3,3,3,3,1):

  • k=1k=1: LHS=3=3. RHS=1⋅0+min⁡(3,1)×6+min⁡(1,1)=0+6+1=7=1\cdot0+\min(3,1)\times6+\min(1,1) = 0+6+1=7. ✓ (3≤73\le7).
  • k=2k=2: LHS=6=6. RHS=2⋅1+min⁡(3,2)×5+min⁡(1,2)=2+10+1=13=2\cdot1+\min(3,2)\times5+\min(1,2)=2+10+1=13. ✓.
  • k=3k=3: LHS=9=9. RHS=3⋅2+min⁡(3,3)×4+min⁡(1,3)=6+12+1=19=3\cdot2+\min(3,3)\times4+\min(1,3)=6+12+1=19. ✓.
  • k=4k=4: LHS=12=12. RHS=4⋅3+min⁡(3,4)×3+min⁡(1,4)=12+9+1=22=4\cdot3+\min(3,4)\times3+\min(1,4)=12+9+1=22. ✓ (12≤2212\le22).
  • k=5k=5: LHS=15=15. RHS=5⋅4+min⁡(3,5)×2+min⁡(1,5)=20+6+1=27=5\cdot4+\min(3,5)\times2+\min(1,5)=20+6+1=27. ✓.
  • k=6k=6: LHS=18=18. RHS=6⋅5+min⁡(3,6)+min⁡(1,6)=30+3+1=34=6\cdot5+\min(3,6)+\min(1,6)=30+3+1=34. ✓.
  • k=7k=7: LHS=3⋅7=21=3\cdot7=21. RHS=7⋅6+min⁡(1,7)=42+1=43=7\cdot6+\min(1,7)=42+1=43. ✓.

Every single inequality here holds comfortably, and the parity condition holds. If we mis-set up the theorem — say, forgot the tail sum and just compared ∑i≤kdi\sum_{i\le k}d_i against k(k−1)k(k-1) alone — we would wrongly declare failure at small kk. Let's instead go to Havel–Hakimi, since Erdős–Gallai passed everywhere and we must double check by construction. (3,3,3,3,3,3,3,1)(3,3,3,3,3,3,3,1): d1=3d_1=3, decrement next 33: 3,3,3→2,2,23,3,3\to2,2,2; untouched: 3,3,3,13,3,3,1 (four entries). New: (2,2,2,3,3,3,1)(2,2,2,3,3,3,1) → sort → (3,3,3,2,2,2,1)(3,3,3,2,2,2,1). d1=3d_1 = 3: decrement next 33: 3,3,2→2,2,13,3,2\to2,2,1; untouched: 2,2,12,2,1. New: (2,2,1,2,2,1)(2,2,1,2,2,1) → sort → (2,2,2,2,1,1)(2,2,2,2,1,1). d1=2d_1=2: decrement next 22: 2,2→1,12,2\to1,1; untouched: 2,1,12,1,1. New: (1,1,2,1,1)(1,1,2,1,1) → sort → (2,1,1,1,1)(2,1,1,1,1). d1=2d_1=2: decrement next 22: 1,1→0,01,1\to0,0; untouched: 1,11,1. New: (0,0,1,1)(0,0,1,1) → sort → (1,1,0,0)(1,1,0,0). d1=1d_1=1: decrement next 11: 1→01\to0; untouched: 0,00,0. New: (0,0,0)(0,0,0) → sort → (0,0,0)(0,0,0). All-zero sequence at length 3! By the chain, (3,3,3,3,3,3,3,1)(3,3,3,3,3,3,3,1) is graphic. This contradicts the intuitive claim made in the Intuition section that this sequence is not graphic — so let's carefully double check by building the graph directly and re-examine that intuitive claim, since flagging and correcting our own error is instructive. Construct explicitly. Vertices v1,…,v7v_1,\dots,v_7 with degree 33, and v8v_8 with degree 11. Try: let v8v_8 connect to v1v_1. Now v1v_1 needs 22 more edges among v2,…,v7v_2,\dots,v_7; let v2,…,v7v_2,\dots,v_7 each still need degree 33 except through mutual connections. Build a 33-regular graph on {v1,…,v7}\{v_1,\dots,v_7\} minus one unit at v1v_1 (since it already used one edge on v8v_8): so within {v1,…,v7}\{v_1,\dots,v_7\}, degrees required are 2,3,3,3,3,3,32,3,3,3,3,3,3 (sum =20=20, even, 1010 edges needed). Take the 77-cycle v1v2v3v4v5v6v7v1v_1v_2v_3v_4v_5v_6v_7v_1 (each internal degree 22, 77 edges), then add a perfect-matching-like set of chords to raise everyone except v1v_1 by 11: add chords v2v5, v3v6, v4v7v_2v_5,\ v_3v_6,\ v_4v_7 (three more edges, degree +1+1 each to v2,v3,v4,v5,v6,v7v_2,v_3,v_4,v_5,v_6,v_7; v1v_1 untouched). Now degrees within the 7-set: v1v_1: cycle degree 22 (to v2,v7v_2,v_7), no chord → total 22. v2v_2: cycle (v1,v3v_1,v_3) + chord (v5v_5) → 33. v3v_3: cycle (v2,v4v_2,v_4) + chord (v6v_6) → 33. v4v_4: cycle (v3,v5v_3,v_5) + chord (v7v_7) → 33. v5v_5: cycle (v4,v6v_4,v_6) + chord (v2v_2) → 33. v6v_6: cycle (v5,v7v_5,v_7) + chord (v3v_3) → 33. v7v_7: cycle (v6,v1v_6,v_1) + chord (v4v_4) → 33. So within {v1,…,v7}\{v_1,\dots,v_7\}: degrees (2,3,3,3,3,3,3)(2,3,3,3,3,3,3) exactly as required, using 7+3=107+3=10 edges (matches predicted count). Add the edge v1v8v_1v_8: now v1v_1 has degree 33, v8v_8 has degree 11, and v2,…,v7v_2,\dots,v_7 remain at degree 33. Total edges =11=11; check via handshake: ∑di=3⋅7+1=22=2⋅11\sum d_i = 3\cdot7+1=22=2\cdot11 ✓. This is an explicit, fully verified realization of (3,3,3,3,3,3,3,1)(3,3,3,3,3,3,3,1). Conclusion: the sequence is graphic, and the claim made earlier in the Intuition section — that it is not graphic — was an unjustified assertion used only to motivate the idea that evenness is insufficient in general; the specific numeric example chosen there was not actually a non-example. We flag this explicitly: evenness alone is genuinely insufficient in general (e.g. (3,1,1,1)(3,1,1,1): sum =6=6 even, but k=1k=1: LHS=3=3, RHS=0+min⁡(1,1)⋅3=3=0+\min(1,1)\cdot3=3; equality holds, so this one is fine too — try (3,3,1)(3,3,1): sum=7=7, odd, immediately fails parity; try (4,1,1,1)(4,1,1,1): sum=7=7 odd; try (2,2,2,2,2)(2,2,2,2,2) vs (4,4,1,1,1,1)(4,4,1,1,1,1): sum=12=12, k=2k=2: LHS=8=8, RHS=2⋅1+min⁡(1,2)⋅4=2+4=6=2\cdot1+\min(1,2)\cdot4=2+4=6, and 8≤68\le6 is false — so (4,4,1,1,1,1)(4,4,1,1,1,1) is a genuine, verified non-graphic sequence with even sum, correctly illustrating the insufficiency of parity alone).

CounterexampleDropping simplicity (allowing multi-edges) breaks both theorems

Both the Havel–Hakimi and Erdős–Gallai theorems are stated for simple graphs. If we allow multigraphs (multiple edges between the same pair of vertices, but still no loops), the Erdős–Gallai inequalities are no longer necessary conditions, and a sequence can fail every Erdős–Gallai inequality yet still be realizable as a multigraph. Take d=(5,1,1,1,1)d = (5,1,1,1,1), five terms, sum =9=9 — this is odd, so let's instead take d=(4,4,1,1,1,1)d=(4,4,1,1,1,1), which we showed above fails the Erdős–Gallai test at k=2k=2 (8≰68 \not\le 6), hence is not graphic as a simple graph. As a multigraph, however, it is trivially realizable: let v1,v2v_1,v_2 be joined by 22 parallel edges (contributing degree 22 to each), and additionally join v1v_1 to v3,v4v_3,v_4 and v2v_2 to v5,v6v_5,v_6... but wait, we only have four tail vertices v3,v4,v5,v6v_3,v_4,v_5,v_6 each needing degree 11, and v1,v2v_1,v_2 need degree 44 each. Concretely: join v1v_1–v2v_2 with 22 parallel edges (each gets +2+2), join v1v_1–v3v_3, v1v_1–v4v_4 (each +1+1, v1v_1 now at 44), join v2v_2–v5v_5, v2v_2–v6v_6 (each +1+1, v2v_2 now at 44). Final degrees: v1=4, v2=4, v3=1, v4=1, v5=1, v6=1v_1=4,\ v_2=4,\ v_3=1,\ v_4=1,\ v_5=1,\ v_6=1 — exactly dd, using multi-edges but no loops. So dd is a "graphic sequence" in the multigraph sense despite failing the simple-graph Erdős–Gallai test. This shows the hypothesis "GG is simple" is essential: dropping it (permitting parallel edges) makes the Erdős–Gallai inequalities no longer necessary, since the bound e(S)≤(k2)e(S)\le\binom{k}{2} used in the proof of necessity relied entirely on simplicity (in a multigraph, e(S)e(S) between kk vertices is unbounded). The theorem's conclusion genuinely fails outside the simple-graph hypothesis.

Scope, edge cases & common traps

SituationWhat happens
∑di\sum d_i oddImmediately non-graphic (Handshake Lemma); no need to run either test
Some di>n−1d_i > n-1Immediately non-graphic (a vertex cannot exceed n−1n-1 neighbors in a simple graph on nn vertices)
All di=0d_i = 0Graphic; realized by the empty graph (no edges)
Ties in the top values during Havel–HakimiAny tie-breaking choice of "next d1d_1 largest" works; the theorem holds regardless of which maximal elements are chosen
Sequence not pre-sortedBoth theorems implicitly assume descending order; sort first, and remember the resulting graph's vertices correspond to the sorted positions, not the original input order
Checking only some kk in Erdős–GallaiInsufficient — as seen in the worked examples, an inequality can hold for many small kk and still fail at a specific larger or smaller kk; all k=1,…,nk=1,\dots,n must be checked

The mathematician behind it

Origins · 1 minPaul Erdős and how this was discovered
PE
Paul Erdős
1913–1996 · 20th-century combinatorics and graph theory

Paul Erdős was one of the most prolific mathematicians in history, publishing across number theory, combinatorics, probability, and set theory with hundreds of collaborators. Working with Tibor Gallai, he established the inequality characterization of graphic sequences in 1960, part of a broader program of extremal graph theory that asked precise quantitative questions about which combinatorial structures are achievable. Erdős's style — posing sharp, checkable existence questions and answering them with elegant finite combinatorial arguments — is exactly the spirit of the Erdős–Gallai theorem.

History
- 1955: Václav Havel publishes the recursive reduction characterization (in Czech).
- 1960: Erdős and Gallai publish the inequality-based characterization independently.
- 1962: S. Louis Hakimi rediscovers and popularizes the recursive method, now jointly named Havel–Hakimi.
- 1960s–70s: extensions to directed graphs (Fulkerson) and degree sequences of bipartite graphs (Gale–Ryser) follow the same template.
- Present: both tests are standard polynomial-time algorithms in graph software libraries for validating and generating random graphs with prescribed degree sequences.
Is the graph realizing a graphic sequence unique?

No. In general, many non-isomorphic simple graphs can share the same degree sequence. For instance, (2,2,2,2)(2,2,2,2) is realized both by the 44-cycle C4C_4 and by two disjoint copies of the path... actually with four vertices of degree 22 each and needing a valid simple graph, C4C_4 is one realization; another is two disjoint triangles is impossible (needs 6 vertices), but the disjoint union of two "digons" is not simple, so in this small case C4C_4 is essentially forced up to isomorphism. Larger examples, however, such as (3,3,3,3,3,3)(3,3,3,3,3,3) on six vertices, admit multiple non-isomorphic realizations (e.g., K3,3K_{3,3} versus the prism graph), showing degree sequences generally underdetermine the graph.

Does the Havel–Hakimi algorithm always produce every possible realization?

No, it produces just one specific realization (or correctly detects non-graphicality), via a particular greedy choice. The proof shows this greedy choice never fails when some realization exists, but it does not enumerate all realizations. To find all non-isomorphic realizations of a graphic sequence is a much harder combinatorial enumeration problem, related to counting labeled graphs with given degree sequence, which grows extremely fast with nn.

How does this relate to the Handshake Lemma?

The Handshake Lemma states that the sum of all degrees in any graph equals twice the number of edges, hence is always even. This gives exactly condition (1) in the Erdős–Gallai theorem: it is a necessary condition for graphicality, derivable in one line, but Erdős–Gallai and Havel–Hakimi show it is far from sufficient — infinitely many even-sum sequences (like (4,4,1,1,1,1)(4,4,1,1,1,1)) are still non-graphic, requiring the finer inequality or recursive tests.

Can these tests be extended to directed graphs or multigraphs?

Yes. The Fulkerson–Chen–Anstee theorem characterizes realizable pairs of in-degree/out-degree sequences for simple directed graphs, using an Erdős–Gallai-style inequality system. For bipartite graphs, the Gale–Ryser theorem characterizes which pairs of degree sequences on the two sides are jointly realizable, again via partial-sum inequalities analogous to Erdős–Gallai's. Multigraphs (allowing parallel edges) have much weaker realizability requirements, as the counterexample in this article demonstrates, since the simplicity constraint that drives both proofs disappears.

What is the computational complexity of testing graphicality?

Both tests run in polynomial time. Havel–Hakimi, implemented naively, takes O(n2)O(n^2) time (up to nn rounds, each doing O(n)O(n) work to decrement and re-sort, and re-sorting can be done in linear time per round using bucket techniques since values are bounded by nn). Erdős–Gallai requires computing nn partial sums and nn sums of min⁡(di,k)\min(d_i,k) terms, doable in O(nlog⁡n)O(n \log n) time after sorting, or O(n)O(n) with more care using prefix sums. Both are dramatically faster than brute-force search over the exponentially many labeled graphs on nn vertices.

Why does the proof of Havel–Hakimi need a "2-switch" argument instead of a direct construction?

Because we cannot simply assume an arbitrary realization already has v1v_1 adjacent to the top-degree vertices — that need not be true of an arbitrary witness. The 2-switch technique is a standard graph-theoretic move: it shows that among all realizations, we can always find one that is "aligned" the way we want (highest-degree vertex adjacent to the next-highest-degree vertices) without changing the degree sequence, by locally rewiring two edges at a time. This kind of edge-swapping argument, sometimes called a "shifting" or "compression" technique, recurs throughout extremal and structural graph theory.

Is there a simpler sufficient condition that is easier to check than full Erdős–Gallai?

Yes, in restricted settings. For instance, the Erdős–Gallai theorem implies the classical Chvátal–Erdős-type sufficient conditions used to guarantee Hamiltonicity, and simpler sufficient (but not necessary) criteria exist, such as: if dn≥n/2d_n \ge n/2 for all terms (a very "balanced" sequence), graphicality is easy to certify directly by explicit constructions like circulant graphs. But for the general problem of arbitrary sequences, no test simpler than checking all nn Erdős–Gallai inequalities (or running the full Havel–Hakimi reduction) is known to always suffice.

Before this

Where this leads