math 340 notes

Transcription

math 340 notes
Discrete Structures II, MATH 340
Instructor O. Kharlampovich
1
Undirected graphs
The edges in an undirected graph connect pairs of vertices.
• A graph is a pair G = (V, E) where V = {v1 , v2 , · · · , vn } is the set of
vertices and E = {e1 , e2 , · · · , em } is the set of edges.
• Each edge ei has two endpoints u, v ∈ V .
• If there is an edge ei with endpoints u and v then we say that u and v are
adjacent, and that ei is incident with u and v.
• When u = v the edge ei is called a loop.
• We use V (G) to denote the vertices of G and E(G) to denote the edges of
G.
• For each vertex v ∈ V (G) let deg(v) denote the number of edges incident
with v (counting loops twice). This is called the degree of v.
• We say that G is simple if there are no loops in E(G) and at most one
edge between any pair of vertices. In this case, an edge between u and v
is denoted (u, v).
• In this course, we will use the word graph to denote a simple graph.
This is the area where our terminology most differs from the Rosen text.
• A walk (in text: path) in a graph is a sequence of vertices v1 , v2 , . . . , vk
such that vi−1 and vi are adjacent for all i.
• A trail (in text: simple path)is a walk without repeated edges.
• A path (this important concept has no name in the text) is a trail without
repeated vertices.
• A closed walk or circuit (in text: circuit or cycle) is a walk v0 , . . . , vk
where vk = v0 .
• A k − cycle is a closed walk of length k with no repeated vertices except
v0 = vk . Notation Ck .
• A graph G is connected if for all vertices u, v there is a path from u to v
Lemma 1.1. Every walk from u to v contains a path from u to v.
1
Proof. Let w be a walk from u to v and let p = v0 , e1 , v1 , e2 , . . . , ek , vk be the
shortest walk from u = v0 to v = vk that uses only edges in w. We claim that
p is a path.
Suppose that p is not a path, and that there are vertices i, j such that i < j
and vi = vj . Then
p = v0 , e1 , . . . , vi , ej+1 , vj+1 , . . . , vk
is a shorter path from u to v using only edges in w. This contradicts our choice
of p. Hence all the vertices in p are distinct and p is a path.
Lemma 1.2. If there is a path from u to v and a path from v to w then there
is a path from u to w.
Proof. Form a walk from u to w that starts with the path from u to v followed
by the path from v to w. By Lemma 1.1 this walk contains a path from u to
w.
Definition 1.3 (connected). We say that two vertices u, v are connected if
there exists a path from u to v. A graph G = (V, E) is connected if each pair
of vertices is connected.
Theorem 1.4. Let R be the relation on V whereby (u, v) ∈ R if and only if u
is connected to v. Then R is an equivalence relation.
Proof.
Reflexive: For every v there the path of length 0 from v to itself, so (v, v) ∈ R.
Symmetric: If there is a path from u to v then reversing the order of vertices
and edges in the path gives a path from v to u. Hence (u,v) ∈ R implies (v,u)
∈ R.
Transitivity: If (u, v) ∈ R and (v, w) ∈ R then there is a path from u to v and
from v to w. By the preceding lemma there is a path from u to w and (u, w) ∈
R.
Definition 1.5 (components, isolated). The components of G are the maximal connected subgraphs of G (Figure 1). These correspond to the equivalence
classes of the connectedness relation. A vertex with degree 0 is an isolated
vertex. Every isolated vertex is in a separated component.
Lemma 1.6. Adding an edge to a graph reduces the number of components by
at most one. Hence removing an edge from a graph increases the number of
components by at most one.
Proof. If u are v are in the same component then adding the edge e = (u, v) has
no effect on the number of components. If u and v are in different components
then adding the edge e = (u, v) combines the component containing u and
the component containing v, thereby reducing the number of components by
one.
2
•
•
•
•
•
•@
 @@@

@@

@

•@
•
@@


@@

@@ 

•
Figure 1: 2 connected components
Corollary 1.7. A graph with n vertices and k edges has at least n - k components.
Proof. We prove this by induction on k. Let P (k) denote the proposition: ”if G
has n vertices and k edges then G has at least n − k components”. Then P (0)
is true since if k = 0 the graph would consist of n isolated vertices.
Suppose that m ≥ 0 and that P (m) is true. Suppose that G has m + 1
edges. Remove an edge to give a graph with m edges, which by P (m) has at
least n − m components. Adding the edge again give a graph with at most
n − (m + 1) components.
Definition 1.8 (Subgraph). Let G = (V, E) and H = (V 0 , E 0 ) be graphs. We
say that G is a subgraph of H if V 0 ⊆ V and E 0 ⊆ E.
Definition 1.9 (Spanning). H is called a spanning subgraph if V 0 = V .
Definition 1.10 (Induced). Suppose that U ⊆ V and that E 0 is the set of
edges in E that have both endpoints in U . Then H = (U, E 0 ) is called the
subgraph of G induced by U (Figure 2).
v1
v3
||
||
|
|
||
v2 v1
v4 v3
||
||
|
|
||
v2
Figure 2: The right graph is an induced subgraph of the left graph on the set
U = {v1 , v2 , v3 }
.
Definition 1.11 (adjacency matrix). Let G be a finite graph with vertices
v1 , v2 , . . . , vn . The adjacency matrix A for G is the n × n matrix where Aij
equals the number of edges with endpoints vi , vj (Figure 3).
A is symmetric. For simple graphs, Aij ∈ {0, 1}
Theorem 1.12. The number of distinct walks from vi to vj of length k equals
(Ak )ij . By definition, A0 is the identity matrix.
3

v1
v3 B
BB
BB
BB
B
v4
v2
v5


A = 


0
0
1
0
1
0
0
1
0
0
1
1
0
1
0
0
0
1
0
1
1
0
0
1
0






Figure 3: The adjacency matrix corresponding to a graph.
Proof. We prove this by induction on k.
Let Wk (u, v) denote the set of walks from u to v.
Let P (k) denote the proposition: ”|Wk (vi , vj )| = (Ak )ij ”.
P (1) is true since there is only one distinct (trivial) walk of length zero from
each vertex to itself. Suppose P (m) is true for m ≥ 0. For each l, let
Wm+1 (vi , vlj , vj ) denote the set of walks of length m + 1 from vi to vj that
finish with an edge from vl to vj . Then each walk of length (m + 1) from vi to
vj is in exactly one of the sets Wm+1 (vi , vl , vj ), so
X
|Wm+1 (vi vj )| =
|Wm+1 (vi , vl , vj )|.
l
How many walks are then in each set Wm+1 (vi , vl , vj )? Each of these walks
consists of a walk of length m from vi to vl followed by one of the edges from
vl to vj . Hence the number of different walks in Wm+1 (vi , vl , vj ) equals the
number of walks of length m from vi to vl multiplied by the number of edges
from vl to vj . That is,
|Wm+1 (vi , vl , vj )| = (Am )ij · (A1 )lj = (Am+1 )ij .
Thus P (m + 1) is true and by induction, P (k) is true for all k ≥ 0.



A = 


2
2
1
0
2
2
1
1
0
1
1
0
0
3
0
0
2
1
0
2
2
0
0
2
0
0





 3
A = 




0
0
5
0
4
0
0
3
0
2
5
3
0
5
0
0
0
5
0
4
4
2
0
4
0






Figure 4: Powers of A corresponding to Figure 3
Corollary 1.13. G is connected if and only if
Pn
k=1
Ak has no zero elements.
Proof. If G is connected then for each vi , vj there is a path from vi to vj . Let k 0
be the length of the path. Since the vertices on the path are distinct the path
0
contains at most n vertices,P
so k 0 ≤ n. Thus (Ak )ij ≥ 1 while (Ak )ij ≥ 0 for
n
all k 6= k 0 . It follows that ( k=1 Ak ) > 0.
Suppose that G is not connected. Then there are vertices vi and vj such
that there is no path from vi to vj . It follows that (Ak )ij = 0 for all k.
4
2
Directed Graphs
Definition 2.1 (Digraph, arcs). A directed graph (or digraph) is defined in
the same way as an undirected graph, except the edges are oriented and have
beginnings and endings. The edges in directed graphs are sometimes called
arcs.
Definition 2.2 (head, tail). If ei is an directed edge from u to v we say that u
is the tail or initial vertex of ei and that v is the head or end vertex of ei .
Definition 2.3 (In-degree, Out-degree). For each vertex v ∈ V (G) let deg+ (v)
denote the number of edges starting at v and let deg− (v) denote the number of
vertices ending at v. We say that deg+ (v) is the out − degree of v and deg− (v)
is the in − degree of v.
A (directed) walk in a directed graph is a sequence of vertices v1 , v2 , . . . , vk
such that (vi−1 , vi ) ∈ E for all i. A (directed) trail is a walk without repeated
edges. A (directed) path is a trail without repeated vertices.
A graph G is strongly connected if for all u, v there is a path from u to v
and a path from v to u. The strong components of a digraph are the maximally
strong connected subgraphs.
We can construct adjacency matrices for digraphs and Theorem 1.12 holds
in this case as well.
Lemma 2.4. If G = (V, E) is a directed graph then
X
X
|E| =
deg + (v) =
deg − (v).
v∈V
v∈V
Proof. We count the number of edges |E| two ways. For each vertex u there are
deg + (u)Pedges starting at u, and every edge starts at exactly one vertex. Thus
+
−
|E| =
u∈V deg (u). For each vertex v there are deg (v)
P vertices ending at v
and every edge ends at exactly one vertex. Thus |E| = v∈V deg − (v).
3
Trees
Definition 3.1 (K-cycle). A k − cycle is a walk v0 , v1, . . . , vk − v0 such that
all v0 , v1 , . . . , vk−1 are distinct (called a simple circuit in Rosen text).
Definition 3.2 (tree). A tree is a connected graph without cycles.
Definition 3.3 (forest). A forest is a graph without cycles. The connected
components of a forest are trees.
Definition 3.4 (leaf). A leaf is a vertex of degree 1.
Lemma 3.5. Every finite tree with at least two vertices has at least two leaves.
5
Proof. Let P be the longest path in the tree and let u and v be its endpoints. If
deg(u) > 1 then u is either adjacent to a different vertex of P (giving a cycle) or
u is adjacent to a vertex not on P (so that we can make a longer path.) Either
case leads to a contradiction. Hence, deg(u) = 1 and by the same argument
deg(v) = 1.
Theorem 3.6. A tree with n vertices has n - 1 edges.
Proof. Let P (n) denote: ”if T is a tree with n vertices then T has n − 1 edges”.
Then P (1) is true. Suppose that m ≥ 1 and that P (m) is true. Let T be a
tree with m + 1 vertices. One of these is a leaf. Remove it. This gives a tree
with one less vertex and, by P (m), m − 1 edges. That means that T has m
edges.
Definition 3.7 (Cut edge). An edge e is a graph G is a cut edge if removing
e increases the number of connected components of G.
Theorem 3.8. A connected graph G is a tree if and only if every edge is a cut
edge.
Proof. Suppose G is a tree. Then G has n − 1 edges. For any edges e, G − e
has n vertices and n − 2 edges, so by Lemma 2.4, G − e has at least two
components. It follows that every edge e is a cut edge.
Now suppose that every edge is a cut-edge. We use a proof by contradiction.
Suppose that G contained a cycle, and let e = {u, v} be an edge on this cycle.
This cycle contains a path from u to v in the graph G − e.
Let w be an arbitrary vertex in G. Since G is connected, there is a path
Pw from w to u. If this path does not go through e then w is connected to u
is G − e. If the path does go through e, then removing the last edge gives a
path from w to v in G − e. As there is already a path from v to u this implies
that there is a path from w to u. Hence G − e is connected and e is not a
cut-vertex.
Lemma 3.9. If G is a tree then there is a unique path between any two vertices.
Proof. We use a proof by contradiction. Suppose there are two paths P1 , P2
between two vertices u, v. Let e be an edge of P1 that is not an edge of P2 .
There is therefore a walk formed from P1 − e and P2 that connects the endpoints
of e. This walk contains a path between the endpoints of e which, together with
e, creates a cycle in G.
Definition 3.10 (Spanning tree). A spanning tree is a spanning subgraph which
is a tree.
Lemma 3.11. Every finite connected graph contains a spanning tree.
Proof. Remove edges that don’t disconnect the graph. What remains is a minimally disconnect subgraph: a tree.
6
Lemma 3.12. Let G be a finite connected graph and let e be an edge of G.
Then there is a spanning tree of G that contains e.
Proof. Repeatedly apply the following: find a cycle and remove an edge of this
cycle that does not equal e.
Since every cycle contains at least two edges, we can remove an edge each
time we find a cycle. Removing an edge in the cycle doesn’t disconnect the
graph. The process repeats until we have obtained a spanning tree and this
spanning tree will contain e.
By the same argument we have that e is a cut edge if and only if e is contained
in every spanning tree.
Theorem 3.13. (Cayley) Let Kn be a complete graph on n vertices (every two
vertices are adjacent). The number of spanning trees in Kn is nn−2 .
Proof. The first proof we present, due to Prüfer (1918), uses the algorithm
that produces a ”code” that characterizes the tree. Any such code uniquely
determines a tree.
Let T be a tree with V (T ) = {1, 2, . . . , n}. We use the order on the vertex
set.
Let T1 = T , for Ti let bi denote the least leaf of Ti , let ai be the vertex
adjacent to bi and let Ti+1 = Ti − {(ai , bi )}.
We get the code {a1 , . . . , an−1 } but the last number is always n = an−1 .
Therefore {a1 , . . . , an−2 } is the code for T (Figure 3).
v4 B
v5 B
v6
v7
BB
BB
{
{
BB
BB
{
BB
BB
{{
B
B {{{
v2
v1
v10 C
v8
CC
|
|
CC
||
CC
||
C
||
v9
v3
b1
b2
b3
b4
b5
b6
b7
b8
b9
=
=
=
=
=
=
=
=
=
3
4
2
5
6
7
1
8
9
a1
a2
a3
a4
a5
a6
a7
a8
a9
=
=
=
=
=
=
=
=
=
2
2
1
1
7
1
10
10
10
Figure 5: A tree T and the step-by-step application of Prüfer’s algorithm.
Applying the algorithm in reverse shows how to construct a tree if we have
a Prüfer code {a1 , . . . , an−2 }: Write an−1 = n. For i = 1, . . . , n − 1 let bi be
7
the least vertex not in {ai , . . . , an−1 } ∪ {b1 , . . . , bi−1 }. Then {(bi , ai )} will be
the edge set of a spanning tree (Figure 3).
b1
b2
b3
..
.
=
=
=
3
4
2
..
.
a1
a2
a3
..
.
=
=
=
2
2
1
..
.
(3,2)
(4,2)
(2,1)
..
.
Figure 6: The reverse of prüfer’s algorithm.
In general, any sequence of n − 2 numbers from {1, 2, . . . , n} uniquely determines a tree on this set. There are nn−2 such sequences, proving the theorem.
We now give a second proof of Cayley’s theorem by counting since it is useful
to have been seen this method.
We remind the definition of a multinomial coefficient. Recall the binomial
coefficient:
n X
n
n
(x + y)
=
xi y n−i
i
i=0
n!
n
=
i
i!(n − i)!
Now the multinomial coefficient:
n
(x1 + · · · + xk )
=
X
n
r1 , . . . , rk
xr11 . . . xrkk
where the sum is over all k-tuples (r1 , . . . , rk ) with sum n.
n!
n
=
r1 , . . . , rk
r1 ! . . . rk !
(x1 + · · · + xk )n = (x1 + · · · + xk )n−1 · (x1 + · · · + xk )
k X
n
n−1
=
r1 , . . . , rk
r1 , . . . , ri−1 , . . . rk
i=1
Denote the number of spanning trees in Kn for which the degrees of the vertices are d1 , . . . , dn by t(n, d1 , . . . , dn ). We may assume without loss of generality
that d1 ≥ d, ≥ · · · ≥ dn = 1. Then,
n
X
n
X
di
=
2(n − 1) = 2|E|
(di − 1)
=
n−2
i=1
i=1
8
Theorem 3.14. The number of spanning trees of Kn having degrees of vertices
d1 , . . . , dn is t(n, di , . . . , dn )
(n − 2)!
n−2
=
= Qn
d1 − 1, . . . , dn − 1
i=1 (di − 1)!
Proof. Take the leaf vn corresponding to dn = 1. It is joined to some vertex vj
of deg di ≥ 2 and any of the remaining vertices are candidates. Therefore
t(n, di , . . . , dn )
=
n−1
X
t(n − 1, d1 , . . . , di − 1, . . . , dn )
i=1
It is trivial to check by hand that
t(n, di , . . . , dn ) =
n−2
d1 − 1, . . . , dn − 1
for n = 3. Since the numbers on the lefthand side and on the righthand side
satisfy the same recurrence relation, it follows by induction that equality
t(n, di , . . . , dn ) =
n−2
d1 − 1, . . . , dn − 1
is true for all n.
We find now by putting
x1 = . . . = xn = 1 in the multinomial formula
n−2
= nn−2 which gives another proof of Cayley’s theod1 − 1, . . . , dn − 1
rem.
P
Definition 3.15 (K-clique). A k − clique in a graph is a subgraph isomorphic
to Kk (a set of pairwise adjacent vertices). w(G) denotes the size of the largest
clique in G.
Definition 3.16 (Anti-clique). An independent k-set anti − clique of size k
is a complement of a k-clique (k vertices no two of which are adjacent). α(G)
denotes the maximum size of the anti-clique.
Definition 3.17 (Distance). The distance between two vertices u and v is the
length of the shortest path between u and v
Definition 3.18 (Diameter). The diameter of G is the maximum distance
between all pairs of vertices (but don’t confuse the diameter with the length of
the longest path).
Definition 3.19 (Girth). The girth of G is the length of its shortest cycle.
Every forest has infinite girth.
9
v
~
~~
~
~
~~
•@
@@
@@
@@
u
•@
@@
@@
@@
•
•





•
•
Figure 7: A cyclic graph whose diameter is 4 but where the longest path between
u and v is 7.
•
•
•
•
•
•
•
•
•
•
•
•
Figure 8: The diameter of a n × m grid is n + m − 2.
4
Coloring
Definition 4.1 (K-coloring). A legal k-coloring is an assignment of k-colors to
vertices of G such that any two adjacent colors have different colors.
f : V → [K] = {1, 2, . . . , k}
Definition 4.2 (Chromatic number). Let G be a finite graph. The chromatic
number χ(G) is the minimal number k such that G admits k-coloring.
Example 4.3 (Exam Scheduling). Suppose we have n different courses: V =
courses. The vertices u and v are adjacent if there exists a student taking both
classes. Colors correspond to exam times.
Example 4.4 (Mobile telephone frequencies). A similar problem occurs when
assigning calling frequencies for mobile telephone towers. Two towers should
not broadcast on the same frequency if it possible that someone might be in the
range of both towers.
Definition 4.5 (bipartite). A graph is bipartite if it is 2-colorable.
(χ(G) = 2) ⇒ V = V1 ∪ V2
There do not exist edges (u, v) such that u, v ∈ V1 or u, v ∈ V2 .
10
Lemma 4.6. Every tree is bipartite.
Proof. Let P (n) be the proposition: ”a tree of n vertices is bipartite”. P (1) is
true trivially.
Suppose that m ≥ 1 and that P (m) is true. Let T be a tree with m + 1
vertices. Then T contains a leaf x. Let y be the vertex adjacent to x and let
T 0 be the tree formed by removing x from T . Then T 0 has a 2-coloring and we
can extend this to T by coloring x a different color than y.
Lemma 4.7. If G is a bipartite graph, then every cycle in G has even length.
Proof. Let C = a1 , a2 , a3 , . . . , am , a1 be a cycle of G and consider any 2-coloring
of G. These colors must alternate around the cycle, so the cycle has to be of
even length.
Theorem 4.8. A connected graph G is bipartite if and only if it contains no
cycles of odd length.
Proof. We just proved that if G is bipartite then every cycle has odd length.
We now prove the converse.
Suppose that G contains no cycles of odd length. Let T be a spanning tree
for G, and suppose we have a 2-coloring of T . We need to show that this will
also be a two coloring of G.
Suppose that it is not. That is, there are vertices u, v that are assigned the
same color in T but that are adjacent in G. Let P be the path in T from u to
v. Then P alternates between the two colors and so is of even length. However,
then P , together with the edge {u, v}, gives a cycle of odd length in G. This
is a contradiction. Hence the 2-coloring of T is also a 2-coloring of G and the
graph is bipartite.
Corollary 4.9. A graph G (not necessarily connected) is bipartite if and only
if it contains no cycles of odd length.
5
Eulerian walks
Definition 5.1 (Eulerian walk/circuit). A eulerian walk is a walk that uses
edge exactly once. A eulerian circuit is a circuit (closed walk) with the same
property.
Example 5.2 (Seven Bridges of Königsberg). A famous early problem in graph
theory was based on the geography of the city of Königsberg, Prussia (now
Kaliningrad, Russia). The city is spread over two islands which are joined
together and with the mainland by seven bridges. Mathematicians of the time
sought to discover whether it is possible to construct a route which crosses each
bridge once (that is, a Eulerian walk). The solution, by Leonhard Euler in 1736,
is considered the first theorem of graph theory.
11
Figure
9:
Three
ways
of
viewing
the
city
of
Königsberg
and
the
seven
bridges
problem
(graphic
from
http://en.wikipedia.org/wiki/Seven Bridges of Königsberg).
Theorem 5.3. An Eulerian walk exists if and only if at most two vertices of
the multigrahp are of odd degree. An eulerian circuit in a connected graph exists
if and only if all vertices have even degrees.
Definition 5.4 (Eulerian graph). A graph G is called Eulerian if it has an
Eulerian circuit.
Theorem 5.5. A graph G has an Eulerian trial if and only if it has at most
2 vertices with odd degrees. G is Eulerian if and only if every vertex has even
degree.
Proof. We begin with an observation: Let G be a graph and suppose that every
vertex in G has even degree. If we remove a cycle C from G, then vertices of
the connected components of {G − C} will also have even degrees
The algorithm is thus: find a cycle, remove it, and construct by induction an
Eulerian circuit in each connected component of G − C beginning with a vertex
in C. Combining these circuits, construct an Eulerian circuit in G.
v2
•A
}} AAA
}
AA
}
AA
}}
}}
•A
•
AA
}
AA
}}
}
AA
}
A }}}
•
v1
Figure 10: Construct a path beginning from one vertex with odd degree (v1 )
and ending at the other (v2 ).
If G has exactly two vertices of odd degree, then begin with a vertex of
odd degree. If on the way we get a cycle C, remove C and apply induction to
construct an Eulerian trial in G − C Otherwise we come to the second vertex
with odd degree, constructing path P . Connected components of {G − P } are
Eulerian graphs.
12
Fleury Algorithm. We begin in an arbitrary vertex. At each step, we move
across an edge whose deletion doesn’t result in more than one connected component unless we don’t have a choice. Then we delete this edge from G and
adjoin it to the Eulerian circuit. At the end of the algorithm there are no edges
left.
An Euler circuit in a digraph (directed graph) is a directed circuit that uses
each edge once.
Lemma 5.6. A digraph G = (V, E) has an Eulerian circuit if and only if it is
weakly connected:
∀v ∈ V : deg + (v) = deg − (v)
Example 5.7. If in a digraph G there exists a walk from u to v then there
exists a path from u to v. If there exists a path from u to v and from v to w
then there exists a path from u to w. This is an equivalence relation (Theorem
1.4).
Every G is a union of disjoint strongly connected components.
/•
O
/•
O




/•
•
/•
O




/•
•
•O
Figure 11: An example of a graph with two clearly delineated connected components.
Definition 5.8 (Component graph). Once we have the strong components of G,
we can construct the component graph. This has one vertex for each strong
component and an edge between two vertices if the corresponding components
are connected by an edge.
Definition 5.9 (Acyclic digraph). An acyclic digraph is a digraph without
cycles
Definition 5.10 (Sink, source). A sink is a vertex with zero out degree. A
source is a vertex with zero in degree.
Example 5.11. An acyclic digraph has a sink and a source.
Proof. Let P be the longest path, then if P goes from u to v, then u is a source
and v is a sink. There does not exist a path from w ∈
/ P to u, because then
some other path {P + w}.
/•
•
Figure 12: The component graph corresponding to Figure 11
13
6
Hamilton paths/cycle
Definition 6.1. A Hamilton path is a path that uses all vertices of the graph
(exactly once). A Hamilton cycle is a cycle that uses all vertices exactly once.
The decision problem to determine if G has a Hamilton path is NP-Complete.
Definition 6.2 (Hamiltonian). A graph is called Hamiltonian if it has a
Hamilton cycle.
Example 6.3 (Hamilton, 1865). The dodecahedron graph is hamiltonian (Figure 13). In fact, all the platonic solids (the cube, octahedron, dodecahedron,
tetrahedron, and icosahedron) are hamiltonian.
Figure 13: A graph of the dodecahedron and its hamiltonian path (graphic from
http://en.wikipedia.org/wiki/Hamiltonian path).
Example 6.4. Every complete graph is hamiltonian.
Theorem 6.5 (Ore, 1960). If G is a graph of order n ≥ 3 such that for all
pairs of distinct nonadjacent vertices x and y, deg(x) +deg(y) ≥ n, then G is
hamiltonian.
Proof. Suppose the result is not true. Then there exists a maximal nonhamiltonian graph G of order n ≥ 3 that satisfies the conditions of the theorem. That
is, G is non-Hamiltonian, but for any pair of nonadjacent vertices x and y in G,
the graph G + xy is Hamiltonian. Since p ≥ 3, the graph G is not complete.
Now consider H = G + xy. The graph H is hamiltonian and, in fact, every
hamiltonian cycle in H must use the edge from x to y. Thus, there is an x − y
hamiltonian path P : x = v1 , v2 , . . . , vh = y in G. Now, observe that if
vi ∈ N (x), then vi−1 ∈
/ N (y), or else (see Figure 6).
v1 , vi , vi+1 , . . . , vh , vi−1 , vi−2 , . . . , v1
would be a hamiltonian cycle in G Hence, for each vertex adjacent to x, there
is a vertex of V − {y} not adjacent to y. But then, we see that deg(y) ≤
(n − 1) − deg(x). That is, deg(x) + deg(y) ≤ n − 1, a contradiction.
14
Figure 14: The path P and possible adjacencies.
it.
We now state an immediate corollary of Ore’s theorem that actually preceded
Corollary 6.6 (Dirac, 1954). If for all vertices of the graph G with n ≥ 3,
deg(v) ≥ n/2 then G is Hamiltonian.
Following Ore’s theorem, a stream of further generalizations were introduced. This line of investigation culminated in the following work of Bondy
and Chvátal. The next result stems from their observation that Ore’s proof
does not need or use the full power of the statement that each nonadjacent pair
satisfies the degree sum condition.
Theorem 6.7. Let x and y be distinct nonadjacent vertices of a graph G or
order p such that deg(x) + deg(y) ≥ p. Then G + xy is hamiltonian if and only
if G is hamiltonian.
Proof. If G is hamiltonian, then clearly G + xy is hamiltonian. Conversely, if
G + xy is hamiltonian but G is not, then we proceed exactly as in Ore’s theorem
to produce a contradiction to the degree sum condition.
Example 6.8 (Petersen graph). A famous non-hamiltonian graph, and a counter
example to seemingly everything one can imagine, is the Petersen graph shown
in Figure 6.8
Figure 15: The Petersen graph, shown here with its three-coloring (graphic from
http://en.wikipedia.org/wiki/Petersen graph).
15
Example 6.9 (Tournament). A tournament is a directed graph obtained by
choosing a direction for each edge in an undirected complete graph. For example,
Figure 6.9 is a tournament on 4 vertices. The name tournament originates
/ v2
vO1 B
BB ||>
B|B|
|| BB
|| B v3 o
v4
Figure 16: A tournament in four vertices.
from such a graph’s interpretation as the outcome of some sports competition
in which every player encounters every other player exactly once, and in which
no draws occur; let us say that an arrow points from the winner to the loser. If
player a beats player b, then it is said that a dominates b.
Any tournament on a finite number n of vertices contains a Hamiltonian
path, i.e., directed path on all n vertices (Rédei 1934). This is easily shown
by induction on n: suppose that the statement holds for n, and consider any
tournament T on n + 1 vertices. Choose a vertex v0 of T and consider a directed
path v1 , v2 , . . . , vn in T \{v0 }. Now let i ∈ {0, . . . , n} be maximal such that
vj → v0 for all j with 1 ≤ j ≤ i. Then v1 , . . . , vi , v0 , vi+1 , . . . , vn is the directed
path as desired.
Similarly, any strongly connected tournament on n ≥ 3 vertices contains
cycles of length 3, . . . , n. As a corollary, a tournament is strongly connected if
and only if it has a Hamiltonian cycle (Camion 1959).
T his example f rom :
http : //en.wikipedia.org/wiki/T ournament %28graph theory%29
7
Planar Graphs
Definition 7.1. A graph is planar if it can be drawn on the plane such that
no two edges cross.
Example 7.2. K4 is planar, K3,3 is non-planar, K5 is non-planar.
We prove that K3,3 (complete bipartite graph) is non-planar. Suppose
{v1 , v2 , v3 } and {v4 , v5 , v6 } is a partition of V (G) such that each vertex from
the first set is adjacent to each vertex from the second set.
In any planar representation of K3,3 , the vertices v1 and v2 must be connected to both v4 and v5 . These four edges form a closed curve that splits the
plane into two regions R1 (the outside region) and R2 (the inside one). The
vertex v3 is in either R1 or R2 . When v3 is in R2 , the edges between {v3 , v4 }
and {v3 , v5 } separate R2 into two regions R21 and R22 . Now there is no way to
place v6 without forcing a crossing. A similar argument can be used when v3 is
in R1 .
16
Planar graphs are important because: 1. Many networks are designed to be
planar (ex. roads); 2. Many algorithms are much faster on planar graphs.
Theorem 7.3. Any planar graph has a planar drawing such that each edge is
a straight line.
Note that a planar drawing divides the plane into regions known as faces
(the exterior region is also counted). The boundaries of faces are edges.
Theorem 7.4 (Euler formula). If r, |E|, |V | are, respectively, the number of
regions, edges and vertices of a connected planar (simple) graph, then r + |V | −
|E| = 2.
Proof. By induction on e.
If |E| = 0 then |V | = 1, r = 1, |V | + r = 2.
Assume the statement of the theorem is true for graphs with fewer than
|E| edges. If G has no cycles, then G is a tree with |E| + 1 vertices, r = 1
and the statement is true. Let G have a cycle C and e be any edge in C. Let
G0 = G − e. The graph G0 is connected and planar with one less edge than G.
So by induction r0 + |v 0 | − |E 0 | = 2. Since r = r0 + 1, |V | = |V 0 |, |E| = |E 0 | + 1,
the formula is proved.
If the graph has too many edges it probably isn’t planar.
As an example of an application, it has been known for millenia that there
are only platonic solids - these are the unique k-regular (k > 2) planar graph in
which all faces have degree s, where
(k, s) = {(3, 3), (3, 4), (3, 5), (4, 3), (5, 3)}
. Indeed, we combine the Euler formula with the formula for the degrees of
regions : 2|E| = sr and handshaking lemma 2|E| = k|V |, and obtain 2/s +
2/k − 1 = 2/|E|. Since s > 2, and the lefthand side cannot be negative, we have
the result.
Theorem 7.5. In a connected planar simple graph |E| ≤ 3|V |−6, when |V | ≥ 3.
Proof. The proof is based on the concept of the degree of a region, which is
defined to be the number of edges on the boundary of this region. When an
edge occurs twice it contributes 2 to the degree.
A connected planar simple graph drawn in the plane divides it into regions,
say r of them. The degree of each region is at least 3. (The degree of the
unbounded region is at least 3 since there are at least 3 vertices. It follows that
X
2|E| =
deg(R) ≥ 3r.
all regions∈R
Hence
(2/3)|E| ≥ r.
17
Using Euler’s formula r = |E| − |V | + 2 we obtain
|E| − |V | + 2 ≤ (2/3)|E|.
It follows that
|E|/3 ≤ |V | − 2.
Corollary 7.6. K5 is not planar.
Indeed, K5 has 5 vertices and 10 edges, these numbers don’t satisfy the
inequality in Theorem 7.5.
Definition 7.7 (Elementary subdivision, homeomorphic). If a graph os planar,
so will be any graph obtained by removing an edge {u, v} and adding a new
vertex w together with edges {u, w} and {w, v}. Such an operation is called
an elementary subdivision. Two graphs are homeomorphic if they can be
obtained from the same graph by a sequence of elementary subdivisions.
Theorem 7.8 (Kuratovski). A graph is non-planar if and only if it contains a
subgraph homeomorphis to K3,3 or K5 .
The proof is too complicated to be presented in this course.
There exists a polynomial time algorithm to check if the graph is planar
[Hopcroft and Tarjan, 1974].
8
Coloring Planar Graphs
The most famous result in graph coloring is the f our color theorem:
Theorem 8.1 (Appel & Haken, 1976). Any map (which can be represented as
a planar graph) can be colored using 4 colors.
Equivalently, χ(G) ≤ 4 for any planar G.
Appel and Haken showed that if the four-color theorem were false, there
would have to be a counterexample of approximately one of 2000 different types.
The rest of the proof is done by a computer.
Theorem 8.2. χ(G) ≤ 5 for any planar graph G.
Proof. Let|V | ≥ 5. Use induction on |V |. Take a straight line representation of
G. Since |E| ≤ 3|VP
| − 6, there is a vertex v with at most 5 neighbors v1 , . . . , v5
(otherwise 2|E| = v∈V deg(v) ≥ 6|V |). So G − v has a 5-coloring. If v1 , . . . , v5
are colored with only 4 colors, then the other color may be used for v. So
suppose that v1 , . . . , v5 are colored by colors 1,. . . ,5.
(i) Suppose there is no path P in G from v1 to v3 whose vertices are alternatively colored by 1 and 3.
Switch the colors 1 and 3 for v1 and all the alternating 1-3 paths beginning
at v1 . This is a valid coloring. Since there is no such path ending at v3 , the
18
color of v3 remains the same (color 3). Now v1 gets color 3, and we can use
color 1 for v.
(ii) If there is a 1-3 path from v1 to v3 , then there is no 2-4 path from v2
to v4 because the graph is planar. The previous argument can be used for v2 ,
v4 .
This gives a simple algorithm to 5-color a planar graph.
First we consider the algorithm to 6-color.
1. Pick a vertex of degree ≤ 5, call it vn .
2. Find a vertex of degree ≤ 5 in G − vn , call it vn−1 .
3. Repeat.
4. Color the vertices in the order v1 , . . . , vn using the greedy algorithm.
Since any vertex has ≤ 5 neighbors before it it this ordering, we use at most 6
colors.
The algorithm runs in O(|E|) = O(|V |) time.
To 5-color we just need to add the procedure that includes the color-switching
operation in the proof.
9
Bipartite graphs:
Edge coloring and matchings
Definition 9.1 (Edge coloring). A function E(G) → {1, 2, . . . } is called an
edge coloring if two edges with a vertex in common don’t receive the same
coloring.
If δ(G) = maxv∈G {deg(v)} then we need at least δ(G) colors.
Example 9.2. K4 needs 3 colors for edge coloring.
•@ α •
@@ 
 γ
γ
β @@
 @
• α •
Example 9.3. Peterson’s graph requires more colors than δ(G) for edge coloring.
Theorem 9.4. If G = (X ∪ Y, E) is a bipartite graph, then the minimal number
of colors needed for edge colorings of G equals δ(G)
Proof. We proceed by induction on |E|.
The trivial case |E| = 1 is true.
Let |E| > 1, remove an edge (x, y). Let δ(G) = k.
δ(G − {(x, y)}) is either k or k − 1.
If δ(G − {(x, y)}) = k − 1, then by induction it has an edge coloring with
k − 1 colors and we can use color k for (x, y).
19
Suppose δ(G − {(x, y)}) = k. Fix an edge coloring for G − {(x, y)} with k
colors. If there exists a color α not used on x and not used on y, we can color
(x, y) by α.
Suppose not, in any case deg(x) ≤ k − 1 and deg(y) ≤ k − 1 in G − {(x, y)}.
Let α be the color not used on x and β the color not used on y.
Let (x, y1 ) be the edge colored by β. If α is not used on y1 , we stop, else
if α is used, suppose (x1 , y1 ) has color α. If β is not used on x1 , we stop, else
suppose (x1 , y2 ) as color β.
xB
BBB
y
βB
BB
x1 B α y1
BB
βB
BB
x2 α y2
Finally we stop. We have a path:
x
α
y1
β
x1
β
y2
α
x2
β
y2
yk
Switch the colors in this path.
y
xB β
BB
B
αBB
BB
x1 B β y1
BBB
αBB
BB
x2 β y2
We can now assign (x, y) the color β.
Definition 9.5 (Latin square). A latin square is a square table with rows
r1 , r2 , . . . , rk and columns c1 , c2 , . . . , ck such that each entry contains a symbol
s1 , s2 , . . . , sk and each row and each column contains each symbol exactly once.
Example 9.6.
r1
r2
r3
c1
s2
s3
s1
c2
s3
s1
s2
c3
s1
s2
s3
One solution to find a latin square is to edge color the corresponding bipartite
20
graph:
or
r10 B s2 c1
00BBB ||
00 ||B|BB
|
|
| 00 B
r2 B 00 c2
BB 0|0|
B|
|||BBB000
B
|
|
r3 s3 c3
s10 B r3 c1
00BBB ||
00 ||B|BB
|
||00 B
s2 B 00 c2
BB 0|0|
B|
|||BBB000
|| B
s3 r3 c3
Definition 9.7 (Latin rectangle). A latin rectangle (m < n). Each row
contains each symbol only once and no symbol occurs more than once in a
column.
Example 9.8 (A 3 by 5 latin rectangle).
r1
r2
r3
c1
s1
s5
s2
c2
s2
s1
s3
c3
s3
s4
s1
c4
s4
s3
s5
c5
s5
s2
s4
Theorem 9.9. Every latin rectangle can be extended to a latin square.
Proof. We form a bipartite graph with edges connecting symbols with columns:
G = (S ∪ C, E), E = {si cj : symbol si doesn’t appear in column j}
Example 9.10 (for the example rectangle).
s1(+
c1
(+(+
((++
((++ s20 B( + c2
00B(B( +B+ +
00((B++BB
0(0( ++B
s30 (0(0 + c3
00 ((00++
00 ((00++
00 (( 0+
s4 00 (( c4
00 ((
00 (
0(
s5
c5
21
Max deg(G) = δ(G) = n − m, because each column contains m symbols and
thus doesn’t contain n − m.
G is regular bipartite δ(G) = n − m. By theorem 9.4, the edges can be
colored by n − m colors.
Completing a partial latin rectangle
Suppose we have a table of m rows and p columns filled in with symbols from
{s1 , . . . , sn }; p, m < n such that no symbol occurs more than once in a row and
in a column.
Question: When can such a rectangle be completed to a n by n square?
Example 9.11 (Of a rectangle that can not be completed).
B occurs too few times to complete the square.
A
C
E
C
E
A
D
A
C
E
B
D
Theorem 9.12. Let R be a partial m × p latin rectangle in which the symbols
s1 , . . . , sn are used and let nR (si ) denote the number of times si occurs in R.
(1 ≤ i ≤ n)
R can be completed to an n × n latin square if and only if nR (si ) ≥ m + p −
n (∀i = {1, . . . , n}).
Proof. Suppose R can be completed. Then there are n − m rows and n − p
columns to be filled in.
n ≤ (n − p) + (n − m) + nR (si )
m + p − n ≤ np (si )
Now suppose the inequality holds. Construct a bipartite graph G = {rows ∪
S, E}. E = {ri sj : sj is not used in ri }. Each symbol si occurs at least m + p − n
times and each occurrence is in a different row.
deg(si ) = m − (m + p − n) ≤ n − p
Every row contains p different symbols, thus n−p are not used, and deg(ri ) =
n − p. So δ(G) ≤ n − p and there exists an edge coloring of G with n − p colors
cp+1 , cp+2 , . . . , cn .
If ri sj ∈ E and colored with ck (p + 1 ≤ k ≤ n), then we put sj in row rj
and columns ck . Thus gives m × n latin rectangle, which can be completed to
a latin square by Theorem 9.9.
Example 9.13. Find all values of Q ∈ {A, B, C, D, E, F } such that rectangle
R can be extended to a 6 × 6 latin square.
A B C D
F E A B
R1 :
C D F A
D A B Q
np (x) ≤ m + p − n = 4 + 4 − 6 = 2 ⇒ Q = E
22
To complete the rectangle:
A
F
B
D
R2 :
10
B
E
D
A
C
A
F
B
r1&'
A
&'&'
&&''
&'
r20 A&&''
B
00&A& 'A' A }}
0&&0''}}A}AA
}
}}&&0'0' A
r30 && 0''0 C
00 && ''0}0}
00 }}&& }'' 00
}
}
} 00 && ' 0
r40 00&& ''' D
00 0&0& '
00 &00''
00 && 0'
00 && E
00 &&
00 &&
0&
F
D
B
There does not exist a value of Q
A
Q
Matchings and Bipartite Graph
Definition 10.1 (Matching, Perfect matching). A matching in a graph is a
disjoint set of edges. A perfect matching is a matching which covers all the
vertices.
Consider the following problem: There is a set of people X and a set of jobs
Y such that each person is qualified to do exactly k jobs and for each job there
exists exactly k people who are qualified to do it.
Prove that:
1: |X| = |Y |
2: For any subset of n people in X, there exists at least n jobs which they
are qualified to do.
Proof. 1:
|E| =
X
deg(x) =
x∈X
X
deg(y)
y∈Y
|E| = k|X| = k|Y | ⇒ |X| = |Y |
Proof. 2: If A ⊆ X, J(A) = {y ∈ Y : ∃x ∈ A, (x, y) ∈ E} the set of jobs for
which people from A are qualified.
23
Let |A| = n, show |J(A)| ≥ n. There are nk edges with one vertex in A. All
these edges have one vertex in J(A).
The total number of edges with one vertex in J(A) is k|J(A)|.
nk ≤ k|J(A) ⇒ |A| ≤ |J(A)|
Definition 10.2 (Maximal matching). A matching is maximal if there does
not exist a matching with more edges.
Definition 10.3 (Complete matching). A matching is complete if |M | = |X|
(all people get jobs).
Example 10.4. A complete matching does not exist for G with 3 people and
2 jobs.
Theorem 10.5 (Hall). A bipartite graph G = (X ∪ Y ) has a complete matching
if and only if
∀A ⊆ X, |J(A)| ≥ |A|.
Proof. Suppose a complete matching exists, then:
∀A ⊆ X, |J(A)| ≥ |A|.
Now suppose that Hall’s condition is satisfied. Let M be an incomplete matching, we will construct M 0 such that |M 0 | = |M | + 1. There exists x0 ∈ X such
that x0 is unmatched. |J({x0 }) ≥ 1. There exists y1 adjacent to x0 .
If y1 is unmatched then M 0 = M ∪ (x0 , y1 ). Suppose y1 is matched to x1 .
|J({x0 , x1 }| ≥ 2 and there exists y2 such that |J({x0 , x1 }) ⊇ {y1 , y2 }
If y2 is unmatched, we stop. Otherwise continue . . .
x0
x1
x2
∈M
/
y1
∈M
/
y2
∈M
/
y3
|
||
∈M
|
||
|
||
∈M
|
||
We eventually stop, we have constructed a path:
x0
∈M
/
y1
∈M
x1
∈M
/
y2
∈M
x2
∈M
/
y2
such that (yi , xi ) ∈ M and (xi+1 , yi ) ∈
/ M.
M 0 = M − (yi , xi ) ∈ M + (xi+1 , yi ) ∈
/M
|M 0 | = |M | + 1
24
yn
The algorithm from the proof:
Begin with an arbitrary matching M .
If it is not complete, construct M 0 .
If M 0 is not complete, find an alternating path to construct (M 0 )0 and so on.
Corollary 10.6. A bipartite graph G has perfect matching if and only if:
∀A ⊆ X, B ⊆ Y
|J(A)| ≥ |A|&|J(B)| ≥ |B|
Definition 10.7 (Deficiency). A deficiency of a bipartite graph is:
d = maxA⊆X {|A| − |J(A)|} ≥ 0.
We remark that the emply set is a subset of X, os d ≥) in all the cases.
Theorem 10.8. A maximal matching for a bipartite graph G = (X ∪ Y, E) has
size |X| − d.
Proof. Consider a set Z of cardinality d and let
G∗ = (X ∪ Y ∗ , E ∗ )
Y∗ =Y ∪Z
E ∗ = E ∪ {(x, z) ∀x ∈ X, ∀z ∈ Z}
Let A0 be the subset of X such that d = |A0 | − |J(A0 )|. Let M be a complete
matching for G∗ (G∗ satisfies the Hall condition.)
Then (M − the edges in M \ E) = M 0 . M 0 is a maximal matching for G.
|M 0 | = M − d = |X| − d.
M 0 is maximal because d people from the set A0 are not satisfied without
jobs in Z.
To verify Hall’s condition, one has to check 2|X| subsets which takes exponential time. But there exists a polynomial algorithm to construct a maximal
matching (not necessarily in a bipartite graph).
Theorem 10.9. If M is not a maximal matching in G = (X ∪ Y, E), then there
exists an alternating path.
Proof. Suppose there exists M ∗ of greater cardinality than M . Let H be a
subgraph of G formed by edges that belongs to M or M ∗ but not both.
Each vertex has degree 1 or 2 initially. Connected components of M are
either alternating paths or alternating cycles. Each cycle contains the same
number of edges in M and M ∗ ⇒ there exists an alternating path.
25
The algorithm:
We begin at some unmatched vertex x0 .
G = (X ∪ Y, E), X = {x1 , . . . , x5 } Y = {y1 , . . . , y5 }
We have an adjacency table:
x1
y1
y3
x2
y1
y3
x3
y1
y3
y5
x4
y2
y4
y5
x5
y3
y4
M = {(x1 , y3 ), (x2 , y1 ), (x3 , y5 ), (x4 , y4 )}
Begin at some unmatched x0 :
1: In level 1, insert all ys adjacent to x0 . If one of the y’s (yi ) is unmatched,
then we found the alternating path: (x0 , yi ).
2: If all ys at level 1 are matched, insert corresponding x’s.
3: Insert all the new y’s adjacent to x’s at level 2. If one of the y’s is
unmatched, then the path is alternating.
x5
y3
y4
x1
x4
y1
y2
y5
If at some odd numbered level, there do not exist new y’s to insert, then
there does not exist an alternating path from x0 . But we have to try all other
unmatched x’s. If there does not exist an alternating path from any of them,
then M is maximal.
M 0 = {(x1 , y3 ), (x2 , y1 ), (x3 , y5 ), (x5 , y4 ), (x4 , y2 )}
11
Transversals for families of finite sets
Example 11.1. There are 4 committes in a university math department:
Teaching: {M, A}
Research: {M, B}
Admin: {M, A, B}
Car Parking {C, D, E}
We want to form the committee for committees, which consists of one different person from each committee. Construct a complete matching:
M = {(T, A), (R, B), (Adm., M ), (Car, C)}
26
Definition 11.2 (Transversal). In general, let ∪i∈I Si be a finite family of finite
sets. A complete set of representatives:
{si : i ∈ I, si ∈ Si }
i 6= j → sj 6= sj
is called a transversal for a family of finite sets.
Theorem 11.3. Hall’s condition implies there exists a transversal for the family
{si , i ∈ I} if and only if:
∀A ⊆ I, |A| ≤ | ∪i∈A Si |
12
Applications of trees
Definition 12.1 (Rooted tree). A rooted tree is a tree with a vertex designated as the root. Every edge is directed from the root.
Definition 12.2 (Parent, Child, Sibling). v is a parent of child u if it is the
vertex directly above u in the tree. Siblings are children of the same parent.
Definition 12.3 (Internal vertex). Internal vertices are vertices with children.
Definition 12.4 (Ancestor, Descendant). The ancestors of u are all the vertices in the path from u to the root. The descendants of u are all the vertices
for which u is an ancestor.
Definition 12.5 (Subtree). A subtree originating at u is u and all its descendants.
Definition 12.6 (M-ary, Full m-ary, Binary). Tree T is called an m-ary tree
if every internal vertex has at most m children. A full m-ary tree has exactly
m children of each internal vertex. If m = 2, then T is called a binary tree.
Binary trees have left subtrees and right subtrees; vertices in binary trees have
left children and right children.
Definition 12.7 (Height). The height of the tree is the maximal level of
vertices.
Lemma 12.8. There exist at most mh leaves in an m-ary tree of height h.
Corollary 12.9.
h ≥ dlogm le
If the tree is full and balanced (every leaf has height h or h−1), then h = dlogm le.
27
Proof.
l
=
mh
logm l
≤
h
l
>
mh−1
h − 1 < logm l ≤ h ⇒ h = dlogm le
Example 12.10 (The false coin). There exists one genuine coin labelled 0 and
r other coins labeled by 1, . . . , r.
One of these r coins is false and must be heavier or lighter than the others.
One needs at least log3 (2r + 1) weightings on a balance scale to determine
if all the coins are good or one is heavier/lighter than the others.
Proof. There exist 2r + 1 outcomes: {G, 1H, 1L, . . . , }. We form a ternary tree
with each of the outcomes as a leaf. By Lemma 12.8, h ≥ dlog3 (2r + 1)e.
0, 1 : 2, 3 WW
WWWWW
gggg
g
g
g
WWW
g
g
g
=
>WWWW
ggg<
WWWWW
g
g
g
g
g
WWW+
g
g
sgg
2 : 3E
2 : 3F
0 : 4J
EEE
FFF
JJJ
xxx
yyy
ttt
x
y
t
=
=
=
<
>FF
>
<
>EE
<
J
J
t
x
y
EE
FF
JJ
|xxx
zttt
|yyy
"
"
$
3H
1L
2H
4H
G
4L
3L
1H
2L
Figure 17: The solution tree for the false coin problem with r = 4 that uses two
weightings.
Example 12.11. To sort 3 numbers {a, b, c} with comparisons, we can construct a binary tree.
h ≥ dlog2 6e ⇒ h ≥ 3
Example 12.12. Sort the following words in alphabetical order: {math, physics,
28
a:c
pp
ppp
a>b
p
p
pw pp
pp
ppp c>b
a>c>b
a<b
b : c NN
NNN
a>c
pa>c
p
wppp
a>b>c
a:b
b>a>c
a<cNN
NNN
'
a<c<b
Figure 18: The comparison tree to sort three numbers a, b, and c
geography, biology, meteorology, geology, psychology, chemistry}.
math PP
PPP
PPP
PPP
P
physicsP
geography
PPP
ppp
PPP
p
p
p
PPP
pp
p
P
p
p
biology
geology
meteorology
psychology
chemistry
Following the tree from left to right gives the sorted order: {biology → chemistry → geography → geology → mathematics → meteorology → physics →
psychology}.
Every vertex has a key, for every vertex all the keys of the left subtree are
less than the keys of this vertex, and all the keys of the right subtree are greater
than the key of this vertex.
For all children, it is known if this is a right or left child.
Lemma 12.13.
1. A full m-ary tree with i internal vertices has n = mi + 1 vertices.
2. A full m-ary tree with n vertices has i =
n−1
m
internal vertices.
3. A full m-ary tree with i internal vertices has l = (m − 1)i + 1 leaves.
4. A full m-ary tree with l leaves has n =
ml−1
m−1
Proof. 1: Every vertex is a child except the root.
1⇒2
3: n = i + l mi + 1 = i + l ⇒ (m − 1)i + 1 = l
29
vertices and i =
l−1
m−1 .
13
Complexity of sorting algorithms based on
binary comparisons
The worst case complexity is h ≥ dlog2 (n!)e(n! leaves).
log(n!)
= θ(nlogn)
n! ≤
log(n!) ≤
⇒ log(n!)
nn
nlogn
= O(nlogn)
One can also show that log(n!) = Ω(nlogn)
Theorem 13.1. The worst case complexity for any binary comparison based
sorting algorithm is Ω(nlogn).
14
Prefix codes
Encode letters by binary strings of different lengths.
1. A code for one letter should not be a prefix of a code for a different letter
(if we code a by 0, b by 1, and c by 01, then 01 could be interpreted as
’ab’ or as ’c’).
2. Letters that occur frequently should be encoded by shorter strings.
Huffman coding
We know the probabilities of the occurrences of each letter (divide the number
of occurrences of letter by the length of the sequence).
Huf f man
Begin with a forest consisting of isolated vertices label by each letter.
1 while T is not a tree
2
Replace the rooted trees T1 and T2 of least weights with a tree of new root
that has T1 and T2 as its left and right subtrees where w(T1 ) > w(T2 ).
3 The label of each leaf is the label of the path from the root to that leaf
30
Example 14.1. Given a set of letters with probabilities {A : .08, B : .10, C :
.12, D : .15, E : .20, F : .35}, we construct the Huffman code as follows:
Step 1:
.18 H
HH
vv
HH
v
HH
vv
v
HH
v
v
v
B : .10
A : .08
Step 2:
.27 H
HH
HH
HH
HH
C : .12
vv
vv
v
vv
vv
B : .10
.27 H
HH
HH
HH
HH
C : .12
.38 H
HH
HH
HH
HH
.18 H
E : .20
HH
vv
HH
v
HH
vv
v
HH
v
v
v
B : .10
A : .08
.62 H
HH
HH
HH
HH
.27 H
F : .35
HH
v
HH
vv
v
HH
v
v
HH
v
vv
D : .15
C : .12
.38 H
HH
HH
HH
HH
.18 H
E : .20
HH
v
HH
vv
v
HH
v
v
HH
v
vv
B : .10
A : .08
vv
vv
v
vv
vv
D : .15
.18 H
HH
HH
HH
HH
A : .08
Step 3:
v
vv
vv
v
v
vv
D : .15
Step 4:
Final Tree:
jj 1.00 KKKK
jjjj
K
j
j
1KKK
jjj0
j
KK
j
j
jjj
.62 H
.38 H
HH
HH
H
H
0
1HH
0
1HH
HH
HH
.18 H
.27 H
F : .35
E : .20
HH
HH
vv
vv
H
H
v
v
v
v
1HH
0
1HH
0
v
v
HH
HH
v
v
v
v
v
v
D : .15
C : .12
B : .10
A : .08
The complete code is therefore:
{A = 111, B = 110, C = 011, D = 010, E = 10, F = 00}
31
15
Depth First Search
DFS(G)
G is a connected graph with vertices v1 , . . . , vn
1 T = tree consisting only of v1
2 visit(v1 )
visit(v, T )
v is a vertex in a graph, T a tree
1 for each w adjacent to v and not yet in T
2
do Add w to T and add (v, w) to T
3
visit(w)
For every v, the procedure visit(v) is called only once, when v is first
encountered. Every edge is considered at most twice. The complexity is thus
O(e) = O(n2 ).
16
Breath First Search
BFS(G)
G is a connected graph with vertices v1 , . . . , vn
1 T = tree consisting only of v1
2 L = a list, initially empty
3 Add v1 to L
4 while L is not empty
5
do Remove the first vertex from L
6
for each neighbor of v
7
if w is not in T and not in L
8
do Add it to the end of L
9
Add w and (v, w) to T
The complexity of breath first search is O(|E|).
Example 16.1.
a
b
c
d
e
f
i
h?
??
??
??
?
m
k
j
32
l
g
a
e >NNN
>> NN
>> NNN
>> NNN
NNN
>
f <
i N<NN d
<< NNN
<<
<< NNN
<<
<< NNN
<<
<
NNN
<
g
j
h
k
b
c
m
l
L = {e, b, f, i, d, a, c, g, j, h, k}
T = {(e, b), (e, f ), (e, i), (e, d), (b, a), (b, c), (f, g), (f, j), (g, l), (i, h), (i, k), (k, m)}
17
Minimum Spanning Trees
Definition 17.1 (Minimum Spanning Tree). A minimum spanning tree in
a connected, weighted graph is a spanning tree with minimum possible weight
(the minimum sum of weights of edges).
Example 17.2.
2000
1200
1000
Chicago
SF I
NY C
MMM
r
II
MMMrrrr
II900
1600
II 1300 rrr MM 800
II
700
MM
rrr
Denver 1400 Atlanta
2200
The minimum spanning tree for the above graph consists of the four edges:
{(Chicago, Atlanta), (N Y C, Atlanta), (SF, Denver), (SF, Chicago)}.
1200
Chicago
SF I
NY C
MMM
II
MMM
II900
II
800
M
II
700 MMM
Denver
Atlanta
Kruskal’s Algoritm
1 Begin with an edge of minimal weight
2 Successively add edges with minimal weight that do not
form a cycle with the edges that have already been added.
3 Stop after n − 1 steps.
33
It’s easy to show that the complexity of Kruskal’s Algorithm is O(n · logn).
But we can improve the bound to O(n · log∗ n), where log∗ n = M denotes the
iterated logarithm such that log(log(. . . log(n))) ≤ 1.
|
{z
}
M
18
Disjoint Sets
We have a collection of disjoint sets. Each set is identified by a unique representative.
Y
X
y
x
z,
Z
Our data structure will have the following operation:
i) Make-Set(v): Creates a singleton set with the element v.
ii) Find-Set(v): Find the set that v is contained in i.e. find the representative
of the set cpntaining v.
iii) Merge(x, y): Merge the two sets that contain x and y
Applications:
• Kruskal’s algorithm for Minimum Spanning Trees
• Equivalence Classes
• Computer Vision (pixelized pictures)
Parent Pointer Sets: We store sets as directed trees where nodes point to
their parents:
Text1
So, we get
34
i) Make-Set(v): Makes a node v pointing at itself.
ii) Find-Set(v): Follows a path from v to the root and returns the root.
iii)So,
Merge(x,
we get y): Finds the representatives of the sets containing x and y, say
rep(x) and rep(y) respectively, and either makes rep(x) point to rep(y) or
i) Make-Set(v):
Makes a node v pointing at itself.
vice versa.1
ii) Find-Set(v): Follows a path from v to the root and returns the root.
The bottleneck operation is Find-Set. The runtime of Find-Set depends
iii) Merge(x, y): Finds the representatives of the sets containing x and y, say
on the
path lengths of the trees. So if we can keep the depth of the trees small
rep(x) and rep(y) respectively, and either makes rep(x) point to rep(y) or
then the
are fast.
viceoperations
versa.1
Trick
1.bottleneck
On merging,
we merge
the “shallower”
into thedepends
“deeper” tree.
The
operation
is Find-Set.
The runtimetree
of Find-Set
onWe
the give
path lengths
of the vtrees.
So ifρ(v).
we canInitially
keep the ρ(v)
depth =
of height(v)
the trees small
every node
a rank
= maximum
then thefrom
operations
fast.
distance
v to aare
leaf
node. The rank of a node doesn’t change when we perform
the1.second
trick (path
compression)
below.
When
preform
Make-Set(x)
Trick
On merging,
we merge
the “shallower”
tree into
the we
“deeper”
tree.
we set
0. node v a rank ρ(v). Initially ρ(v) = height(v) = maximum
Weρ(x)
give =
every
distance from v to a leaf node. When we preform Make-Set(x) we set ρ(x) = 0.
We
Link(x,
follows:
Weperform
perform Link(x,
y)y)
as as
follows:
i) We do:
PSfrag replacements ii) We do:
iii) We do:
x
y
x
y
x
y
if ρ(x) < ρ(y)
if ρ(x) > ρ(y)
if ρ(x) = ρ(y) and we set ρ(y) = ρ(y) + 1
So our Merge-Set(x, y) operation consists of two Find-Set operations folSo our
Merge-Set(x, y) operation consists of two Find-Set operations followed
lowed by Link(rep(x), rep(y)).
by Link(rep(x), rep(y)).
Lemma 1.
Lemma 18.1.
1. The number of nodes in the subtree rooted at v is at least 2 r where r =
ρ(v).number of nodes in the subtree rooted at v is at least 2r where r =
1. The
2. ρ(v).
The number of nodes of rank r is at most
nodes in our forest.
n
2r
where n is the number of
2. The number of nodes of rank r is at most 2nr where n is the number of
Proof.
Byour
induction.
nodes1. in
forest. The statement holds for r = 0. After linking, it is
clearly true for cases i) and ii). In case iii) we see that the new tree has
at least
2r + 2r = 2r+1
. statement holds for r = 0. After linking, it is
Proof. size 1.
By induction.
The
1 We
clearly
true
for cases i)link(rep(x),
and ii). rep(y))
In case iii) we see that the new tree has
shall call
this sub-operation
size at least 2r + 2r = 2r+1 .
1 We
shall call this sub-operation link(rep(x),
rep(y))
2
35
2. Fix some number r. Only set representatives can change their rank.
Whenever the rank of any set representative x changes from r − 1 to
r mark all the objects in x’s. Since representative’s rank can only increase
over time, each object is marked at most once. There exists n objects alltogether, and any object with rank r marks at least 2r objects. It follows
immediately from the preceding part that there are at most n/2r objects
with rank r as claimed.
Corollary 18.2. Each tree has height O(log(n)). So our Find-Set operation
shold run in time O(log(n)).
Trick 2 (Path Compression). After traversing a path during a Find-Set operation, set the parent pointers of the nodes along the path to point the root of
the tree.
r
r
pc
gt
d
i
a
j
b
c
d
j
i
c
g
b
a
h
f
e
g
e
h
f
This multiplies the runtime of the Find-Set by a constant factor2
A way to analyse the effect of path compression is to procede as follows:
First divide the ranks into blocks
[0, b0 ], [b0 + 1, b1 ], . . . , [bi + 1, bi+1 ]
where
b0 = 1
bi+1 = 2bi
Note that there are at most log∗ (log(n)) = log∗ (n)−1 blocks.3 We use amortized
analysis. Suppose we do N operations n of which are Make-Set operations (i.e.
n nodes). The only operation that is not O(1) is Find-Set.
Consider the path we compress at each step:
2 Go along the path once to find the parent and go a second time and at each node along
the way set the pointer to the root, so it should take three times longer.
3 log∗ (k) = M , the least integer such that log log . . . log(k) ≤ 1
|
{z
}
M times
36
c
r
b4
b3
b2
b1
b0
The cost is 2(#red nodes +#grey nodes), where a node x is red if the rank of
its parent is in a higher block.
Observations:
• ρ(x) < ρ(Parent(x))
• ρ(Parent(x)) < ρ(Parent0 (x)) where Parent0 (x) is the parent of x after
path compression.
• ρ(x) never changes once x is not a root. These observations imply that a
red node always stays red.
The highest possible rank is logn. Clearly the cost assigned to red nodes is
at most log∗ (n) for each Find-Set operation as there are at most log∗ (n) red
nodes along a path.
To analyze the total cost assigned to the grey nodes note that
1. A node x in block Bj can change parents at most bj − bj−1 ≤ bj times
before it turns red.
2. By Lemma 18.1, the number if nodes in block j is bounded by
bj
X
i=bj−1 +1
n
n
n
n
≤ bj−1 +1 (1 + 1/2 + 1/4 + . . .) ≤ bj−1 =
i
2
2
2
bj
So the total time spent traversing grey nodes in block Bj is at most bj · bnj = n.4 .
Hence the total time spent on grey nodes over all blocks is at most n log∗ (n).
So overall, the amortized time is O log∗ (n) per operation.
We proved the following result.
4 And this result holds even in N n in particular when all the nodes turn red or become
children of the root
37
Theorem 18.3. Suppose we perform N disjoint set operations, i.e. find-root
and merge operations, on a disjoint set forest containing n nodes. Then path
compression and merging by rank give the amortized running time devoted to
these operations at most O((N + n)log ∗ (n)).
19
Networks & Flows
Definition 19.1 (Network). A network is a diagram with two distinguished
vertices: the source s and the sink t.
Definition 19.2 (Capacity, Flow). C : E → R > 0 is called the capacity of
the edges. F : E → R > 0 is called the flow function.
∀(u, v) ∈ E : f (u, v) ≤ c(u, v)
Example 19.3.
? a ?O?OOO
? OO
1:6?? 2:3OO
3:5
OOO
?
O
s > 2:2 / b 2:4 ?/ d 4:4oo7/' t
>>
o

 ooo
1:7 o2:5
3:3>>

o
> ooo
co
Figure 19: A network, its flows, and its edge capacities.
Definition 19.4 (In-flow, Out-flow).
X
inFlow(v) =
f (x, v)
(x,v)∈E
X
outFlow(v) =
f (v, y)
(v,y)∈E
∀v 6= s, t : inFlow(v) = outFlow(v)
Definition 19.5 (Cut). A cut in a network is a partition of the vertices into
two disjoint parts: S t T = E such that s ∈ S and t ∈ T .
The capacity of the cut is
X
c(u, v).
u∈S
v∈T
(u,v)∈E
38
Definition 19.6 (Value). The value of a flow F is
val(F ) = outFlow(s) = inFlow(t)
The conservation rule, ∀v 6= s, t : inFlow(v) = outFlow(v), implies
X
X
f (u, v)
f (x, y) −
val(F ) =
u∈T
v∈S
x∈S
y∈T
Example 19.7. Continuing from example 19, let S = {a, b, s} and T = {c, d, t}.
val(F )
= F (s, c) + F (a, t) + F (a, d) + F (b, d)
=
3+2+1+2
=
8
Theorem 19.8. For any cut S t T = E,
val(F ) ≤ c(S, T )
Proof. Let S t T = E be a cut.
val(F )
=
X
f (x, y) −
x∈S
y∈T
≤
X
X
f (u, v)
u∈T
v∈S
f (x, y)
x∈S
y∈T
≤
X
c(x, y) = c(S, T )
x∈S
y∈T
Example 19.9. Define a new flow in example 19 as follows:
? a ?O?OOO
? OO
4:5
1:6?? 3:3OO
OOO
?
O
s > 2:2 / b 2:4 ?/ d 4:4oo7'/ t
>>
o

 ooo
1:7 o2:5
3:3>>

> oooo
co
Let path refer to the path in the graph obtained from the network by disregarding edge directions. Then the a path from s to t is:
s
4
5
/a
1
6
/do
39
1
2
c
2
5
/t
Definition 19.10 (Augmenting path, Incomplete augmenting path). A path
s = x1 , . . . , xk−1 , xk = t in the undirected graph corresponding to the network
is called an augmenting path if f (xi , xi+1 ) < c(xi , xi+1 ) and (xi , xi+1 ∈ E)
or f (xi+1 , xi ) > 0 and (xi+1 , xi ) ∈ E).
An incomplete augmenting path is the same as an augmenting path
except that the final vertex is not t.
Denote by
α = min
c(xi , xi+1 ) − f (xi , xi+1 )for(xi , xi+1 ) ∈ E
f (xi+1 , xi )for(xi+1 , xi ) ∈ E
We can define f1 such that val(f1 ) = val(f) + α.
f1 (xi , xi+1 )
= f (xi , xi+1 ) + αfor(xi , xi+1 ) ∈ E
f1 (xi+1 , xi )
= f (xi+1 , xi ) − αfor(xi+1 , xi ) ∈ E
Theorem 19.11 (Min-cut/Max-flow). The maximal value of the flow from s
to t in a network is equal to the minimal value of a cut.
Proof. Let f be a maximal flow. We will construct a cut with the same capacity
as val(f ).
Let s = {v| such that there exists an incomplete augmenting path from s to
v.
T is the rest of the vertices. t ∈ T because there does not exist an augmenting
path from s to t.
For a maximal flow ⇒ S,T is a cut.
X
X
val(f ) =
f (x, y) −
f (z, u)
x∈S
y∈T
z∈T
u∈S
If ∃x∈S such that f (x, y) < c(x, y), then the augmenting path from s to x
y∈T
could be extended to y ⇒ y ∈ S which is a contradiction. Therefore, f (x, y) =
c(x, y).
If ∃u∈S such that f (z, u) > 0, then the augmenting path from s to u could
t∈T
be extended to z, which is a contradiction. Thus,
X
val(f ) =
c(x, y) = c(S, T ).
x∈S
y∈T
20
20.1
Basic Counting Techniques
Product Rule
If a procedure of two tasks and task 1 can be preformed in n1 ways, task 2 in
n2 ways, then there exists n1 n2 ways to preform the procedure.
40
Example 20.1. How many binary strings are there of length 6?
Answer: 26 .
Example 20.2. The number of functions from an m-set (a set with m elements)
to an n-set is nm . Similarly, the number of words of length m in an alphabet of
n letters is also nm .
20.2
Pigeonhole principle
If there exist n pigeonholes and n + 1 pigeons, then there are at least 2 pigeons
in at least one hole.
Example 20.3. In the set of n people, at least 2 people have the same number
of friends within the set.
Proof. If each have friends, then there exist n − 1 possibilities within the set.
Suppose someone doesn’t have any friends. If there are two such people,
we are done, otherwise exclude the loner and consider the problem with n − 1
people.
Example 20.4. In a set of 27 english words, at least two begin with the same
letter.
Lemma 20.5. In pigeon form, if there exist n pigeons and k holes, then there
is at least one hole with dn/ke pigeons.
Example 20.6. In a set of 100 people, what is the least number of people
whose birthdays are in the same month?
Example 20.7. If there are five possible grades, what is the minimal number
of students such that at least four of them share the same grade?
Answer: 16, because d16/5e = 4.
20.3
Inclusion & Exclusion (Sieve) Principle
IF A&B are two finite sets, then
|A ∪ B| = |A| + |B| − |A ∩ B|
|A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|
Example 20.8. In a set of 50 students, 18 speak German, 30 English, 26
French, 9 both English and German, 16 both English and French, and 8 both
French and German. 47 speak at least one of the languages. How many speak
all three?
Answer:
47
=
30 + 26 + 18 − 16 − 9 − 8 + |English ∩ French ∩ German|
6
=
|English ∩ French ∩ German|
41
Example 20.9 (Computing Euler’s function).
n&m are called co-prime if gcd(n, m) = 1.
The Euler function ϕ(n) = the number of natural numbers k in the range
1 ≤ k ≤ n that are co-prime with n.
If n = p is prime, then ϕ(p) = p − 1.
Compute ϕ(60):
60 = 22 · 3 · 5
If A is the set of number in [1, 60] that are multiples of 2, B the set that are
multiples of 3, and C the set that are multiples of 5, then
ϕ(60) = 60 − |A ∪ B ∪ C|
|A| = 60/2 = 30, |B| = 60/3 = 20, |C| = 60/5 = 12
|A ∩ B| = 60/10, |A ∩ C| = 60/10 = 6, |B ∩ C| = 60/15 = 4
|A ∩ B ∩ C| =
60
=2
2·3·5
|A ∪ B ∪ C| = 30 + 20 + 12 − 10 − 6 − 4 + 2 = 44
ϕ(60) = 60 − 44 = 16
21
R-permutations and R-combinations
Definition 21.1 (Permutation). An ordered arrangement of r elements from
the set of n elements is called an r-permutation (r ≤ n).
P (n, r) = n(n − 1) . . . (n − r + 1) =
n!
(n − r)!
Definition 21.2 (Combination). An unordered arrangement of r elements from
an n-set is called an r-combination.
P (n, r)
n!
n
C(n, r) =
=
=
.
r
r!
r!(n − r)!
Theorem 21.3 (Binomial Theorem).
n X
n
(x + y) =
xn−i y i
i
n
i=0
Corollary 21.4 (Corollaries of the Binomial Theorem).
42
1. 2n =
n
i
Pn
i=0
(x = y = 1).
n
2.
=0
(x = 1, y = −1)
k=0 (−1)
k
n
n
n
n
3.
+
+. . . (even numbers) =
+
+. . . (odd numbers)
0
2
1
3
Pn
n
n
k
4. 3 = k=0 2
(x = 2, y = 1)
k
Pn
k
Theorem 21.5 (Pascal’s Identity).
n+1
n
n
=
+
k
k
k−1
Example 21.6 (Pascal’s Triangle).
4
0
3
0
2
0
4
1
3
1
1
4
1
3
4
2
1
2
6
1
1
1
2
1
1
1
0
0
0
3
2
3
1
4
1
1
2
2
4
3
1
Theorem 21.7 (Vandermonde’s Identity).
m+n
r
=
r X
m
n
r−k
k
k=0
Proof.
43
∀r ≤ m, n
3
3
4
4
m+n
r-k
k
m
Theorem 21.8.
n
n+1
r+1
n X
j
=
r
j=r
n+1
Proof.
= the number of binary strings of length n + 1 with r + 1
r+1
ones.
Each term in the sum corresponds to the number of sequences whose last
one is in the place j + 1.
The number of permutations of n elements, when there are r1 indistinguishable elements of type 1, rk indistinguishable elements of type k, is
n!
r1 !r2 ! . . . rk !
where r1 + r2 + · · · + rk = n.
We denote
n!
r1 !r2 !...rk !
as
n
r1 , . . . , rk
and call it the multinomial number.
Example 21.9. How many 11 letter words can one make from the letters of
the word: ”ABRRACADABRA”?
Answer:
n=1
rA = 5
rB = 2
rR = 2
rE = 1
rD = 1
11!
= 160
5!2!2!1!1!
Lemma 21.10 (Multinomial Formula).
X
n
n
(x1 + · · · + xk ) =
xr11 xr22 . . . xrkk
r1 , . . . , rk
44
The monomial xr11 xr22 . . . xrkk arises from chosing x1 from r1 brackets, x2 from
r2 brackets, and so forth.
Example 21.11. What is the coefficent of x31 x22 x53 in the expression (x1 + x2 +
x3 )10 ? Answer:
10!
10
=
3, 2, 5
5!2!3!
Example 21.12. How many positive integer solution does the equation (x1 +
x2 + x3 ) = 11 have?
Answer: There are 11 objects of three types. What is the number of ways to
make a selection? The solution corresponds to a string of 11 stars and 2 bars;
stars are objects, bars mark off cells.
13 · 12
11 + 2
13
= 128
=
=
11
2
2
Theorem 21.13. The number of selections of n objects from the set of objects
of k types is
n+k−1
n+k−1
=
k
n
Proof. Corresponds to strings with n stars and k − 1 bars. This is also the
number of bijections from an n-set to a k-set. If f (i) = j then we put i into bar
j.
22
Permutations
A permutation on the set A is a bijection from A → A. We will consider
permutations on finite sets A = {1, . . . , n}.
Notation: 2σ = 3 or σ(2) = 3 means permutation σ takes 2 to 3.
τ (σ(2)) = τ ◦ σ(2) is a composition of σ and τ . Similarly, (2σ )τ = 2στ means
the composition of σ and τ .
Definition 22.1 (Group). A group G is a set of elements with an operation ?
such that:
1. (Closure) ∀g1 , g2 ∈ G ∃g3 ∈ G such that g1 ? g2 = g3
2. (Associativity) (g1 ? g2 ) ? g3 = g1 ? (g2 ? g3 ) ∀g1 , g2 , g3 ∈ G
3. (Identity) ∃e ∈ G such that ∀g ∈ G, g ? e = e ? g = g
4. (Inverse) ∀g ∈ G ∃g −1 ∈ G such that g −1 ? g = g ? g −1 = e.
Example 22.2. All permutations on {1, . . . , n} form a group with the composition operation
Example 22.3. Z+ (All integers with addition as the group operation)
e = 0 and the inverse of z ∈ Z+ is −z.
45
Example 22.4. Q× or R×
If only axioms 1,2, and 3 apply the group is called a monoid. Axioms 1 and
2 give a semi-group.
Example 22.5. The group of isometries (distance preserving bijections) of the
plane.
Example 22.6. A group of automorphisms of a given graph.
If the graph is finite, then it is a subgroup of the group of permutations on
the set V of vertices.
Definition 22.7 (Sub-group). A subset H of a group G is a subgroup if H is
itself a group with respect to the same operation in G. We denote this relation
as H ≤ G.
Example 22.8. Let G = Z+
Every subgroup of Z+ has the form mZ+ = {ma | a ∈ Z+ }, m ∈ Z+ , m > 0.
Let H = mZ+ . 0 ∈ H.
If x = ma, y = mb ⇒ x + y = m(a + b) ∈ H). So H is closed under addition.
If x = ma, then −x = −ma ⇒ −x ∈ H. So H is closed under inversion.
Lemma 22.9.
H ≤ G ⇔ ∀a, b ∈ H : ab−1 ∈ H
Definition 22.10 (Order). The order of G, |G|, is the number of elements in
G.
Definition 22.11 (Generator). A subgroup H of G is generated by a set S if
H is the intersection of all subgroups of G containing S. Denote by < S > the
subgroup generated by S.
Definition 22.12. If A, B ⊆ G, then AB = {ab|a ∈ A, b ∈ B}.
∅B = ∅
Lemma 22.13. For S ⊆ G, denote by S −1 = {a ∈ G|a−1 ∈ S}. Denote by
An = AA
. . . A}.
| {z
n times
Then the subgroup of G generated by S is
−1 n
∪∞
) .
n=0 (S ∪ S
−1 n
Proof. Obviously, < S >⊇ ∪∞
) (notice, that S 0 = e).
n=0 (S ∪ S
−1
−1 −1 −1
−1 n
Notice also that (abc) = c b a . The equality < S >= ∪∞
)
n=0 (S∪S
∞
−1 n
because ∪n=0 (S ∪ S ) is a subgroup itself.
46
23
Representing permutations
σ:
means
1
3
2
1
...
...
n
i
σ: 1
2
...
n
3
1
...
i
Definition 23.1 (Support, Fix).
supp(σ) = support of σ = {x ∈ X : xσ 6= x}
fix(σ) = fix of σ = {x ∈ X : xσ = x}
fix(σ) t supp(σ) = {1, . . . , n}
Definition 23.2 (Disjoint). σ and τ are disjoint if and only if
supp(σ) ∩ supp(τ ) = ∅
Lemma 23.3. If σ and τ are disjoint, then στ = τ σ.
Proof. Let σ, τ ∈ Sn = Sym({1, . . . , n}). If x ∈ {1, . . . , n}, then either x ∈
supp(σ) of x ∈ supp(τ ), or x ∈ {1, . . . , n} − (supp(σ) ∪ supp(τ )).
If x ∈ (supp(σ), then x ∈ (fix(τ ) and xτ = x. So, xτ σ = xσ . Thus,
στ
x = (xσ )τ , show xσ ∈ supp(τ ) because xσ ∈ supp(σ) because σ is a bijection.
If x ∈ supp(σ), then xσ ∈ supp(σ).
Similarly, if x ∈ supp(τ ), then xστ = xτ = xτ σ . If x ∈ supp(σ), then
σ
x ∈ supp(σ).
24
Cyclic notation for permutations
Definition 24.1.
(1 2 . . . k) =
1
2
2
3
3 ...
4 ...
k
1
If σ = (i1 . . . ik ) then σ is called a cycle of length k (k-cycle). A 2-cycle is
a transposition. Two cycles are disjoint if they are disjoint permutations.
Example 24.2. (1 2 3) and (4 6 7) are disjoint 3-cycles.
Theorem 24.3. Every permutation can be written as a product of disjoint
cycles. This form is unique except for the order of the cycles and the addition
of cycles of length 1.
47
Example 24.4.
1 2 3
σ =
3 1 2
=
4
9
5
8
6
7
7
6
8
5
9
4
10
17
11
15
12
16
13
14
14
10
15
11
16
12
17
13
18
18
(1 3 2)(4 9)(5 8)(6 7)(10 17 13 14)(11 15)(12 16)(18)
Remarks:
1. (1 2 3 4) = (2 3 4 1) = . . .
2. (1 2 3 4)−1 = (4 3 2 1) and (i1 . . . ik )−1 = (ik . . . i1 )
3. (1 4 3 5 7)(2 1 4 3 6) = (1 3 5 7 4 6 2)
Definition 24.5 (Order). The order of the element g in a group is the minimal
n such that g n = e. The order is ∞ if this n does not exist.
Example 24.6. The order of a k-cycle in Sn is k.
(1 2 . . . k)(1 2 . . . k) . . . (1 2 . . . k) = (1)(2) . . . (k)
|
{z
}
k times
Example 24.7. If σ is a product of disjoint cycles of length k1 , . . . , km then
|σ| = lcm(k1 , . . . , km ).
Example 24.8.
σ = (1 2 3)(4 5 6 7 8) ⇒ σ n = (1 2 3)n (4 5 6 7 8)n ⇒ |σ| = 15
Definition 24.9. A permutation is even if it is a product of even number of
transpositions (i, j) and odd if it is a product of an odd number of transpositions.
The same permutation cannot be represented both by even and odd number
of transpositions.
Hint of proof: A transposition (i, j) corresponds to a product of an elementary matrix Eij obtained from the identity matrix by switching rows i and j by
the column vector (x1 , . . . , xn )t . Every permutation corresponds to a product
of elementary matrices because it is a composition of transpositions. If
A = Ei1 j1 . . . Eik jj
Q
det Eij = −1, det A = detEi1 j1 . A permutation is even iff det(A) = 1 is odd
iff det A = -1 One can define for σ ∈ Sn sign(σ) = +1 if σ is even, -1 if odd
Ex (1) = (12)(12) Every k-cycle for k odd is an even permutation
(12 . . . k) = (12)(13) . . . (1k)
{z
}
|
k−1
48
25
Basic algebra in groups
Example 25.1.
1. The identity element of a group is unique.
e1 · e2 = e2 = e1 · e2 = e1
2. If ab = ac in group G, then b = c
a−1 ab =
a−1 ac
eb =
ec
ba =
ca ⇒ b = c
3. Each element has an unique inverse
Definition 25.2 (Order of a group element). The order of g ∈ G, denoted |g|,
is either the min positive integer n such that g n = e or is infinity if no such n
exists.
Definition 25.3 (Group Table). If G is a finite group of order m, then we
construct an m × m table as follows:
g1
..
.
g1
g2
...
gi
..
.
gj
...
gm
gi gj
gm
Example 25.4. The group table is a latin square
Definition 25.5 (Group Isomorphism). Two groups G, ? and H, are isomorphic if there exists a bijection φ : G → H such that
∀g1 , g2 ∈ G : φ(g1 ? g2 ) = φ(g1 ) φ(g2 )
The image of the product is the product of the images.
If α is the group table for G, αij = gi gj , then βij = φ(gi )φ(gj ) is the group
table for H.
26
Cyclic groups
Definition 26.1 (Cyclic group). If G is a group, S a subset, then we say that
a subgroup H is generated by S (denoted H = < S >) if H is the intersection
of all subgroups containing S.
If G is generated by one element, then G is called a cyclic group.
49
Theorem 26.2. Every infinite cyclic group C∞ is isomorphic to Z+ (the integers with group operation addition.) Every finite cyclic group of order m is
isomorphic to Z+
m (residues modulo m).
Proof. If G is generated by c then
G = {. . . , c−2 , c−1 , e, c1 , c2 , . . . }.
Case 1: ∀i 6= j : ci 6= cj Consider φ : G → Z+ such that φ(ck ) = k. e = c0 ⇒
φ(e) = 0. φ is a bijection.
φ(ck ct ) = φ(ck+t ) = k + t
φ(ck ) + φ(ct ) = k + t
therefore φ is an isomorphism.
Case 2: ∃i > j such that ci = cj ⇒ ci−j = cj−j = e. ∃m > 0 such that
cm = e.
Take the minimum positive m such that cm = e. This m = |c|. Show
that G = {e, c, . . . , cm−1 }. Take cn , n ∈ Z. Then ∃t such that n = tm + r,
0 ≤ r ≤ m − 1.
φ : G → Z+
m
φ(cr ) = r
φ(cr1 cr2 = r1 + r2 = r1 + r2 )
Example 26.3. In S3 , < (1 2 3) >∼
= C3 , the cyclic group of order 3.
27
Cosets and Lagrange’s Theorem
Lemma 27.1. Let H ≤ G. Consider the equivalence relation
g1 ∼ g2 ⇐⇒ g2−1 g1 ∈ H.
∼ is an equivalence relation because:
(reflectivity) g1−1 g1 ∈ H
(transitivity) If g3−1 g2 ∈ H and g2−1 g1 ∈ H, then g3−1 g2 g2−1 g1 = g3−1 g1 ∈ H.
(symmetry) g2−1 g1 ∈ H ⇐⇒ g1−1 g2 = (g2−1 g1 )−1 ∈ H.
G is a disjoint union of the equivalent classes of ∼.
Definition 27.2 (Coset). Equivalent classes gH = {gh|h ∈ H} are called left
cosets of H.
Proof. If g2 ∼ g then g2−1 g = h ∈ H, g2 = gh ∈ gH.
If g2 ∈ gH, then g2 = gh, h ∈ H and g −1 g2 = h ∈ H.
50
Corollary 27.3. Two left cosets are either the same or disjoint
Corollary 27.4.
|gH| = |H|
a
G=
gi H
Theorem 27.5 (Lagrange).
If H ≤ G, |G| < ∞ then |H| | |G|.
Proof.
G
g1H
g2H
gkH
|G| = k|H| where k is the number of left cosets.
Corollary 27.6 (Corollary of Sylow’s Theorem).
αm
1
If |G| = n = pα
1 . . . pm , pi 6= pj primes.
i
Then ∀i = 1, . . . , m, G has a subgroup of order pα
and of order pi . A
i
αi
subgroup of order pi is called a Sylow pi -subgroup.
Theorem 27.7. Every subgroup of order p is cyclic.
Proof. Let |H| = p. ∃a such that H = < a >.
If not, then take some a ∈ H, < a >≤ H.
| < a > | | |H| ⇒ < a > = H
.
Consider S3 . |S3 | = 6 = 2 · 3.
S3 has one subgroup of order 3: H = {e, (1 2 3), (1 3 2)}.
S3 has three subgroups of order 2: {e, (1 2)}, {e, (1 3)}, {e, (2 3)}.
Example 27.8 (Triangle Group D3 ∼
= S3 ).
The group of symmetries of a regular triangle is called the triangle group or
D3 , the dihedral group.
Let ρ be rotation by −2π
3 : (1 2 3).
Let r represent reflection. Then,
D3 = {e, ρ, ρ2 , r, ρr, ρ2 r}.
51
Definition 27.9 (Isometry). An isometry of the plane is a bijection that
preserves distances between any two points.
Remark An isometry also preserves angles.
Definition 27.10 (Orientation preserving, reversing). An isometry is orientation preserving if it preserves an orientation of vertices of every triangle (
clockwise → clockwise). Otherwise it is called an orientation reversing.
Every orientation preserving isometry is either a translation or rotation.
Every orientation reversing isometry is either reflection or a glide reflection: a
reflection followed by translation parallel to the reflection line.
Definition 27.11 (Dihedral Group). Dn is the dihedral group of symmetries
of a regular n-gon. Dn ≤ Sn , Dn 6∼
= Sn ∀n > 3.
Dn =< ρ, r|ρn = e, r2 = e, ρr = rρ−1 >
Example 27.12. D4 is the square. ρ is rotation by
reflection: (1 2)(4 3).
Example 27.13.
−π
2
→ (1 2 3 4). r is
ρ3 rρ2 r = ρ3 ρ−2 rr = ρe = ρ
Example 27.14. Take G = D4 , H =< e, r >.
Find all left cosets of H in G.
G =
=
{e, r} ∪ {ρ, ρr} ∪ {ρ2 , ρ2 r} ∪ {ρ3 , ρ3 r}
H ∪ ρH ∪ ρ2 H ∪ ρ3 H
|G| = 8, |H| = 2
Definition 27.15 (index). The index [G : H] is the number of left cosets of
H in G.
Example 27.16. [D4 : H] = 4
Definition 27.17 (Conjugate). If h, g ∈ G then h−1 gh is called the conjugate
of g by h (also denoted g h ).
Definition 27.18 (Commutator). h−1 g −1 hg = [h, g] is called the commutator of h and g.
Lemma 27.19. Let σ ∈ Sn , τ = (1 2 . . . k), then σ −1 τ σ = (σ(1), σ(2), . . . , σ(k)).
Proof. Let i ∈ {1, . . . , k}. σ(i) = iσ .
(iσ )σ
If i ∈
/ {1, . . . , k},
−1
τσ
= iσσ
−1
τσ
(iσ )σ
= iτ σ ≡ (i + 1)σ mod k
−1
τσ
52
= iσ .
Corollary 27.20.
σ −1 (i1 . . . ik )(j1 . . . jk ) . . . (t1 . . . tk )σ = (σ(i1 ) . . . σ(ik ))(σ(j1 ) . . . σ(jk ))(σ(t1 ) . . .
Definition 27.21 (cyclic). A cyclic structure of a permutation is the expression
1k1 2k2 . . . 5k5 where k5 is the number of 5-cycles in the canonical representation
of the permutation.
Corollary 27.22. Conjugation preserves the cyclic structure of a permutation.
Example 27.23. Find σ such that σ −1 τ σ = δ where
τ = (1 2)(4 5 3)
σ=
1
4
2
5
δ = (4 5)(6 7 1)
3 4 5 6 7
= (1 4 6 2 5 7 3)
1 6 7 2 3
Example 27.24. Find σ such that σ −1 τ σ = δ where
τ = (3 5 1)(4 7 6)(2 8)
σ=
1
3
2
7
δ = (7 6)(2 1 3)(4 8 5)
3 4 5 6 7 8
= (1 3 2 7 8 6 5)(4)
2 4 1 5 8 6
Example 27.25. Find all subgroups of A4 (the alternating group, which is the
group of even permutations, on a 4 element set).
Sn = An ∪ (1 2)An
Since every odd σ = (1 2)τ for some even τ .
Suppose σ is odd, then τ = (1 2)σ is even ⇒ σ = (1 2)τ .
4!
|S4 |
=
= 12
2
2
A4 = {e, (1 2)(3 4), (1 3)(2 4), (1 4)(2 3), (1 2 3), (1 3 2), (1 3 4), (1 4 3), (1 2 4), (1 4 2), (2 3 4), (2 4 3)}
|A4 | =
Construct a digraph (Figure 20), vertices are labeled by subgroups. If H1 ≤
H2 , then we draw an edge from H1 to H2 . By symmetry, the product of any
two elements of order two in A4 give the third element of order 2.
[(1 2)(3 4)][(1 3)(2 4)] = (1 4)(2 3)
Order 6: A subgroup of order 6 must contain an element of order 3 and of
order 2. Suppose it contains (1 2 3), then it contains (1 3 2). It also contains a
product of two transpositions.
(1 2 3)−1 (1 2)(3 4)(1 2 3) = (1 4)(2 3)
(1 3 2)−1 (1 2)(3 4)(1 3 2) = (1 3)(2 4)
We’ve obtained 6 elements so far. Thus the seventh element is:
(1 2)(3 4)(1 2 3)(1 2)(3 4) = (1 4 2).
53
Figure 20: A graph, called a lattice, showing the relation of the subgroups.
Figure 13.4 in Bigg’s text.
Example 27.26. Find the group of automorphisms of the graphs:
1.
6
p 1 >>
ppp
>>
p
p
>>
ppp
p
p
>
p
p
p
2
5 N>NN
>> NNN
N
>> NN
>> NNN
NN
4
3
An automorphism takes a vertex into a vertex of the same degree. We
can extend every symmetry of a triangle 4135 to an automorphism of the
group.
G = Aut(Γ) ∼
= D3
Aut(Γ) = {e, (1 3 5)(2 4 6), (1 5 3)(2 6 4), (5 3)(6 2), (5 1)(2 4), (3 1)(4 6)}
φ = Aut(Γ) → D3 =< ρ, r|ρ3 = e, r2 = e, ρr = rρ−1 >
φ is an isomorphism:
(1 3 5)(2 4 6) →φ ρ
(5 3)(6 2) →φ r
54
2.
2
1>
>>
>>
>>
3
5>
>>
>>
>>
6
4
1 can only be switched with 6. a: let 1 → 1
{e, (2 3)(5 4)} = stabilizer of 1
b: let 1 → 6
{(1 6)(2 5)(3 4), (2 3)(5 4)(1 6)(2 5)(3 4) = (2 4)(3 5)(1 6)}
3.
2.
5>
..
>>
>>
.. >>
.. .
6
1>
..
>>
>>
...
>> .
3
4
a: let 1 → 1
{e, (2 3)(5 4), (5 4), (2 3)}
b: let 1 ↔ 6, then the automorphisms look like: H(1 2)(2 5)(3 4) = right
coset of H. | Aut(Γ) = 8.
4.
4>
>>
>>
>>
5
3
2
If 3 is fixed,
if 3 ↔ 4
1>
>>
>>
>>
6
{e, (2 4), (5 6), (2 4)(5 6)} = H
H(3 1)(4 5)(2 6)
55
28
Counting the number of orbits
Let G be a group of permutations of set X.
F (σ) = {x ∈ X|σ(x) = x}
Lemma 28.1. If y ∈ Gx, y = σ(x), then Gy = σGx σ −1 is the conjugate of Gx
by σ −1 .
Proof. If r ∈ σGx σ −1 , then τ = σδσ −1 , δ(x) = x
τ (y) = σδσ −1 (σx) = σx = y ⇒ τ ∈ Gy ⇒ σGx σ −1 ⊆ Gy.
But x = σ −1 (y). By symmetry σGx σ −1 ⊆ Gx .
Gy ⊆ σGx σ −1 ⇒ Gy = σGx σ −1 .
Corollary 28.2. If y ∈ Gx, then
|Gy | = |Gx |.
Theorem 28.3. The number of orbits t is
t=
1 X
|F (g)|
|G|
g∈G
Proof. Let E = {(σ, x)|σ ∈ G, x ∈ X, σ(x) = x}
α
|E| =
σ
...
σ∈G rσ
=
P
...
P
x∈X
x
..
.
1
ασx = 1 ⇐⇒ σ(x) = x; o.w. ασx = 0
cx , where rσ is the row sum and cx is the column sum.
rσ = |F (σ)|
cx = |Gx |
X
X
cy =
Gy = |Gx ||Gx| = |G|
y∈Gx
y∈Gx
The input of each orbit in |E| is |G|.
|E| = t|G| =
X
|F (σ)|
σ∈G
t=
1 X
|F (G)|
|G|
σ∈G
56
29
Applications
Example 29.1. Necklaces are manufactured from 13 white pearls and 3 black
pearls (with no fastening). How many different necklaces can be made?
Imagine each
pearl
is the vertex of a regular 16-gon.
16
= 560 possible configurations.
There are
= 16·15·14
3·2
3
We want to find the number of orbits for the action of the D1 6 (the group
of symmetries of a regular 16-gon) on the configuration.
|G| = |D1 6| = 2 · 16 = 32
D1 6 has 16 rotations. |F (e)| = 560, |F (σ)| = 0 for any other rotation.
If σ is a reflection in the axis through opposite vertices, then |F (sigma)| =
14. If σ is a reflection in the axis through midpoints of the opposite edges then
|F (σ)| = 0.
The number of orbits is
t=
1
(60 + 8 · 14) = 21.
32
Example 29.2. How many identity cards can be made from a metal square
with a 3 × 3 square grid on both sides and two holes?
The number
·
·
of configurations
e
ρ
ρ2
ρ3
r1 = (1 2)(3 4)
r2 = (2 4)
r3 = (2 3)(1 4)
r4 = (3 1)
9
is
= 9·8
2 = 36. D4 acts on the set of configurations.
2
|F (e)| = 36
|F (ρ)| = 0
|F (ρ2 )| = 4
|F (ρ3 )| = 0
|F (r1 )| = 6
|F (r2 )| = 6
|F (r3 )| = 6
|F (r4 )| = 6
t=
1
(36 + 4 + 4 · 6) = 8.
8
Definition 29.3 (Group product). Let G and H be groups, let
G × H = {(g, h)|g ∈ G, h ∈ H}.
Define multiplication component-wise by
(g1 , h1 )(g2 , h2 ) = (g1 g2 , h1 h2 )
then G × H is a group called the product of G and H.
57
Example 29.4. Prove that for gcd(m, n) = 1
cm × cn ∼
= cmn .
cn is a cyclic group of order m. Let cm =< a|am = e >, cn =< b|bn = e >.
Then the order of (a, b) in cm × cn is mn.
(a, b)i = (ai , bi )
|(a, b)| = mn
|cm × cn | = mn ⇒ (a, b) generates the whole group
Therefore this group is cyclic.
Example 29.5.
c2 × c̄2 c4
c2 = {e, (1 2)}
c̄2 = {(3 4)}
c2 × c̄2 ∼
= {e, (1 2), (3 4), (1 2)(3 4)}
Example 29.6. For the deck of 12 cards, how many times do we have to repeat
a perfect shuffle to bring the deck back to the original order?
1 → 1
2 → 7
3 → 2
4 → 8
5 → 3
6 → 9
7 → 4
8 → 10
9 → 5
10 → 11
11 → 6
12 → 12
σ = (1)(12)(2 7 4 8 10 11 6 9 5 3)
10 shuffles are required to restore the original ordering.
58