Lesson 31 +30 XP

Graph Terminology, Degree & the Handshaking Theorem

  1. What is a Graph?

A graph G = (V, E) consists of a non-empty set V of vertices (nodes) and a set E of edges, each edge joining one or two vertices (its end-points).

TypeMultiple edges?Loops?Directed?
Simple graph❌❌❌
Multigraph✅❌❌
Pseudograph✅✅❌
Directed graph (digraph)❌ (simple digraph)✅✅
Directed multigraph✅✅✅

Graphs model networks, maps, molecules, dependencies, social links, state machines …

Simple graph, multigraph, pseudograph and digraph, with vertex degreesSimple graph, multigraph, pseudograph and digraph, with vertex degrees

2. Basic Vocabulary

  • u and v are adjacent (neighbours) if {u, v} ∈ E; the edge is incident with u and v.
  • Degree deg(v) = number of edges incident with v (a loop counts twice).
  • Isolated vertex: degree 0. Pendant (end) vertex: degree 1. Other vertices are internal.
  • In a digraph: in-degree deg⁻(v) = edges coming in, out-degree deg⁺(v) = edges going out.

Example (undirected). deg(v₁) = 3, deg(v₂) = 4 (with a loop), deg(v₃) = 3, deg(v₄) = 3, deg(v₅) = 1 (pendant), deg(v₆) = deg(v₇) = 0 (isolated).

Example (directed). a has a loop and edges giving in-degree 3, out-degree 1; b: 1 and 2; c: 2 and 1; d: 1 and 3. Σ in = Σ out = 7 = number of edges.

3. The Handshaking Theorem

For any undirected graph G = (V, E): ∑v ∈ V deg(v) = 2e

Proof. Every edge has two ends, so it contributes exactly 2 to the sum of degrees (1 to each end-point, or 2 to one vertex if it is a loop). Summing over all e edges gives 2e. ∎

Example. A graph with degrees a = 2, b = 3, c = 4, d = 3, e = 2: sum 14 = 2 × 7, so it has 7 edges.

Corollary. Every graph has an even number of odd-degree vertices. Proof. Σ deg = Σ(even-degree vertices) + Σ(odd-degree vertices) = 2e is even. The first part is even, so the second is even; a sum of odd numbers is even only if there is an even count of them. ∎

For digraphs: Σ deg⁻(v) = Σ deg⁺(v) = e.

** Can a simple graph have degrees 3, 3, 3, 3, 2? Sum = 14 = 2·7 ✓ and four odd vertices (even) ✓ - possible.

Degrees 3, 3, 3, 1? The sum is 10 (even) and there are four odd vertices (even), so the handshaking test passes-yet no simple graph has these degrees: in a 4-vertex simple graph a degree-3 vertex is adjacent to all others, so three such vertices give the last vertex degree 3, not 1.

The handshaking test is necessary, not sufficient.

Solved. How many edges does a graph with 10 vertices each of degree 6 have? 10 × 6 = 2e ⇒ e = 30.

4. Special Simple Graphs

Complete graphs Kₙ, cycles Cₙ, wheels Wₙ, cubes Qₙ and complete bipartite graphsComplete graphs Kₙ, cycles Cₙ, wheels Wₙ, cubes Qₙ and complete bipartite graphs

GraphDescriptionVerticesEdges
Kₙ (complete)every pair adjacentnn(n − 1)/2
Cₙ (cycle), n ≥ 3v₁ - v₂ - … - vₙ - v₁nn
Wₙ (wheel)Cₙ plus a hub joined to alln + 12n
Qₙ (n-cube)bit strings of length n, adjacent if they differ in one bit2ⁿn·2ⁿ⁻¹
Kₘ,ₙ (complete bipartite)parts of size m and n, every cross pair adjacentm + nmn

Regular graph: every vertex has the same degree k (k-regular). Kₙ is (n − 1)-regular, Cₙ is 2-regular, Qₙ is n-regular.

Bipartite graphs

G is bipartite if V = V₁ ∪ V₂ (disjoint) and every edge joins V₁ to V₂. Theorem. G is bipartite iff it can be 2-coloured iff it has no odd cycle. C₆ is bipartite; C₅ and K₃ are not.

5. Subgraphs and Operations

  • Subgraph H = (W, F) with W ⊆ V, F ⊆ E. Spanning subgraph: W = V. Induced subgraph: all edges of G among W.
  • Complement Ḡ: same vertices, edges exactly where G has none. G ∪ Ḡ = Kₙ, so e(G) + e(Ḡ) = n(n − 1)/2.
  • Union G₁ ∪ G₂ = (V₁ ∪ V₂, E₁ ∪ E₂).

6. Representing Graphs

Adjacency matrix vs adjacency list for a 4-vertex graph (from the Data Structures course)Adjacency matrix vs adjacency list for a 4-vertex graph (from the Data Structures course)

RepresentationSpaceEdge testBest for
Adjacency matrix A (aᵢⱼ = number of edges i-j)O(V²)O(1)dense graphs
Adjacency listO(V + E)O(deg v)sparse graphs
Incidence matrix (V × E, 1 if vertex on edge)O(VE)O(E)theory

For an undirected graph A is symmetric, and the row sum of vertex i is deg(i) (a loop is usually entered as 2 so that this holds).

🎯 END-TERM EXAM PREP

📝 IPU End-Term Exam Corner (5-10 Marks)

  • Q1. State and prove the handshaking theorem. Show that the number of odd-degree vertices is even. (5 Marks)
  • Q2. Define simple graph, multigraph, pseudograph, regular graph, complete graph and bipartite graph with figures. (5 Marks)
  • Q3. A graph has 21 edges, 3 vertices of degree 4 and all other vertices of degree 2. How many vertices does it have? (2.5 Marks) → 3·4 + 2(n − 3) = 42 ⇒ n = 18.
  • Q4. Find the number of edges of K₇, W₅ and Q₃. (2.5 Marks) → 21, 10, 12.