BITS Pilani
BITS Logo
CS G526: Advanced Algorithms and Complexity

Graphs and Algebraic Matchings

Lecture 9 |2026-08-24
Tulasimohan Molli
BITS Pilani, Hyderabad Campus

Agenda

  1. Introduction to Graph Theory — vertices, edges, and representations.
  2. Degrees & Handshaking Lemma — connectivity metrics and degree sum invariant.
  3. Subgraphs & Edge Contraction — structurally modifying graphs.
  4. Graph Modeling — stable matching (seat allocation), PageRank, and cuts.
  5. Matchings in Graphs — definitions (maximal, maximum, perfect, stable).
  6. Cuts in Graphs — partitioning vertices and crossing edges.
  7. Tutte Matrix & Perfect Matchings — Lovász’s Theorem and PIT.
  8. Randomized Algorithm for Matchings — substitution, Schwartz-Zippel, and runtime.

Introduction to Graph Theory

A graph G = (V, E) is a fundamental mathematical structure used to model pairwise relations between objects.

  • Vertices/Nodes (V): The set of entities (e.g., V = \{1, 2, 3, 4\}).
  • Edges (E): The set of connections between vertices.
    • Undirected E \subseteq \{\{u, v\} \mid u, v \in V\}.
    • Directed E \subseteq V \times V.
  • Adjacency: Two vertices u, v are adjacent if \{u, v\} \in E.
  • Path-connectivity: A graph is connected if there is a path between every pair of vertices.
1 2 3 4 V = {1,2,3,4}, E = {(1,2), (1,3), (1,4), (2,3), (3,4)}

Degrees & Handshaking Lemma

How do we measure vertex connectivity, and what global invariants exist?

  • Degree d(v): The number of edges incident to vertex v.
    • For directed graphs:
      • in-degree d^-(v): number of incoming edges.
      • out-degree d^+(v): number of outgoing edges.
  • Handshaking Lemma: The sum of degrees in any undirected graph is exactly twice the number of edges: \sum_{v \in V} d(v) = 2|E|
    • Proof Intuition: Every edge \{u, v\} has two endpoints, contributing +1 to d(u) and +1 to d(v). Thus, each edge is counted exactly twice.
  • Corollary: Every graph contains an even number of vertices with odd degree.
d=3 d=2 d=3 d=2 Sum = 3+2+3+2 = 10 = 2 * (5 edges)

Subgraphs & Edge Contraction

Modifying graphs structurally via subgraphs and edge mergers:

  • Subgraph H = (V', E'): A graph where V' \subseteq V and E' \subseteq E.
    • An induced subgraph G[V'] keeps all edges from G that connect vertices in V'.
  • Edge Contraction (G / e): Merging the endpoints of an edge e = (u, v).
    • Vertices u and v are replaced by a single new vertex uv.
    • All edges incident to u or v now connect to uv.
    • Important: Self-loops are deleted; parallel edges are kept (creating a multigraph).
    • Contraction reduces the vertex count by exactly 1.
e (contract) u v w uv w

Special Graph Families I

Different structural constraints define interesting families of graphs:

  • Path (P_n): A sequence of vertices connected line-by-line: v_1 - v_2 - \dots - v_n.
  • Cycle (C_n): A path loop returning to its start: v_1 - v_2 - \dots - v_n - v_1.
  • Tree: A connected acyclic graph (no cycles). Has exactly n-1 edges.
  • Complete Graph (K_n): Every pair of distinct vertices is connected by a unique edge. Has exactly \binom{n}{2} edges.
Path P_4 Cycle C_4 Tree Complete K_4

Special Graph Families II

Further structural constraints defining interesting families of graphs:

  • Bipartite Graph: Vertices can be split into two sets U and W such that every edge has one endpoint in U and one in W. No edges exist within U or within W.
  • Hamiltonian Cycle: A closed loop (cycle) that visits every vertex in the graph exactly once.
  • Planar Graph: A graph that can be drawn in the plane such that no two edges intersect except at their endpoints.
    • Example: K_4 is planar (can be drawn without crossings), but the complete graph K_5 is non-planar.
Bipartite U W Planar K_4 Hamiltonian

Application: Google’s PageRank

How Google structured search as a massive graph algorithm using random walks:

  • The Web Graph: Modeling the entire web as a directed graph G = (V, E), where pages are vertices and hyperlinks are directed edges.
  • The Algorithm (Random Surfer):
    • A user browses the web. At page u, they follow a random out-link with probability 1 - d.
    • With probability d (damping factor, typically 0.15), they teleport to a completely random page.
  • PageRank Score: Over time, the probability of being at page v converges to its PageRank score: P(v) = \frac{d}{n} + (1-d) \sum_{u \in \text{In}(v)} \frac{P(u)}{d^+(u)}.
  • Spectral Interpretation: This is the stationary distribution of a random walk (finding the principal eigenvector of the Google matrix).
A PR: 0.1 B PR: 0.2 C PR: 0.25 D PR: 0.45

Problems Modeled via Graphs

Many complex real-world allocation and network problems map directly to graph structures:

  • Seat Allocation (Stable Matching): Match candidates to college seats based on preferences (e.g., JoSAA counselling) such that no candidate and college mutually prefer each other over their assigned match.
  • Network Reliability (Global Min-Cut): Find the minimum set of links to disconnect a network or separate an image, revealing the structural bottleneck.
  • Route Planning (Travelling Salesperson): Find the minimum-cost closed tour (Hamiltonian cycle) that visits every city exactly once.
C_1 C_2 C_3 S_1 S_2 S_3 JoSAA Seat Counselling Model

Matchings in Graphs

A key topic in graph algorithms is finding matching elements:

  • Matching (M): A subset of edges M \subseteq E such that no two edges share a common vertex.
    • Vertices incident to an edge in M are matched; others are unmatched.
  • Maximal Matching: A matching that cannot be expanded by adding another edge (no more independent edges can fit).
  • Maximum Matching: A matching containing the largest possible number of edges.
  • Perfect Matching: A matching of size exactly n/2 (every single vertex in the graph is matched).
    • Condition: A perfect matching can only exist if n is even.
  • Stable Matching (Teaser): Pair elements from two sets based on preferences such that no two elements prefer each other over their assigned partners.
Maximum Matching (Size 2) Blue vertex is unmatched

Cuts in Graphs

A cut separates a graph’s vertices into two groups, partitioning the network:

  • Cut (S, V \setminus S): A partition of the vertex set V into two disjoint, non-empty subsets S and V \setminus S.
  • Cut-Set: The set of edges with one endpoint in S and the other in V \setminus S.
  • Size/Capacity of a Cut:
    • Unweighted: The number of crossing edges.
    • Weighted: The sum of weights of the crossing edges.
  • Notation: c(S, V \setminus S) = |\{ (u, v) \in E \mid u \in S, v \notin S \}|.
  • Goal (Min-Cut): Find a cut (S, V \setminus S) that minimizes this crossing size (the “bottleneck” of the graph).
Cut boundary S V\S Cut Size = 3

Tutte Matrix & Perfect Matchings

Can we determine if a graph has a perfect matching (a way to pair up every vertex with an edge)?

  • Lovász’s Theorem (1979):
    • Create a Tutte Matrix T where we put a variable x_{ij} if edge (i,j) exists (and -x_{ji} symmetrically).
    • The graph has a perfect matching \iff \det(T) is not the zero polynomial.
  • The Problem:
    • Expanding \det(T) symbolically is exponential (n! terms).
    • But checking if \det(T) \not\equiv 0 is exactly a PIT instance!
Tutte Matrix T for K_4:
[  0   x12  x13  x14 ]
[-x12   0   x23  x24 ]
[-x13 -x23   0   x34 ]
[-x14 -x24 -x34   0  ]

det(T) = (x12*x34 - x13*x24 + x14*x23)^2
This is NOT identically zero!
So K_4 has a perfect matching.

Randomized Algorithm for Matchings

Using Lovász’s characterization and Schwartz-Zippel, we get a fast randomized algorithm:

  • The Steps:
    1. Pick a large set of integers S (e.g., |S| = 2n).
    2. Substitute each variable x_{ij} in the Tutte matrix T with a random value chosen uniformly from S.
    3. Compute the determinant \det(T) numerically using Gaussian elimination in O(n^3) time.
    4. If \det(T) \neq 0, output YES (100% correct). If \det(T) = 0, output NO.
  • Error Probability: One-sided error. If a matching exists, the probability of a false zero is at most n/|S| \le 1/2.

Next Lecture

Randomized Global Min-Cut (Karger’s Algorithm) — edge contractions, success probability analysis, amplification, and structural bounds via the probabilistic method.