Great Theoretical Ideas In Computer Science
Victor Adamchik
Cayley’s Formula
CS 15-251
Carnegie Mellon University
Graphs - II
The number of labeled trees on n nodes is nn-2
Put another way, it counts the number of
spanning trees of a complete graph Kn.
4
2
1
3
5
P = 5, 1, 1, 5
6
We proved it by finding a bijection between the
set of Prϋfer sequences and the set of labeled
trees.
Planar Graphs
Theorem: In any connected
planar graph with V vertices, E
edges and F faces, then
V–E+F=2
Theorem: In any connected planar graph with at
least 3 vertices:
E≤3V-6
Lemma: In any connected planar graph with at
least 3 vertices:
3F≤2E
K5 can be embedded on the torus
Embedding a graph onto a surface means drawing
the graph on the surface such that no edges cross.
Is K5 planar?
K5 has 5 vertices and 10 edges,
thus
E = 10 ≤ 3x5 – 6 = 9
which is false, therefore
K5 is not planar.
Theorem: In any connected
planar graph with V vertices, E
edges and F faces, then
V–E+F=2
Outline
Bipartite Graphs
Kuratowski-Wagner Theorem
Graph Coloring
Bipartite Matching
Always there is a surface so any graph can be
embedded to.
1
Bipartite Graphs
Bipartite Graphs
Theorem. A graph is bipartite iff it does not have
an odd length cycle.
A graph is bipartite if the
vertices can be partitioned
into two sets V1 and V2 such
that all edges go only between
V1 and V2 (no edges go from V1
to V1 or from V2 to V2)
The complete bipartite graphs Km,n have the
property that two vertices are adjacent if and
only if they do not belong together in the
bipartition subsets.
Proof. )
If it’s bipartite and
has a cycle, its
length must be even.
Bipartite Graphs
Theorem. A graph is bipartite iff it does not have
an odd length cycle.
) (by construction)
Fix a vertex v. Define two sets of
vertices
A ={w V | even length shortest
edge path from v to w}
v
x
y
B ={w V | odd length
shortest edge path from v to w}
If x and y from A, they cannot be adjacent. By
contradiction. There will be an odd length cycle.
The same argument for B. These sets provide a
bipartition.
Is K3,3 planar?
Is K3,3 planar?
In any connected planar graph
with at least 3 vertices:
E≤3V-6
K3,3 has 6 vertices and 9 edges,
thus
E = 9 ≤ 3x6 – 6 = 12
Not conclusive!
Is a tree always
a bipartite graph?
∑(edge, face) ≤ 2 E, since each
edge is associated with at most
2 faces.
∑(edge, face) ≥ 4 F , since
graph contains no simple
triangle regions of 3 edges.
Utility Graph
It follows, that
4F≤2E
and for K3,3 we have
4F ≤ 18
From Euler’s theorem: V – E + F = 2
F ≤ 4.5
F = 2 + 9 – 6 = 5. Contradiction!
2
Planar Bipartite Graphs
The previous example established two simple
criteria for testing whether a given planar graph
is bipartite.
Kuratowski Theorem (1930)
Theorem. A graph is planar if and only if it
contains no subgraph isomorphic to a
subdivision of K5 or K3,3.
Theorem. In any bipartite planar graph with at
least 3 vertices:
E≤2V-4
Lemma: In any bipartite planar graph with at
least 3 vertices:
4F≤2E
For any graph on V vertices there are efficient
algorithms for checking if the graph is planar.
The best one runs in linear time O(V)
Graph Isomorphism
Graph Isomorphism
Definition. Two simple graphs G and H are
isomorphic G H if there is a vertex
bijection VH->VG that preserves adjacency
and non-adjacency structures.
Does not preserve adjacency
Does not preserve adjacency
Subdivision
Definition. Subdividing an edge means inserting a
new vertex (of degree two) into this edge.
The graph isomorphism problem has no known
polynomial time algorithm which works for an
arbitrary graph.
Theorem. A graph is planar if and only if it
contains no subgraph isomorphic to a
subdivision of K5 or K3,3.
A
A
a
B
b
e
c
C
Petersen
graph
a
d
D
E
The
Petersen
graph
10 vertices
15 edges
B
b
c
C
e
d
E
Remove B
to get a
subgraph
D
3
Theorem. A graph is planar if and only if it
contains no subgraph isomorphic to a
subdivision of K5 or K3,3.
A is
subdividing
(a,E)
A
b
c
C
a
e
b
d
D
E
Theorem. A graph is planar if and only if it
contains no subgraph isomorphic to a
subdivision of K5 or K3,3.
a
e
b is
subdividing
(d,e)
c
C is
subdividing
(c,D)
Subdivision and Contraction
Definition. Subdividing an edge means inserting a
new vertex (of degree two) into this edge.
e
a
D
E
c
d
d
E
D
Wagner Theorem
Theorem. Graph G is planar if and only if it
contains no subgraph that can be contracted
to K5 or K3,3.
Is the Petersen graph planar?
Definition. An edge contraction is an operation
which removes an edge from a graph while
simultaneously merging the two vertices it
used to connect.
Coloring Graphs
A coloring of a graph is an assignment of a
color to each vertex such that no neighboring
vertices have the same color
Graph Coloring
Theorem : Every simple planar graph has a vertex
of degree < 6.
Proof.
∑deg(vk) = 2 E ≤ 2 (3 V – 6)
Average degree:
1/V ∑deg(vk) ≤ 6 – 12/V < 6
Thus, there exists a vertex of degree < 6.
This technique is called the probabilistic method.
4
Coloring Planar Graphs
Theorem: Any simple planar graph can be
colored with 6 colors.
Proof. (by induction on the number of vertices).
If G has six or less vertices, then the result is
obvious. Suppose that all such graphs with V-1
vertices are 6-colorable
Remove a vertex of degree less than 6, use IH.
Put it back, since it has at most 5 adjacent
vertices, we have enough colors. QED
Coloring Planar Graphs
Theorem: Any simple planar graph can be
colored with less than or equal to 5 colors.
Proof. (repeat the 6-colors proof)
Pick a vertex v of degree 5. Label the
vertices adjacent to v as x1, x2, x3, x4 and x5.
Assume that x4 and x5 are not adjacent to each
other.
Why we can
assume this?
If all x1,…,x5
adjacent,
we get K5.
4 Color Theorem (1976)
Theorem: Any simple planar graph can be
colored with less than or equal to 4 colors.
Contract edges (v, x4), (v, x5). Vertices v, x4, x5
will be replaced by y, so neighbors of v, x4, x5
will be neighbors of y.
We obtain a new graph H with two less vertices.
By IH the graph H can be colored with 5 colors.
Next, we assign y-color to x4 and x5
We give v a color different from all colors used on
the four vertices x1, x2, x3 and y. QED
Graph Coloring
Graph coloring is computationally
hard. It is NP-complete to decide if
a given graph admits k>2 colorings.
Important case: 3-coloring., also NP-complete,
even for planar graphs.
It was proven in 1976 by K. Appel and W. Haken.
They used a special-purpose computer program.
Since that time computer scientists have
been working on developing a formal program proof
of correctness. The idea is to write code that
describes not only what the machine should do, but
also why it should be doing it.
In 2005 such a proof has been developed by
Gonthier, using the Coq proof system.
Bipartite Matching
A graph is bipartite if the vertices can be
partitioned into two disjoint (also called
independent) sets V1 and V2 such that all edges go
only between V1 and V2 (no edges go from V1 to V1
or from V2 to V2)
Personnel Problem. You are the boss
of a company. The company has M
workers and N jobs. Each worker is
qualified to do some jobs, but not
others. How will you assign jobs to
each worker?
5
Bipartite Matching
Bipartite Matching
Definition. A subset of edges is a matching if no
two edges have a common vertex (mutually
disjoint).
Definition. A perfect matching is a matching in
which each node has exactly one edge incident on it.
A perfect matching is like a bijection, which
requires that |V1| = |V2 | and in which case its
inverse is also a bijection.
Definition. A maximum matching is a matching with
the largest possible number of edges
Hall’s (marriage) Theorem
Maximum Matching
Consider a matching M = {(y1,x2),(y3,x4)}
Theorem. (without proof)
Let G be bipartite with V1 and V2.
For any set SV1, let N(S) denote the set of
vertices adjacent to vertices in S.
Alternating path has edges alternating between M
and E/M. Path x1, y1, x2, y3, x4 is alternating.
An alternating path is augmenting if both of
its endpoints are free vertices.
Then, G has a perfect matching if and only if
for every SV1.
|S| ≤ |N(S)|
x1
x2
x3
x4
y1
y2
y3
y4
Path x1, y1, x2, y3, x4, y4
is augmenting.
Maximum Matching
Hungarian Algorithm
If a matching M (in green) has an augmenting path,
then we get a larger matching by swapping the
edges on the augmenting path.
x1
x2
x3
x4
x1
x2
x3
x4
y1
y2
y3
y4
y1
y2
y3
y4
The algorithm starts with any matching and
constructs a tree via a breadth-first search to
find an augmenting path.
If the search succeeds, then it yields a matching
having one more edge than the original.
Then we search again (it most it happens is V/2)
for a new augmenting path.
If the search is unsuccessful, then the algorithm
terminates and must be the largest-size matching
that exists.
6
Proof of Correctness
What is the runtime
complexity of the
Hungarian algorithm?
The algorithm clearly terminates, since we
match one edge per step.
Complexity of BFS – O(V+E)
Suppose that there were another matching M1
that used more edges than M.
Overlap M and M1 - the result is a union of cycles
and paths.
There is a path that have more M1 edges than
from M.
We run it V/2 times
This, the runtime is O(V E).
This path is an augmenting path. Contradiction.
Matching on Non-Bipartite Graphs
The Hungarian algorithm does not work on general
graphs.
The problem is to find an
augmenting path, that in
general case might have an
odd length cycle (called a
blossom).
The blossom can be
shrunk and the search
restarted recursively.
Rook Attack
This problem asks us to place a
maximum number of rooks (they
move horizontally and vertically)
on a chessboard with some
squares cut out (forbidden
positions)
R
Rook
R
The Blossom algorithm is
due to Edmonds, 1965.
Rook Attack
This problem asks us to place a maximum number
of rooks on a chessboard with some squares cut
out.
r1
c1
r2
c2
r3
c3
The number of non-attacking rooks equals the
number of edges in a matching.
Planar Graphs
Kuratowski Theorem
Graph Coloring
Bipartite Graphs
Bipartite Matching
Hall Theorem
Here’s What
You Need to
Know…
7
© Copyright 2026 Paperzz