Skip to main content

9.1 Graph Formalisms, Degree Sequences & the Handshaking Lemma

πŸ“šModule 09: Graph Theory Foundations, Paths & ConnectivityTopic 9.1: Graph Formalisms & Degrees⏱️5 min read
🎯High-Yield For:Semester Exams β€’ GATE CSE β€’ Technical Interviews

πŸ’‘ Core Intuition: The 3-Second Mental Model​

🍳 The Everyday Analogy: The Cocktail Party & Highway Bridges​

Think of graphs as mathematical blueprints of relationships between entities:

  1. The Handshaking Principle: Imagine entering a room with nn guests. When two guests shake hands, one single handshake adds 2 to the total count of handshakes given (1 to Person A's tally, and 1 to Person B's tally).
    • If 10 handshakes take place in the room, the sum of all individual handshakes recorded is exactly 2Γ—10=202 \times 10 = 20.
    • Because every handshake contributes 2 to the global tally, the sum of all degrees across the universe is always an even number!
    • Consequently, the number of guests who shook an odd number of hands must be an even number!
  2. Simple Graphs vs Multigraphs:
    • Simple Graph: At most one direct flight between any two cities, and no flight that takes off and immediately lands at the exact same airport (no self-loops).
    • Multigraph: Multiple competing airlines flying between the same pair of cities (parallel edges).
  3. The Havel-Hakimi Test: A group of people claim: "I have 3 friends, she has 3, he has 3, they have 1." Is that network physically possible, or are they lying? Havel-Hakimi recursively strips the highest degree to test whether a degree sequence can actually form a simple graph!

πŸ’» Bridging to Computer Science: Networks, Social Graphs & Compilers​

In computer systems:

  • Computer Networks: Routers are vertices; fiber-optic cables are edges. Degree represents port bandwidth and network resilience.
  • Social Networks (LinkedIn / Facebook): Users are vertices; bidirectional friendships form undirected edges; unidirectional follow relationships form directed edges.
  • Compiler Register Allocation: Program variables are vertices; interference (overlapping live ranges) forms edges. The graph is colored to assign variables to physical CPU registers.

πŸ•ΈοΈ Formal Graph Taxonomy & Combinatorial Counting​

πŸ“–Definition 9.1: Formal Graph Definitiondefinition

A Graph G=(V,E)G = (V, E) consists of:

  1. A non-empty set V=V(G)V = V(G) whose elements are called vertices (or nodes).
  2. A set E=E(G)E = E(G) whose elements are called edges (or links), where each edge e∈Ee \in E is associated with an unordered pair {u,v}\{u, v\} (for undirected graphs) or an ordered pair (u,v)(u, v) (for directed graphs) of vertices from VV.
  • Order of GG: The number of vertices: n=∣V∣n = |V|.
  • Size of GG: The number of edges: m=∣E∣m = |E|.
  • Null Graph (NnN_n): A graph containing nn vertices and 00 edges (∣E∣=0|E| = 0).
  • Trivial Graph (K1K_1): A graph with exactly 11 vertex and 00 edges.

The Spectrum of Graph Topologies

Classifying graphs based on directionality, edge duplication, and self-loops

🌐

Simple Graph

Standard Model
  • Undirected edges.
  • NO self-loops (no edge connecting a vertex to itself).
  • NO multiple / parallel edges (at most one edge between any pair).
  • Maximum possible edges: C(n, 2) = n(n - 1) / 2.
πŸ”€

Multigraph

Parallel Channels
  • Allows multiple edges connecting the exact same pair of vertices.
  • Models redundant network links or multi-lane highways.
  • Zero self-loops allowed.
πŸ”„

Pseudograph

Loops Allowed
  • Allows both parallel edges AND self-loops (edges from v to v).
  • A self-loop contributes 2 to the degree of its incident vertex!
➑️

Directed Graph (Digraph)

Asymmetric Flow
  • Edges are ordered pairs e = (u, v) with a designated direction.
  • u is the initial vertex (source); v is the terminal vertex (target).

πŸ”’ Combinatorial Counting of Labeled Simple Graphs​

πŸ“Theorem 9.1: Counting Labeled Graphstheorem

Let VV be a set of nn labeled vertices:

  1. Total Number of Potential Edges: N=(n2)=n(nβˆ’1)2N = \binom{n}{2} = \frac{n(n - 1)}{2}
  2. Total Number of Labeled Simple Graphs: Every potential edge {u,v}\{u, v\} can either be present or absent (2 independent binary choices): TotalΒ Graphs=2N=2(n2)\text{Total Graphs} = 2^N = 2^{\binom{n}{2}}
  3. Number of Labeled Simple Graphs with exactly ee edges: Choosing ee edges out of the (n2)\binom{n}{2} available slots: Count(n,e)=((n2)e)\text{Count}(n, e) = \binom{\binom{n}{2}}{e}

πŸ”’ Vertex Degrees & The Handshaking Lemma​

πŸ“–Definition 9.2: Degree of a Vertexdefinition

Let G=(V,E)G = (V, E) be an undirected graph, and let v∈Vv \in V:

  1. The degree of vertex vv (denoted deg⁑(v)\deg(v) or d(v)d(v)) is the number of edges incident with vv. Each self-loop counts as two incident edges.
  2. Isolated Vertex: A vertex with degree 00 (deg⁑(v)=0\deg(v) = 0).
  3. Pendant (Leaf) Vertex: A vertex with degree 11 (deg⁑(v)=1\deg(v) = 1).
  4. Minimum and Maximum Degrees: Ξ΄(G)=min⁑v∈Vdeg⁑(v),Ξ”(G)=max⁑v∈Vdeg⁑(v)\delta(G) = \min_{v \in V} \deg(v), \qquad \Delta(G) = \max_{v \in V} \deg(v)
  5. For a directed graph:
    • In-Degree (degβ‘βˆ’(v)\deg^-(v)): Number of edges terminating at vv.
    • Out-Degree (deg⁑+(v)\deg^+(v)): Number of edges originating from vv.
πŸ“Theorem 9.2: The Handshaking Lemma (Euler's First Theorem)theorem

In any undirected graph G=(V,E)G = (V, E):

βˆ‘v∈Vdeg⁑(v)=2∣E∣\sum_{v \in V} \deg(v) = 2 |E|

Proof: Every edge e={u,v}e = \{u, v\} has two distinct endpoints (uu and vv). When summing the degrees of all vertices across the graph, each edge is counted exactly twice: once at vertex uu and once at vertex vv. (A self-loop at uu contributes 2 to deg⁑(u)\deg(u), again contributing 2 to the sum). Therefore, the sum of all vertex degrees must equal exactly twice the number of edges.

Directed Graph Analogue:

βˆ‘v∈Vdegβ‘βˆ’(v)=βˆ‘v∈Vdeg⁑+(v)=∣E∣\sum_{v \in V} \deg^-(v) = \sum_{v \in V} \deg^+(v) = |E|

Average Degree Inequality: The average vertex degree is davg=2∣E∣nd_{\text{avg}} = \frac{2|E|}{n}. Consequently:

Ξ΄(G)≀2∣E∣n≀Δ(G)\delta(G) \le \frac{2|E|}{n} \le \Delta(G)
πŸ“Theorem 9.3: The Odd-Degree Vertex Parity Theoremtheorem

In any undirected graph, the number of vertices of odd degree is ALWAYS EVEN!

Proof: Partition the vertex set VV into two disjoint subsets:

  • VevenV_{\text{even}}: The set of vertices with even degree.
  • VoddV_{\text{odd}}: The set of vertices with odd degree. By the Handshaking Lemma:
βˆ‘v∈Vdeg⁑(v)=βˆ‘v∈Vevendeg⁑(v)+βˆ‘v∈Vodddeg⁑(v)=2∣E∣\sum_{v \in V} \deg(v) = \sum_{v \in V_{\text{even}}} \deg(v) + \sum_{v \in V_{\text{odd}}} \deg(v) = 2 |E|

Notice that:

  • 2∣E∣2 |E| is strictly an even integer.
  • βˆ‘v∈Vevendeg⁑(v)\sum_{v \in V_{\text{even}}} \deg(v) is a sum of even numbers, which is strictly even. Rearranging:
βˆ‘v∈Vodddeg⁑(v)=2∣Eβˆ£βˆ’βˆ‘v∈Vevendeg⁑(v)=Evenβˆ’Even=Even\sum_{v \in V_{\text{odd}}} \deg(v) = 2 |E| - \sum_{v \in V_{\text{even}}} \deg(v) = \text{Even} - \text{Even} = \text{Even}

The sum of an odd number of odd terms is odd! Therefore, for the sum of odd degrees to be even, there must be an even number of terms in VoddV_{\text{odd}}.


πŸ›οΈ Standard Graph Families​

Fundamental Families of Simple Graphs

Classical symmetric topologies forming the building blocks of network theory

⭐

Complete Graph (Kβ‚™)

All-to-All Mesh
  • Every pair of distinct vertices is connected by an edge.
  • Degree of every vertex: n - 1.
  • Total edges: |E| = n(n - 1) / 2 = C(n, 2).
  • Hamiltonian cycles: (n - 1)! / 2.
  • Spanning trees (Cayley's Formula): n^(n - 2).
πŸ”„

Cycle Graph (Cβ‚™)

Closed Ring (n β‰₯ 3)
  • A single closed loop with vertices v₁, vβ‚‚, ..., vβ‚™.
  • Every vertex has degree exactly 2 (2-regular).
  • Total edges: |E| = n.
  • Bipartite if and only if n is EVEN.
πŸ“

Path Graph (Pβ‚™)

Linear Chain
  • A single non-branching chain with n vertices.
  • Two leaf endpoints of degree 1; n - 2 internal vertices of degree 2.
  • Total edges: |E| = n - 1.
  • Always bipartite for all n β‰₯ 1.
☸️

Wheel Graph (Wβ‚™)

Hub & Spokes (n β‰₯ 3)
  • Formed by adding a central hub vertex to a cycle Cβ‚™.
  • Total vertices: n + 1. Total edges: 2n.
  • Central hub has degree n; rim vertices have degree 3.

Regular Graphs​

πŸ“–Definition 9.3: Regular Graphdefinition

A graph is kk-regular if every vertex has the exact same degree kk:

βˆ€v∈V,deg⁑(v)=k\forall v \in V, \quad \deg(v) = k

By the Handshaking Lemma, the number of edges in a kk-regular graph with nn vertices is:

nβ‹…k=2∣Eβˆ£β€…β€ŠβŸΉβ€…β€Šβˆ£E∣=nβ‹…k2n \cdot k = 2 |E| \implies |E| = \frac{n \cdot k}{2}

Immediate Invariant: For a kk-regular graph to exist, the product nβ‹…kn \cdot k must be an even integer! At least one of nn or kk must be even (e.g., a 3-regular graph cannot have 7 vertices because 7Γ—3=217 \times 3 = 21, which is odd).


πŸŒ“ Bipartite Graphs & TurΓ‘n's Bound​

πŸ“–Definition 9.4: Bipartite Graph & Complete Bipartite (K_{m, n})definition

A simple graph G=(V,E)G = (V, E) is bipartite if its vertex set VV can be partitioned into two non-empty disjoint sets V1V_1 and V2V_2 (V1βˆͺV2=V,V1∩V2=βˆ…V_1 \cup V_2 = V, V_1 \cap V_2 = \emptyset) such that every edge in EE connects a vertex in V1V_1 to a vertex in V2V_2. No edge connects two vertices within the same partition!

  1. Complete Bipartite Graph (Km,nK_{m, n}): Every vertex in V1V_1 (∣V1∣=m|V_1| = m) is connected to every vertex in V2V_2 (∣V2∣=n|V_2| = n).
    • Total vertices: ∣V∣=m+n|V| = m + n.
    • Total edges: ∣E∣=mβ‹…n|E| = m \cdot n.
    • Degrees: Vertices in V1V_1 have degree nn; vertices in V2V_2 have degree mm.
    • Total spanning trees: Ο„(Km,n)=mnβˆ’1nmβˆ’1\tau(K_{m, n}) = m^{n - 1} n^{m - 1}.
  2. TurΓ‘n's Maximum Edge Bound for Bipartite Graphs: In any bipartite graph with nn vertices, the maximum possible number of edges occurs when the partitions are balanced as equally as possible (m=⌊n/2βŒ‹,nβˆ’m=⌈n/2βŒ‰m = \lfloor n/2 \rfloor, n - m = \lceil n/2 \rceil): max⁑∣E∣=⌊n24βŒ‹\max |E| = \left\lfloor \frac{n^2}{4} \right\rfloor
β˜… 2-Colorable Bipartite Graph (Kβ‚‚,₃)Partite Set V₁ (m = 2)Partite Set Vβ‚‚ (n = 3)u₁deg = 3uβ‚‚deg = 3v₁deg = 2vβ‚‚deg = 2v₃deg = 2
Bipartition: V₁ = {u₁, uβ‚‚} and Vβ‚‚ = {v₁, vβ‚‚, v₃}. Every edge connects a blue vertex to an emerald vertex; zero intra-set edges exist.
πŸ“Theorem 9.4: KΕ‘nig's Characterization of Bipartite Graphstheorem

A graph GG is bipartite if and only if GG contains NO ODD CYCLES!

Intuition: To traverse a cycle in a bipartite graph, you must alternately step from V1β†’V2β†’V1β†’V2…V_1 \to V_2 \to V_1 \to V_2 \dots. To return to your starting partition, you must take an even number of steps. Thus, every cycle in a bipartite graph must have even length!

  • C4,C6,C8C_4, C_6, C_8: Bipartite (even cycles).
  • C3,C5,C7C_3, C_5, C_7: NOT Bipartite (contain odd cycles).
  • Trees and Forests: Always bipartite (contain zero cycles).

πŸ”„ Graph Complement & Self-Complementary Graphs​

πŸ“–Definition 9.5: Complement of a Graphdefinition

Let G=(V,E)G = (V, E) be a simple graph. The complement of GG, denoted Gˉ\bar{G}, has the identical vertex set VV, and two distinct vertices are adjacent in Gˉ\bar{G} if and only if they are NOT adjacent in GG:

e={u,v}∈E(GΛ‰)β€…β€ŠβŸΊβ€…β€Še={u,v}βˆ‰E(G)e = \{u, v\} \in E(\bar{G}) \iff e = \{u, v\} \notin E(G)

Fundamental Properties of Graph Complements:​

  1. Edge Sum Conservation: ∣E(G)∣+∣E(GΛ‰)∣=(n2)=n(nβˆ’1)2|E(G)| + |E(\bar{G})| = \binom{n}{2} = \frac{n(n - 1)}{2}
  2. Complement Degree Formula: For every vertex v∈Vv \in V: deg⁑GΛ‰(v)=(nβˆ’1)βˆ’deg⁑G(v)\deg_{\bar{G}}(v) = (n - 1) - \deg_G(v)
  3. Self-Complementary Graphs: A simple graph is self-complementary if it is isomorphic to its own complement: Gβ‰…GΛ‰G \cong \bar{G} If GG is self-complementary, then ∣E(G)∣=∣E(GΛ‰)∣|E(G)| = |E(\bar{G})|. Substituting into the conservation formula: 2∣E(G)∣=n(nβˆ’1)2β€…β€ŠβŸΉβ€…β€Šβˆ£E(G)∣=n(nβˆ’1)42 |E(G)| = \frac{n(n - 1)}{2} \implies |E(G)| = \frac{n(n - 1)}{4} Because ∣E(G)∣|E(G)| must be a non-negative integer: 4∣n(nβˆ’1)β€…β€ŠβŸΊβ€…β€Šn≑0(mod4)orn≑1(mod4)4 \mid n(n - 1) \iff n \equiv 0 \pmod 4 \quad \text{or} \quad n \equiv 1 \pmod 4 (e.g., n=4n = 4 for P4P_4, and n=5n = 5 for C5C_5 are self-complementary).

πŸ” The Havel-Hakimi Theorem: Is a Sequence Graphical?​

A non-increasing sequence of non-negative integers d=(d1,d2,…,dn)d = (d_1, d_2, \dots, d_n) is called graphical if there exists a simple graph whose vertex degree sequence is precisely dd.

The Havel-Hakimi Algorithm for Graphical Sequences

Recursive greedy stripping algorithm to determine if a degree sequence is physically realizable

1

Parity & Range Pre-Flight Check

Pre-Flight Checks

Check: (1) Max degree d₁ ≀ n - 1. (2) Sum of all degrees is EVEN. (3) Number of odd-degree elements is EVEN. If any check fails, IMMEDIATELY NOT GRAPHICAL!

2

Sort in Descending Order

Sort

Arrange the sequence so d₁ β‰₯ dβ‚‚ β‰₯ ... β‰₯ dβ‚™.

3

Extract the Leading Degree d₁

Greedy Strip

Remove the first element d₁. Subtract 1 from each of the next d₁ elements in the sequence.

4

Repeat Until Termination Base Case

Base Case

Re-sort and repeat. If all elements reduce to zeros (0, 0, ..., 0) ⟹ GRAPHICAL! If any element becomes negative (-1) ⟹ NOT GRAPHICAL!


πŸ“ Step-by-Step Worked Examples​

Example 1: Applying the Havel-Hakimi Algorithm​

Problem Statement: Determine whether the following degree sequence is graphical (can form a simple graph):

d=(5,4,3,3,2,2,2,1)d = (5, 4, 3, 3, 2, 2, 2, 1)

Step-by-Step Solution:

  1. Step 1: Pre-Flight Parity Check

    • Number of vertices: n=8n = 8.
    • Max degree is 5≀nβˆ’1=75 \le n - 1 = 7 (valid).
    • Sum of degrees: 5+4+3+3+2+2+2+1=225 + 4 + 3 + 3 + 2 + 2 + 2 + 1 = 22 (Even! Passes the Handshaking Lemma).
    • Odd-degree vertices: {5,3,3,1}\{5, 3, 3, 1\} (4 odd vertices β€…β€ŠβŸΉβ€…β€Š\implies Even count! Passes).
  2. Step 2: Iteration 1 of Havel-Hakimi

    • Current sequence (sorted): (5,4,3,3,2,2,2,1)(5, 4, 3, 3, 2, 2, 2, 1).
    • Remove the leading element d1=5d_1 = 5.
    • Subtract 11 from the next 55 elements:
      • 4βˆ’1=34 - 1 = 3
      • 3βˆ’1=23 - 1 = 2
      • 3βˆ’1=23 - 1 = 2
      • 2βˆ’1=12 - 1 = 1
      • 2βˆ’1=12 - 1 = 1
    • Unaltered remaining elements: (2,1)(2, 1).
    • Resulting sequence: (3,2,2,1,1,2,1)(3, 2, 2, 1, 1, 2, 1).
    • Re-sort in descending order: d(1)=(3,2,2,2,1,1,1)d^{(1)} = (3, 2, 2, 2, 1, 1, 1)
  3. Step 3: Iteration 2 of Havel-Hakimi

    • Remove leading element d1=3d_1 = 3.
    • Subtract 11 from the next 33 elements:
      • 2βˆ’1=12 - 1 = 1
      • 2βˆ’1=12 - 1 = 1
      • 2βˆ’1=12 - 1 = 1
    • Unaltered elements: (1,1,1)(1, 1, 1).
    • Resulting sequence: (1,1,1,1,1,1)(1, 1, 1, 1, 1, 1).
    • Re-sort: d(2)=(1,1,1,1,1,1)d^{(2)} = (1, 1, 1, 1, 1, 1)
  4. Step 4: Iteration 3 of Havel-Hakimi

    • Remove leading element 11. Subtract 11 from next 11 element: (0,1,1,1,1)(0, 1, 1, 1, 1).
    • Re-sort: (1,1,1,1,0)(1, 1, 1, 1, 0).
    • Continuing the greedy strip terminates in all zeros (0,0,0,0,0,0)(0, 0, 0, 0, 0, 0).
    • Conclusion: The sequence IS GRAPHICAL! A simple graph with this degree sequence exists.

Key Takeaway: Always re-sort the remaining elements in non-increasing order after every subtraction step in Havel-Hakimi!


Example 2: Handshaking Lemma & Bipartite TurΓ‘n Limits​

Problem Statement:

  1. A bipartite graph GG has 12 vertices. What is the maximum number of edges GG can have?
  2. If a simple graph has 10 vertices and is 3-regular, how many edges does it contain? What if it is 3-regular with 11 vertices?

Step-by-Step Solution:

  1. Part 1: Maximum Edges in Bipartite Graph (n=12n = 12)

    • By TurΓ‘n's theorem for bipartite graphs: max⁑∣E∣=⌊n24βŒ‹=⌊1224βŒ‹=1444=36Β edges\max |E| = \left\lfloor \frac{n^2}{4} \right\rfloor = \left\lfloor \frac{12^2}{4} \right\rfloor = \frac{144}{4} = 36 \text{ edges}
    • This occurs in the complete bipartite graph K6,6K_{6, 6} with ∣V1∣=6|V_1| = 6 and ∣V2∣=6|V_2| = 6.
  2. Part 2: 3-Regular Graph with 10 Vertices

    • By the Handshaking Lemma: nβ‹…k=2∣Eβˆ£β€…β€ŠβŸΉβ€…β€Š10Γ—3=30=2∣Eβˆ£β€…β€ŠβŸΉβ€…β€Šβˆ£E∣=15Β edgesn \cdot k = 2 |E| \implies 10 \times 3 = 30 = 2 |E| \implies |E| = 15 \text{ edges}
    • Since k=3≀nβˆ’1=9k = 3 \le n - 1 = 9 and nβ‹…k=30n \cdot k = 30 is even, a 3-regular graph with 10 vertices exists.
  3. Part 3: 3-Regular Graph with 11 Vertices

    • Sum of degrees: 11Γ—3=3311 \times 3 = 33.
    • 3333 is an ODD integer, which violates the Handshaking Lemma (βˆ‘deg⁑(v)=2∣E∣\sum \deg(v) = 2|E| must be even).
    • Alternatively, it would require 11 vertices of odd degree, violating the Odd-Degree Parity Theorem!
    • Conclusion: NO such graph can exist.

Key Takeaway: For a kk-regular graph to exist, the product nβ‹…kn \cdot k must be strictly even, and k≀nβˆ’1k \le n - 1.


🎯 Exam & Interview Pitfall Check​

Core Conceptual Questions

Question 1: Can a simple graph with 7 vertices have degree sequence (6,6,6,2,2,1,1)(6, 6, 6, 2, 2, 1, 1)? Key Focus Points: No! Let us analyze the structural constraints:

  • There are 7 vertices in total (n=7n = 7). A vertex of degree 6 connects to every single other vertex in the graph (it is a universal neighbor).
  • Here, there are three distinct vertices of degree 6 (v1,v2,v3v_1, v_2, v_3). Each of these three vertices must connect to every other vertex in the graph.
  • Therefore, every remaining vertex in the graph must connect to at least v1,v2,v_1, v_2, and v3v_3, meaning every vertex must have degree at least 3!
  • The sequence contains vertices of degree 1 and 2, which contradicts the existence of three degree-6 vertices. Thus, it cannot form a simple graph!

Question 2: If a self-complementary graph has nn vertices, why is n=8n = 8 possible but n=7n = 7 or n=6n = 6 impossible? Key Focus Points: For a graph to be self-complementary (G≅GˉG \cong \bar{G}):

∣E(G)∣=n(nβˆ’1)4|E(G)| = \frac{n(n - 1)}{4}
  • For n=8n = 8: ∣E∣=8Γ—74=14|E| = \frac{8 \times 7}{4} = 14 (integer, valid since 8≑0(mod4)8 \equiv 0 \pmod 4).
  • For n=7n = 7: ∣E∣=7Γ—64=10.5|E| = \frac{7 \times 6}{4} = 10.5 (impossible).
  • For n=6n = 6: ∣E∣=6Γ—54=7.5|E| = \frac{6 \times 5}{4} = 7.5 (impossible). Self-complementary graphs can only exist when n≑0n \equiv 0 or 1(mod4)1 \pmod 4.
Common Interview Traps: Architectural Trade-Offs

Trap 1: Forgetting to re-sort after each step in Havel-Hakimi Why it fails: In Havel-Hakimi, after subtracting 1 from the adjacent elements, the resulting numbers may no longer be in descending order. Subtracting from a non-sorted list invalidates the greedy invariant and produces false negatives!

Trap 2: Counting a self-loop as degree 1 Why it fails: A self-loop connects vertex vv back to itself. Both endpoints of the edge attach to vv, contributing +2 to the degree of vv! Counting it as 1 violates the Handshaking Lemma (βˆ‘deg⁑(v)=2∣E∣\sum \deg(v) = 2|E|).

πŸ’¬

Discussion & Doubts