186
Combinatorics A CRC Press FREEBOOK

Combinatorics - Routledge

  • Upload
    others

  • View
    32

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Combinatorics - Routledge

Combinatorics

A CRC Press FREEBOOK

Page 5: Combinatorics - Routledge

9TREES9.1 Characterizations and Types of Trees Lisa Carbone

9.1.1 Properties of Trees

9.1.2 Roots and Orderings

9.1.3 Tree Traversal9.1.4 Infinite Trees

9.2 Spanning Trees Uri Peled

9.2.1 Depth­first and Breadth­first Spanning Trees

9.2.2 Enumeration of Spanning Trees

9.3 Enumerating Trees Paul K. Stockmeyer

9.3.1 Counting Generic Trees

9.3.2 Counting Trees in Chemistry9.3.3 Counting Trees in Computer Science

Page 6: Combinatorics - Routledge

694 Chapter 9 TREES

INTRODUCTION

A tree is a connected graph containing no cycles. Trees have applications in a widevariety of disciplines, particularly computer science. For example, they can be used toconstruct searching algorithms for finding a particular item in a list, to store data, tomodel decisions and their outcomes, or to design networks.

GLOSSARY

ancestor (of a vertex v in a rooted tree): any vertex on a path to v from the root.

m-ary tree: a rooted tree in which every internal vertex has at most m children.

backtrack: a pair of successive edges in a walk where the second edge is the same asthe first, but traversed in the opposite direction.

balanced tree: a rooted m-ary tree of height h such that all leaves of the tree haveheight h or h−1.

bihomogeneous tree: a tree (usually infinite) in which there are exactly two valuesfor the vertex degrees.

binary search tree (BST): a type of binary tree used to represent a table of data,which is efficiently accessed by storage and retrieval algorithms.

binary tree: an ordered rooted tree in which each vertex has at most two children,that is, a possible “left child” and a possible “right child”; an only child must bedesignated either as a left child or a right child (this usage is standard for computerscience); an m-ary tree in which m = 2 (in pure graph theory).

bounded tree: a (possibly infinite) tree of finite diameter.

breadth-first search: a method for visiting all the vertices of a graph in a sequence,in order of their proximity to a designated starting vertex.

caterpillar: a tree that contains a path such that every edge has one or both endpointsin that path.

center (of a tree): the set of vertices of minimum eccentricity.

child (of a vertex v in a rooted tree): a vertex such that v is its immediate ancestor.

chord: for a graph G with a spanning tree T , an edge e of G such that e /∈ T .

complete binary tree: a binary tree where every parent has two children and all leavesare at the same depth.

decision tree: a rooted tree in which every internal vertex represents a decision andeach path from the root to a leaf represents a sequence of decisions.

depth (of a vertex in a rooted tree): the number of edges in the unique path from theroot to that vertex.

depth-first search: a method for visiting every vertex of a graph by progressing as faras possible from the most recently visited vertex, before doing any backtracking.

descendant (of a vertex v in a rooted tree): a vertex that follows v on a path awayfrom the root.

diameter (of a tree): the maximum distance between two vertices in the tree.

Page 7: Combinatorics - Routledge

GLOSSARY 695

distance (between two vertices in a tree): the number of edges in the unique (simple)path between these vertices.

eccentricity (of a vertex in a tree): the length of the longest simple path beginning atthat vertex.

finite tree: a tree with a finite number of vertices and edges.

forest: a graph with no cycles.

full m-ary tree: a rooted tree in which every internal vertex has exactly m children.

fundamental cycle: in a connected graph G, the unique cycle created by adding theedge e ∈ EG not in T to a spanning tree T .

fundamental edge-cut: in a connected graph G, the partition-cut 〈X1, X2〉 where X1

and X2 are the vertex sets of the two components of T − e for some edge e in aspanning tree T for G.

fundamental system of cycles: in a connected graphG, the set of fundamental cyclescorresponding to the various edges of G− T , where T is a spanning tree for G.

fundamental system of edge-cuts: in a connected graph G, the set of fundamentaledge-cuts that result from removal of an edge from a spanning tree T for G.

height (of a rooted tree): the maximum of the levels of its vertices.

homogeneous: property of an (infinite) tree that every vertex has the same degree.

n-homogeneous: property of an (infinite) tree that every vertex has degree n.

infinite tree: a tree with an infinite number of vertices and edges.

inorder traversal (of an ordered rooted tree): a recursive listing of all vertices startingwith the vertices of the first subtree of the root, next the root vertex itself, and thenthe vertices of the other subtrees as they occur from left to right.

internal vertex (of a rooted tree): a vertex with children.

isomorphism (of trees): for trees X and Y , a pair of bijections fV : VX → VY andfE : EX → EY such that if u and v are the endpoints of an edge e in the tree X ,then fV (u) and fV (v) are the endpoints of the edge fE(e) in the tree Y (see §8.1).

isomorphism (of rooted trees): for rooted trees (T1, r1) and (T2, r2), a tree isomor-phism f : T1 → T2 that takes r1 to r2.

labeled tree: a tree with labels such as v1, v2, . . . , vn assigned to its vertices.

leaf : in a rooted tree, a vertex that has no children.

left child (of a vertex in an ordered, rooted binary tree): the first child of that vertex.

left-right tree: Synonym for full binary tree.

left subtree (of an ordered, rooted binary tree): the subtree rooted at a left child.

level (of a vertex in a rooted tree): the length of the unique path from the root to thisvertex.

locally finite tree: a tree in which the degree of every vertex is finite.

nth level (of a rooted tree): the set of all vertices at depth n.

ordered tree: a rooted tree in which the children of each internal vertex are linearlyordered.

Page 8: Combinatorics - Routledge

696 Chapter 9 TREES

parent (of a vertex v, other than the root, in a rooted tree): a vertex that is the im-mediate predecessor of v on the unique path away from the root to v.

partition-cut of a graph: given a partition of the set of vertices of G into X1 and X2,the set 〈X1, X2〉 of edges of G that have one endpoint in X1 and the other in X2.

postorder traversal (of an ordered rooted tree): a recursive listing of vertices startingwith the vertices of subtrees as they occur from left to right, followed by the root.

preorder traversal (of an ordered rooted tree): a recursive listing of vertices startingwith the root, then the vertices of the first subtree, followed by the vertices of othersubtrees as they occur from left to right.

reduced tree: a tree with no vertices of degree 2.

reduced walk: a walk in a graph without backtracking.

regular: Synonym for homogeneous.

right child (of a vertex in an ordered rooted binary tree): the second child of that ver-tex.

right subtree (of an ordered, rooted binary tree): the subtree rooted at the right child.

rooted tree: a tree in which one vertex is designated as the “root”.

siblings (in a rooted tree): vertices with the same parent.

spanning tree (of a connected graph): a subgraph that is a tree and contains all thevertices of the graph.

subtree: a subgraph of a tree that is also a tree.

tree: a connected graph with no cycles.

tree edge: for a graph G with a spanning tree T , an edge e of G such that e ∈ T .

tree traversal: a walk that visits all the vertices of a tree.

9.1 CHARACTERIZATIONS AND TYPES OF TREES

9.1.1 PROPERTIES OF TREES

For trees, as with other graphs, there is a wide variety of terminology in use from oneapplication or specialty to another.

Definitions:

A graph is acyclic if it contains no subgraph isomorphic to a cycle Cn (see §8.1.3).

A forest is an acyclic graph.

A tree is an acyclic connected graph. (Note: Unless stated otherwise, all trees areassumed to be finite, i.e., to have a finite number of vertices.)

A walk is an alternating sequence v0, e1, v1, . . . , er, vr of vertices and edges in which eachedge ei joins vertices vi−1 and vi.

Page 9: Combinatorics - Routledge

Section 9.1 CHARACTERIZATIONS AND TYPES OF TREES 697

A path (sometimes called a simple path) is a walk where all the vertices are different.

The eccentricity of a vertex is the length of the longest (simple) path beginning at thatvertex.

The center of a tree contains all vertices with minimum eccentricity.

An end vertex of a tree is a vertex of degree 1.

A caterpillar is a tree that contains a path such that every edge has one or bothendpoints in that path.

Facts:

1. A (finite) tree with at least two vertices has at least two end vertices.

2. A connected graph with n vertices is a tree if and only if has exactly n− 1 edges.

3. A graph is a tree if and only if there is a unique (simple) path between any twovertices.

4. A graph is a forest if and only if every edge is a cut-edge. (See §8.4.2.)

5. Trees are bipartite. Hence, every tree can be colored using two colors.

6. The center of a tree consists of either only one vertex or two adjacent vertices.

Examples:

1. The following tree has 9 vertices and 9− 1 = 8 edges.

2. The following graph is a forest with three components.

3. The center of the following tree consists of the two adjacent vertices a and b.

a b

4. The following tree is a caterpillar.

Page 10: Combinatorics - Routledge

698 Chapter 9 TREES

5. Neither of the following graphs is a tree. One contains a 3-cycle, and the othercontains a 1-cycle (i.e., a self-loop).

9.1.2 ROOTS AND ORDERINGS

Adding some extra structure to trees adapts them to applications in many disciplines,especially computer science.

Definitions:

A rooted tree (T, r) is a tree T with a distinguished vertex r (the root), in which alledges are implicitly directed away from the root.

Two rooted trees (T1, r1) and (T2, r2) are isomorphic as rooted trees if there is anisomorphism f : T1 → T2 (see §8.1.2) that takes r1 to r2.

A child of a vertex v in a rooted tree is a vertex that is the immediate successor of v ona path away from the root.

A descendant of a vertex v in a rooted tree is v itself or any vertex that is a successorof v on a path away from the root. A proper descendant of a vertex v in a rooted treeis any descendant except v itself.

The parent of a vertex v in a rooted tree is a vertex that is the immediate predecessorof v on the path to v away from the root.

The parent function of a rooted tree T maps the root of T to the empty set and mapsevery other vertex to its parent.

An ancestor of a vertex v in a rooted tree is v itself or any vertex on the path to v awayfrom the root. A proper ancestor of a vertex v in a rooted tree is any ancestor exceptv itself.

Siblings in a rooted tree are vertices with the same parent.

An internal vertex in a rooted tree is a vertex with children.

A leaf in a rooted tree is a vertex that has no children.

The depth of a vertex in a rooted tree is the number of edges in the unique path fromthe root to that vertex.

The nth level in a rooted tree is the set of all vertices at depth n.

The height of a rooted tree is the maximum depth over all vertices.

An ordered tree is a rooted tree in which the children of each internal vertex are linearlyordered.

A left sibling of a vertex v in an ordered tree is a sibling that precedes v in the orderingof v and its siblings. A right sibling of a vertex v in an ordered tree is a sibling thatfollows v in the ordering of v and its siblings.

Page 11: Combinatorics - Routledge

Section 9.1 CHARACTERIZATIONS AND TYPES OF TREES 699

A plane tree is a geometric realization (drawing) of an ordered tree such that the left-to-right order of the children of each vertex in the drawing is consistent with the linearordering of the corresponding vertices in the tree.

In the level ordering of the vertices of an ordered tree, u precedes v under any of thesecircumstances:

• if the depth of u is less than the depth of v;

• if u is a left sibling of v;

• if the parent of u precedes the parent of v.

Two ordered trees (T1, r1) and (T2, r2) are isomorphic as ordered trees if there is arooted tree isomorphism f : T1 → T2 that preserves the ordering at every vertex.

An m-ary tree is a rooted tree such that every internal vertex has at most m children.

A full m-ary tree is a rooted tree such that every internal vertex has exactly m children.

A (pure) binary tree is a rooted tree such that every internal vertex has at most twochildren. This meaning of “binary tree” occurs commonly in graph theory.

A binary tree is a 2-ary tree such that every child, even an only child, is distinguished asleft child or right child. This meaning of “binary tree” occurs commonly in computerscience and in permutation groups.

The principal subtree at a vertex v of a rooted tree comprises all descendants of v andall edges incident to these descendants. It is itself a rooted tree with v designated as itsroot.

The left subtree of a vertex v in a binary tree is the principal subtree at the left child.The right subtree of v is the principal subtree at the right child.

A balanced tree of height h is a rooted m-ary tree in which all leaves are of height hor h−1.

A complete binary tree is a binary tree in which every parent has two children andall leaves are at the same depth.

A complete m-ary tree is an m-ary tree in which every parent has m children and allleaves are at the same depth.

A decision tree is a rooted tree in which every internal vertex represents a decision andeach path from the root to a leaf represents a sequence of decisions.

A prefix code for a finite set X = {x1, . . . , xn} is a set {c1, . . . , cn} of binary stringsin X (called codewords) such that no codeword is a prefix of any other codeword.

A Huffman code for a set X with a probability measure Pr (see §7.1) is a prefix code{c1, . . . , cn} such that

∑nj=1

len(cj)Pr(xj) is minimum among all prefix codes, wherelen(cj) measures the length of cj in bits.

A Huffman tree for a set X with a probability measure Pr is a tree constructed byHuffman’s algorithm to produce a Huffman code for (X,Pr).

Facts:

1. Plane trees are usually drawn so that vertices of the same level in the correspondingordered tree are at the same vertical position in the plane.

2. A rooted tree can be represented by its vertex set plus its parent function.

Page 12: Combinatorics - Routledge

700 Chapter 9 TREES

3. The concept of finite binary tree also has the following recursive definition: (basis)an ordered tree with only one vertex is a binary tree; (recursion) an ordered tree withmore than one vertex is a binary tree if the root has at most two children and if both itsprincipal subtrees are binary trees.

4. A full m-ary tree with k internal vertices has mk+1 vertices and (m−1)k+1 leaves.

5. A full m-ary tree with k vertices has (k−1)/m internal vertices and ((m−1)k+1)/mleaves.

6. There are at most mh leaves in any m-ary tree of height h.

7. A binary search tree is a special kind of binary tree used to implement a random

access table with O(n) maintenance and retrieval algorithms. (See §18.2.3.)

8. A balanced binary tree can be used to implement a priority queue with O(n) enqueueand dequeue algorithms. (See §18.2.4.)

9. Algorithm 1, due to D. Huffman in 1951, constructs a Huffman tree.

Algorithm 1: Find a Huffman code.

input: the probabilities Pr(x1), . . . ,Pr(xn) on a set X

output: a Huffman code for (X,Pr)

initialize F to be a forest of isolated vertices, labeled x1, . . . , xn, each to be

regarded as a rooted tree

assign weight Pr(xj) to the rooted tree xj , for j = 1, . . . , n

repeat until forest F is a single tree

choose two rooted trees, T and T ′, of smallest weights in forest F

replace trees T and T ′ in forest F by a tree with a new root whose left subtree

is T and whose right subtree is T ′

label the new edge to T with a 0 and the new edge to T ′ with a 1

assign weight w(T ) + w(T ′) to the new tree

return tree F

{The Huffman code word for xi is the concatenation of the labels on the unique

path from the root to xi}

Examples:

1. The following is a rooted tree (T, d) with root d.

c

g e f

b

d

a

vertex a b c d e f g

parent d d d ∅ c b c

2. The following is a 2-ary tree of height 4.

Page 13: Combinatorics - Routledge

Section 9.1 CHARACTERIZATIONS AND TYPES OF TREES 701

3. A balanced binary tree is shown next.

4. The following tree is rooted at vertex r. Vertices d and e are children of vertex b.Vertex f is a descendant of f , d, b, and r, but f is not a descendant of vertex a. Vertex ais the parent of c, which is the only proper descendant of vertex a. Vertices d and e aresiblings, but c is not a sibling of d or of e. The leaves are c, e, f ; the internal vertices area, b, r, d.

c

a

r

b

d

f

e

5. The following two rooted trees are isomorphic as graphs, but they are considered tobe different as rooted trees, because there is no graph isomorphism from one to the otherthat maps root to root.

6. The following two plane trees are isomorphic as rooted trees, but they are not iso-morphic as ordered rooted trees, because there is no rooted tree isomorphism from oneto the other that preserves the child ordering at every vertex.

7. A complete binary tree of height 2 and a complete 3-ary tree of height 2 are shownnext.

Page 14: Combinatorics - Routledge

702 Chapter 9 TREES

8. The iterative construction of a Huffman tree for the set X = {a, b, c, d, e, f} withrespective probabilities {0.08, 0.10, 0.12, 0.15, 0.20, 0.35} would proceed as follows:

.08

.18 .27 .20

.18

0 1

a

a

b

b

0 1 0 1

a

forest 0

forest 1

forest 2

b c d

c d e f

c d e f

e f

.10 .12 .15 .20 .35

.12 .15 .20 .35

.35

.38forest 3

forest 4

forest 5

0

0

0

c de

ba

1

1

0

0 e

ba

1

1

0

0

0 e

ba

1

1

1

1 f

dc

0

0

1

1

1 f

dc

0

0

1 f

.27 .35

.38 .62

1.0

The resulting codes are 000 for a, 001 for b, 100 for c, 101 for d, 01 for e, and 11 for f .So the most frequently used objects in X are represented by the shortest codes.

9.1.3 TREE TRAVERSAL

Ordered rooted trees can be used to store data or arithmetic expressions involving num-bers, variables, and operations. A tree traversal algorithm gives a systematic method foraccessing the information stored in the tree.

Definitions:

A boundary walk of a plane tree is a walk around the boundary of the single region ofthe plane imbedding of the tree, starting at the root.

A backtrack along a walk in a graph is an instance . . . , u, e, v, e, u, . . . of two consecutiveedge-steps in which an edge-step traverses the same edge as its predecessor, but in theopposite direction.

Page 15: Combinatorics - Routledge

Section 9.1 CHARACTERIZATIONS AND TYPES OF TREES 703

A preorder traversal of an ordered rooted tree T lists the vertices of T (or their labels)so that each vertex v is followed by all the vertices, in preorder, in its principal subtrees,respecting their left-to-right order.

A postorder traversal of an ordered rooted tree T lists the vertices of T (or theirlabels) so that each vertex v is preceded by all the vertices, in postorder, in its principalsubtrees, respecting their left-to-right order.

An inorder traversal of an ordered rooted tree T lists the vertices of T (or their labels)so that each vertex v is preceded by all the vertices, in inorder, in its first principalsubtree and so that v is followed by the vertices, in inorder, of its other principal subtrees,respecting their left-to-right order.

Prefix (or Polish) notation is the form of an arithmetic expression obtained from apreorder traversal of a binary tree representing this expression.

Postfix (or reverse Polish) notation is the form of an arithmetic expression obtainedfrom a postorder traversal of a binary tree representing this expression.

Infix notation is the form of an arithmetic expression obtained from an inorder traversalof a binary tree representing this expression. A left parenthesis is written immediatelybefore writing the left principal subtree of each vertex, and a right parenthesis is writtenimmediately after writing the right principal subtree.

The universal address system of an ordered rooted tree is a labeling in which the rootis labeled 0 and for each vertex with label x, its m children are labeled x.1, x.2, . . . , x.m,from left to right.

In the level order of the vertices of an ordered tree T , vertex u precedes vertex v if u isnearer the root, or if u and v are at the same level and u and v have ancestors u′ and v′

that are siblings and u′ precedes v′ in the ordering of T .

A bijective assignment of labels from an ordered set (such as alphabetic strings or theintegers) to the vertices of an ordered tree is sorted if the level order of these labels iseither ascending or descending.

Facts:

1. The preorder traversal of a plane tree is obtained by a counterclockwise traversal ofthe boundary walk of the plane region, that is, starting downward toward the left. Aseach vertex of the tree is encountered for the first time along this walk, it is recorded inthe preorder.

2. The postorder traversal of a plane tree is obtained by a counterclockwise traversal ofthe boundary walk of the plane region, that is, starting downward toward the left. Aseach vertex of the tree is encountered for the last time along this walk, it is recorded inthe postorder. Algorithm 2 uses this to find the parents of all vertices.

3. The inorder traversal of a plane tree is obtained by a counterclockwise traversal ofthe boundary walk of the plane region, that is, starting downward toward the left. Aseach interior vertex of the tree is encountered for the second time along this walk, it isrecorded in the inorder. An end vertex is recorded whenever it is encountered for theonly time.

4. Two nonisomorphic ordered trees with sorted vertex labels can have the same preorderbut not the same postorder.

Page 16: Combinatorics - Routledge

704 Chapter 9 TREES

Algorithm 2: Parent-finder for the postorder of a plane tree.

input: the postorder vp(1), . . . , vp(n) of a plane tree with sorted vertex labels and

a vertex vj

output: the parent of vj

scan the postorder until vj is encountered

continue scanning until some vertex vi is encountered such that i < j

return (vi)

Examples:

1. The following plane tree has preorder a b e f h c d g i j k, postorder e h f b c i j k g d a,and inorder e b h f a c i g j k d.

e

b

a

c

f

h i j k

g

d

2. The following binary tree represents the arithmetic expression that has infix form(x+ y)/(x− 2), prefix form /+ x y − x 2, and postfix form x y + x 2− /.

x y x 2

+

/

-

9.1.4 INFINITE TREES

Definitions:

An infinite tree is a tree with an infinite number of vertices and edges.

The diameter of a tree is the maximum distance between two distinct vertices in thetree.

A bounded tree is a tree of finite diameter.

The degree of a vertex is the number of edges incident with it.

A locally finite tree is a tree in which the degree of every vertex is finite.

A homogeneous tree is a tree in which every vertex has the same degree.

An n-homogeneous tree is a tree in which every vertex has degree n.

A bihomogeneous tree is a nonhomogeneous tree with a partition of the vertices intotwo subsets, such that all vertices in the same subset have the same degree.

Page 17: Combinatorics - Routledge

Section 9.2 SPANNING TREES 705

Facts:

1. Konig’s lemma: An infinite tree that is locally finite contains an infinitely long path.

Examples:

1. Suppose that two finite bitstrings are considered adjacent if one bitstring can beobtained from the other by appending a 0 or a 1 at the right. The resulting graph is theinfinite bihomogeneous tree, in which the empty string λ has degree 2 and all other finitebitstrings have degree 3.

111

11

1 λ 0

00

000

001

010

110

101

0110

011100

2. Consider the set of all finite strings on the alphabet {a, a−1, b, b−1} containing no

instances of the substrings aa−1, a−1a, bb−1, or b−1b. Suppose that two such stringsare considered to be adjacent if and only if one of them can be obtained from the otherby appending one of the alphabet symbols at the right. Then the resulting graph is a4-homogeneous tree.

3. Consider as vertices the set of infinite bitstrings with at most two 1s. Suppose twosuch bitstrings are regarded as adjacent if they differ in only one bit and that bit is arightmost 1 for one of the two bitstrings. This graph is a bounded tree of diameter four.

9.2 SPANNING TREES

A spanning tree of a graph G is a subgraph of G that is a tree and contains everyvertex of G. Spanning trees are very useful in searching the vertices of a graph and incommunicating from any given vertex to the other vertices. Minimum spanning trees arecovered in §10.1.

9.2.1 DEPTH­FIRST AND BREADTH­FIRST SPANNING TREES

Definitions:

A spanning tree of a graph G is a tree that is a subgraph of G and that contains everyvertex of G.

A tree edge of a graph G with a spanning tree T is an edge e such that e ∈ T .

A chord of a graph G with a spanning tree T is an edge e such that e /∈ T .

A back edge of a digraph G with a spanning tree T is a chord that joins one of itsendpoints to an ancestor in T . A forward edge is a chord that joins one of its endpointsto a descendant in T . A cross edge is a chord that is neither a back edge nor a forwardedge.

Page 18: Combinatorics - Routledge

706 Chapter 9 TREES

The fundamental cycle of a chord e with respect to a given spanning tree T of agraph G consists of the edge e and the unique path in T joining the endpoints of e.

A depth-first search (DFS) of a graph G is a way to traverse every vertex of a con-nected graph by constructing a spanning tree, rooted at a given vertex r. Each stage ofthe DFS traversal seeks to move to an unvisited neighbor of the most recently visitedvertex, and backtracks only if there is none available. See Algorithm 1.

A depth-first search tree is the spanning tree constructed during a depth-first search.

Backtracking during a depth-first search means retreating from a vertex with no un-visited neighbors back to its parent in the DFS-tree.

A breadth-first search (BFS) of a graph G is a way to traverse every vertex of aconnected graph by constructing a spanning tree, rooted at a given vertex r. Afterthe BFS traversal visits a vertex v, all of the previously unvisited neighbors of v areenqueued, and then the traversal removes from the queue whatever vertex is at the frontof the queue, and visits that vertex. See Algorithm 2.

A breadth-first search tree is the spanning tree constructed during a breadth-firstsearch.

The fundamental system of cycles of a connected graph G associated with a spanningtree T is the set of fundamental cycles corresponding to the various edges of G− T .

Given two vertex sets X1 and X2 that partition the vertex set of a graph G, thepartition-cut 〈X1, X2〉 is the set of edges of G that have one endpoint in X1 andthe other in X2.

The fundamental edge-cut of a connected graph G associated with removal of an edgee from a spanning tree T is the partition-cut 〈X1, X2〉 where X1 and X2 are the vertexsets of the two components of T − e.

The fundamental system of edge-cuts of a connected graph G associated with aspanning tree T is the set of fundamental edge-cuts that result from removal of an edgefrom the tree T .

Algorithm 1: Depth-first search spanning tree.

input: a connected n-vertex graph G and a starting vertex r

output: the edge set ET of a spanning tree and an array X [1..n] listing VG in

DFS order

initialize all vertices as unvisited and all edges as unused

ET := ∅; loc := 1

dfs(r)

procedure dfs(u)

mark u as visited

X [loc] := u

loc := loc+ 1

while vertex u has any unused edges

e := next unused edge at u

Page 19: Combinatorics - Routledge

Section 9.2 SPANNING TREES 707

mark e as used

w := the other endpoint of edge e

if w is unvisited then

add e to ET

dfs(w)

Algorithm 2: Breadth-first search spanning tree.

input: a connected n-vertex graph G and a starting vertex r.

output: the edge set ET of a spanning tree and an array X [1..n] listing VG in

BFS order

initialize all vertices as unvisited and all edges as unused

ET := ∅; loc := 1; Q := r {Q is a queue}

while Q 6= ∅

x := front(Q)

remove x from Q

bfs(x)

procedure bfs(u)

mark u as visited

X [loc] := u

loc := loc+ 1

while vertex u has any unused edges

e := next unused edge at u

mark e as used

w := the other endpoint of edge e

if w is unvisited then

add e to ET

add w to the back of Q

Facts:

1. Every connected graph has at least one spanning tree.

2. A connected graph G has k edge-disjoint spanning trees if and only if for everypartition of VG into m nonempty subsets, there are at least k(m − 1) edges connectingvertices in different subsets.

3. Let T and T ′ be spanning trees of a graph G and e ∈ T − T ′. Then there exists anedge e′ ∈ T ′

− T such that both T − e ∪ {e′} and T ′− e′ ∪ {e} are spanning trees of G.

4. In the column vector space of the incidence matrix of G over Z2, every edge set canbe represented as a sum of column vectors. Let T be a spanning tree of G. Then eachcycle C can be written in a unique way as a linear combination of the fundamental cyclesof whatever chords of T occur in C.

Page 20: Combinatorics - Routledge

708 Chapter 9 TREES

5. Depth-first search on an n-vertex, m-edge graph runs in O(m) time.

6. DFS-trees are used to find the components, cutpoints, blocks, and cut-edges of agraph.

7. The unique path in the BFS-tree T of a graph G from its root r to a vertex v is ashortest path in G from r to v.

8. Breadth-first search on an n-vertex, m-edge graph runs in O(m) time.

9. A BFS-tree in a simple graph has no back edges.

10. Dijkstra’s algorithm (see §10.3.2) constructs a spanning tree T in an edge-weightedgraph such that for each vertex v, the unique path in T from a specified root r to vis a minimum-cost path in the graph from r to v. When all edges have unit weights,Dijkstra’s algorithm produces the BFS tree.

11. The level order of the vertices of an ordered tree is the order in which they wouldbe traversed in a breadth-first search of the tree.

12. The fundamental cycle of an edge e with respect to a spanning tree T such thate /∈ T consists of edge e and those edges of T whose fundamental edge-cuts contain e.

13. The fundamental edge-cut with respect to removal of edge e from a spanning tree Tconsists of edge e and those edges of EG − ET whose fundamental cycles contain e.

Examples:

1. Consider the following graph and spanning tree and a digraph on the same vertexand edge set. The tree edges are a, b, c, e, f, h, k, l, and the chords are d, g, i, j. Chord dis a forward edge, chord i is a back edge, and chords g and j are cross edges.

a b

ed

gf

c

h

l

i j k

a b

ed

gf

c

h

l

i j k

2. In the graph of Example 1, the fundamental cycles of the chords d, g, i, and j are{d, b, e}, {g, f, c, a, b, e}, {i, h, l}, and {j, f, h, l}, respectively. The non-fundamental cycle{a, d, g, c, f} is the sum (mod 2) of the fundamental cycles of chords d and g.

3. A spanning tree and its fundamental system of cycles are shown next.

u a v

b c d

x e w

u

b c

x e w

u a v

c d

w

4. A spanning tree and its fundamental system of edge-cuts are shown next.

u v

c d

x e w

u

b

x e w

u a v

d

w

u a v

b c d

x e w

5. In the graph of Example 1 suppose that the local order of adjacencies at each vertexis the alphabetic order of the edge labels. Then the construction of the DFS-tree is shownin the following figure.

Page 21: Combinatorics - Routledge

Section 9.2 SPANNING TREES 709

1

6

2d e

3

4

7 98

5

a

f

c

h

l

i j k

g

b1

6

2d e

3

4

7 98

5

a

f

c

h

l

i j k

g

b1

6

2

d e

3

4

7 98

5

a

f

c

h

l

i j k

g

b

1

6

2d e

3

4

7 98

5

a

f

c

h

l

i j k

g

b1

6

2d e

3

4

7 98

5

a

f

c

h

l

i j k

g

b

1

6

2d e

3

4

7 98

5

a

f

c

h

l

i j k

g

b1

6

2d e

3

4

7 98

5

a

f

c

h

l

i j k

g

b

1

6

2

d e

3

4

7 98

5

a

f

c

h

l

i j k

g

b

6. In the graph of Example 1 suppose that the local order of adjacencies at each vertexis the alphabetic order of the edge labels. Then the construction of the BFS-tree is shownin the following figure.

1

3

2d e

4

5

7 98

6

a

f

c

h

l

i j k

g

b1

3

2d e

4

5

7 98

6

a

f

c

h

l

i j k

g

b1

3

2d e

4

5

7 98

6

a

f

c

h

l

i j k

g

b

1

3

2d e

4

5

7 98

6

a

f

c

h

l

i j k

g

b1

3

2d e

4

5

7 98

6

a

f

c

h

l

i j k

g

b 1

3

2d e

4

5

7 98

6

a

f

c

h

l

i j k

g

b

1

3

2d e

4

5

7 98

6

a

f

c

h

l

i j k

g

b1

3

2d e

4

5

7 98

6

a

f

c

h

l

i j k

g

b

9.2.2 ENUMERATION OF SPANNING TREES

Definitions:

The number of spanning trees τ(G) of a graph G counts two spanning trees T1 and T2as different if their edge sets are different, even if there is an automorphism of G mappingT1 onto T2.

The degree matrix D(G) of an n-vertex graph G with vertex degree sequence d1, . . . , dnis the n× n diagonal matrix in which the elements of the main diagonal are the degreesd1, . . . , dn (and the off-diagonal elements are 0s).

Page 22: Combinatorics - Routledge

710 Chapter 9 TREES

Facts:

1. Cayley’s formula: τ(Kn) = nn−2, where Kn is the complete graph.

2. τ(Km,n) = mn−1nm−1, where Km,n is the complete bipartite graph.

3. τ(Is ∗ Kn−s) = nn−2 (1− s/n))s−1, where Is is the edgeless graph on n verticesand “∗” denotes the join (see §8.1.2).

4. τ(Wn) =(

3+√5

2

)n+(

3−√5

2

)n− 2, where Wn denotes the wheel with n rim vertices.

5. Matrix-tree theorem: For each s and t, the value τ(G) equals (−1)s+t times thedeterminant of the matrix obtained by deleting row s and column t from D(G)−A(G),where A(G) is the adjacency matrix for G.

6. For each edge e of a graph G, τ(G) = τ(G − e) + τ(G/e), where “−e” denotes edgedeletion and “/e” denotes edge contraction.

7. The number of spanning trees of Kn with degrees d1, . . . , dn equals(

n−2

d1−1,...,dn−1

)

(see §2.3.2). In this formula, the vertices are distinguishable (labeled) and are giventheir degrees in advance, and the only question is how to realize them with edges.

Examples:

1. τ(K3) = 33−2 = 3. Each of the three spanning trees is a path on two edges, asillustrated below. Also, τ(K4) = 44−2 = 16.

2. τ(K2,n) = n2n−1. To confirm this, let X = {x1, x2} and |Y | = n. The spanning treecontains a path of length 2 joining x1 to x2, whose middle vertex in Y can be chosenin n ways. For each of the remaining n− 1 vertices of Y , there is a choice as to which ofx1 and x2 is its neighbor (not both, since that would create a cycle).

3. τ(I3 +K2) = 53(1− 3

5

)2= 20.

4. τ(W4) =(

3+√5

2

)4+(

3−√5

2

)4− 2 = 45.

5. To illustrate the matrix-tree theorem, consider the following graph G. Then

1 2

43

D(G) −A(G) =

3 −1 −1 −1

−1 2 0 −1

−1 0 2 −1

−1 −1 −1 3

.

Deleting row 2 and column 3, for example, yields

τ(G) = (−1)2+3

∣∣∣∣∣∣∣

3 −1 −1

−1 0 −1

−1 −1 3

∣∣∣∣∣∣∣= 8.

The eight spanning trees of G are

Page 23: Combinatorics - Routledge

Section 9.3 ENUMERATING TREES 711

1 2

43

1 2

43

1 2

43

1 2

43

1 2

43

1 2

43

1 2

43

1 2

43

6. The recursive formula τ(G) = τ(G−e)+τ(G/e) is illustrated with the same graph Gof the previous example and with e = v1v4. In the computation G is drawn instead ofwriting τ(G), and similarly with the other graphs. This yields

1 2

3 4

=

1 2

3 4

+

3

1⋅4

2

7. Let the vertices ofK5 be v0, v1, v2, v3, v4. The number of spanning trees ofK5 in whichthe degrees of v0, v1, v2, v3, v4 are 3, 2, 1, 1, 1, respectively, is given by the multinomialcoefficient

(5−2

3−1,2−1,1−1,1−1,1−1

)= 3!

2!·1!·0!·0!·0! = 6

2·1·1·1·1 = 3. The three trees in questionare

v0

v1

v0 v0

v1 v1v4 v4 v4

v3 v2 v3 v2 v3 v2

9.3 ENUMERATING TREES

Tree counting began with Arthur Cayley in 1889, who wanted to enumerate the saturatedhydrocarbons. George Polya developed an extensive theory in 1937 for counting familiesof organic chemicals, which was used by Richard Otter in 1948 in his solution of thespecific problem of counting saturated hydrocarbons. Tree counting formulas are usedin computer science to estimate running times in the design of algorithms.

9.3.1 COUNTING GENERIC TREES

When counting generic trees, we must be careful to distinguish among labeled trees,rooted trees, unlabeled trees, and various other objects. While labeled trees can becounted easily, unlabeled trees, both rooted and unrooted, are typically counted usinggenerating functions.

Definitions:

A labeled tree is a tree in which distinct labels, typically v1, v2, . . . , vn, have beenassigned to the vertices. Two labeled trees with the same set of labels are considered thesame only if there is an isomorphism from one to the other that preserves the labels.

Page 24: Combinatorics - Routledge

712 Chapter 9 TREES

A rooted tree is a tree in which one vertex, the root, is distinguished. Two rooted treesare considered the same only if there is an isomorphism from one to the other that mapsthe root of the first to the root of the second.

A rooted labeled tree is a labeled tree in which one vertex, the root, is distinguished.Two rooted labeled trees with the same set of labels are considered the same only if thereis an isomorphism from one to the other that preserves the labels and maps the root ofthe first to the root of the second.

A reduced tree (or irreducible tree) is a tree with no vertices of degree 2.

Examples:

1. The figure below shows the three isomorphically distinct trees with five vertices.There are 60 essentially different ways to label each of the first two and five essentiallydifferent ways to label the third. Thus there are 125 different labeled trees with fivevertices.

2. There are three essentially different ways to root the first tree in the figure of Ex-ample 1, four essentially different ways to root the second, and two essentially differentways to root the third. Thus there are nine rooted (unlabeled) trees with five vertices.

3. Each of the 125 labeled trees discussed in Example 1 can be rooted at any of its fivevertices, yielding 625 possible rooted labeled trees.

4. The third tree in the figure of Example 1 is the only reduced tree with five vertices.

Facts:

1. The number of labeled trees with n vertices is nn−2. See Table 1. This is sequenceA000272 in [OEIS].

2. The number of rooted labeled trees with n vertices is nn−1. See Table 1. This issequence A000169 in [OEIS].

Table 1: Labeled trees and rooted labeled trees with n vertices.

n Labeled Trees Rooted Labeled Trees

1 1 1

2 1 2

3 3 9

4 16 64

5 125 625

6 1,296 7,776

7 16,807 117,649

8 262,144 2,097,152

9 4,782,969 43,046,721

10 100,000,000 1,000,000,000

11 2,357,947,691 25,937,424,601

12 61,917,364,224 743,008,370,688

Page 25: Combinatorics - Routledge

Section 9.3 ENUMERATING TREES 713

n Labeled Trees Rooted Labeled Trees

13 1,792,160,394,037 23,298,085,122,481

14 56,693,912,375,296 793,714,773,254,144

15 1,946,195,068,359,375 29,192,926,025,390,625

16 72,057,594,037,927,936 1,152,921,504,606,846,980

3. Let Rn denote the number of (unlabeled) rooted trees with n vertices, and let r(x)be the generating function for rooted trees, so that

r(x) =

∞∑

n=1

Rnxn = x+ x2 + 2x3 + 4x4 + 9x5 + 20x6 + · · · .

The coefficients Rn of this generating function can be determined by means of the recur-rence relation

r(x) = x

∞∏

k=1

(1 − xk)−Rk .

See Table 2. This is sequence A000081 in [OEIS].

Table 2: Rooted trees, trees, and reduced trees with n vertices.

n Rooted Trees Trees Reduced Trees

1 1 1 1

2 1 1 1

3 2 1 0

4 4 2 1

5 9 3 1

6 20 6 2

7 48 11 2

8 115 23 4

9 286 47 5

10 719 106 10

11 1,842 235 14

12 4,766 551 26

13 12,486 1,301 42

14 32,973 3,159 78

15 87,811 7,741 132

16 235,381 19,320 249

17 634,847 48,629 445

18 1,721,159 123,867 842

19 4,688,676 317,955 1,561

20 12,826,228 823,065 2,988

21 35,221,832 2,144,505 5,671

22 97,055,181 5,623,756 10,981

23 268,282,855 14,828,074 21,209

24 743,724,984 39,299,897 41,472

Page 26: Combinatorics - Routledge

714 Chapter 9 TREES

n Rooted Trees Trees Reduced Trees

25 2,067,174,645 104,636,890 81,181

26 5,759,636,510 279,793,450 160,176

27 16,083,734,329 751,065,460 316,749

28 45,007,066,269 2,023,443,032 629,933

29 126,186,554,308 5,469,566,585 1,256,070

30 354,426,847,597 14,830,871,802 2,515,169

4. Let Tn denote the number of trees with n vertices, and let t(x) be the generatingfunction for trees, so that

t(x) =

∞∑

n=1

Tnxn = x+ x2 + x3 + 2x4 + 3x5 + 6x6 + · · · .

The coefficients Tn of this generating function t(x) can be determined from the generatingfunction r(x) for rooted trees in Fact 3 above by using the formula

t(x) = r(x) − 1

2

(r2(x)− r(x2)

).

See Table 2. This is sequence A000055 in [OEIS].

5. Counting reduced trees requires an auxiliary sequence Qn with generating functionq(x), so that

q(x) =

∞∑

k=1

Qkxk = x+ x3 + x4 + 2x5 + 3x6 + 6x7 + 10x8 + · · · .

The coefficients Qi of this generating function can be determined from the recurrencerelation

q(x) =x

1 + x

∞∏

k=1

(1− xk)−Qk .

This is sequence A001678 in [OEIS].

6. Let Hn denote the number of reduced trees with n vertices, and let h(x) be thegenerating function for reduced trees, so that

h(x) =

∞∑

n=1

Hnxn = x+ x2 + x4 + x5 + 2x6 + 2x7 + 4x8 + · · · .

The coefficients Hn of this generating function h(x) can be determined from the auxiliaryfunction q(x) in Fact 5 above by using the formula

h(x) = (1 + x)q(x) −

(1 + x

2

)q2(x) +

(1− x

2

)q(x2).

See Table 2. Note that there are no reduced trees with exactly 3 vertices. This is sequenceA000014 in [OEIS].

Page 27: Combinatorics - Routledge

Section 9.3 ENUMERATING TREES 715

9.3.2 COUNTING TREES IN CHEMISTRY

Definitions:

A 1-4 tree is a tree in which each vertex has degree 1 or 4.

A 1-rooted 1-4 tree is a 1-4 tree rooted at a vertex of degree 1.

Remarks:

1. The 1-4 trees model many types of organic chemical molecules such as saturatedhydrocarbons or alkanes. These molecules have the chemical formula CnH2n+2 andconsist of n carbon atoms of valence 4 and 2n+ 2 hydrogen atoms of valence 1.

2. The 1-rooted 1-4 trees model the monosubstituted hydrocarbons such as the alcoholswith the chemical formula CnH2n+1OH and consisting of n carbon atoms, 2n+1 hydrogenatoms, and an OH group.

3. It is convenient when counting alcohols to include the water molecule HOH as anhonorary alcohol.

Examples:

1. The figure below shows the three different 1-4 trees with five vertices of degree 4 and12 vertices of degree 1.

H H H H H

H

H H

H H H H

C C

H

H H

H

H

H

H

C

H

H

H C

H

H HC

C C CC C

H

CH H

H

C

C

H

H

HH

C

H

H

H

C

2. The first 1-4 tree in Example 1 can be rooted at a vertex of degree 1 in three essentiallydifferent ways, the second in four essentially different ways, and the third in essentiallyonly one way. Thus there are eight different 1-rooted 1-4 trees with five vertices of degree4.

Facts:

1. A 1-4 tree with n vertices of degree 4 always has 2n+ 2 vertices of degree 1.

2. Let An denote the number of 1-rooted 1-4 trees with n vertices of degree 4, and leta(x) be the generating function for the number of 1-rooted 1-4 trees, so that

a(x) =

∞∑

n=0

Anxn = 1 + x+ x2 + 2x3 + 4x4 + 8x5 + 17x6 + · · · .

The coefficients An of this generating function a(x) can be determined from the recur-rence relation

a(x) = 1 + x6

(a3(x) + 3a(x)a(x2) + 2a(x3)

).

See Table 3. This is sequence A000598 in [OEIS].

Page 28: Combinatorics - Routledge

716 Chapter 9 TREES

Table 3: 1-Rooted 1-4 trees and 1-4 trees with n vertices of degree 4.

n 1-Rooted 1-4 Trees 1-4 trees

1 1 1

2 1 1

3 2 1

4 4 2

5 8 3

6 17 5

7 39 9

8 89 18

9 211 35

10 507 75

11 1,238 159

12 3,057 355

13 7,639 802

14 19,241 1,858

15 48,865 4,347

16 124,906 10,359

17 321,198 24,894

18 830,219 60,523

19 2,156,010 148,284

20 5,622,109 366,319

21 14,715,813 910,726

22 38,649,152 2,278,658

23 101,821,927 5,731,580

24 269,010,485 14,490,245

25 712,566,567 36,797,588

26 1,891,993,344 93,839,412

27 5,034,704,828 240,215,803

28 13,425,117,806 617,105,614

29 35,866,550,869 1,590,507,121

30 95,991,365,288 4,111,846,763

3. Counting (unrooted) 1-4 trees requires first counting 1-4 trees rooted at a vertex ofdegree 4. Let Zn be the number of 4-rooted 1-4 trees with n vertices of degree 4, and letz(x) be the generating function for the number of 4-rooted 1-4 trees, so that

z(x) =∞∑

n=1

Znxn = x+ x2 + 2x3 + 4x4 + 9x5 + 18x6 + · · · .

The coefficients Zn of this generating function z(x) can be obtained by using the formula

z(x) = x24

(a4(x) + 6a2(x)a(x2) + 8a(x)a(x3) + 3a2(x2) + 6a(x4)

),

where a(x) is the generating function for 1-rooted 1-4 trees from Fact 2. This is sequenceA000678 in [OEIS].

Page 29: Combinatorics - Routledge

Section 9.3 ENUMERATING TREES 717

4. Let Bn denote the number of (unrooted) 1-4 trees with n vertices of degree 4, andlet b(x) be the generating function for 1-4 trees, so that

b(x) =

∞∑

n=0

Bnxn = 1 + x+ x2 + x3 + 2x4 + 3x5 + 5x6 + · · · .

The coefficients Bn of this generating function b(x) can be determined from the functionsa(x) and z(x) from Facts 2 and 3, respectively, by using the formula

b(x) = z(x) + a(x) − 1

2

(a2(x)− a(x2)

).

See Table 3. This is sequence A000602 in [OEIS].

9.3.3 COUNTING TREES IN COMPUTER SCIENCE

Definitions:

A binary tree consists of a root vertex and at most two principal subtrees that arethemselves binary trees. Each principal subtree must be specified as either the leftsubtree or the right subtree. The root vertex of a binary tree is joined by an edge to theroot of each principal subtree.

An ordered tree consists of a root vertex and a sequence t1, t2, . . . , tm of m ≥ 0 principalsubtrees that are themselves ordered trees.

The children of the root vertex of an ordered tree or a binary tree are the roots of theprincipal subtrees.

A full binary tree (sometimes called a left-right tree) is a binary tree in which eachvertex has either 0 or 2 children.

Examples:

1. The following figure shows the five binary trees with three vertices.

2. The next figure shows the five ordered trees with four vertices.

3. The following figure shows the five full binary trees with seven vertices.

Page 30: Combinatorics - Routledge

718 Chapter 9 TREES

Remarks:

1. In computer science, trees are usually drawn with the root at the top.

2. Binary trees are easily represented in a computer. Other types of trees are oftenconverted into binary trees for computer representation.

3. Ordered trees are used to represent structures such as family trees, showing all descen-dants of a person represented by the root. The roots of the principal subtrees representthe children of the root person, in order of birth.

4. Full binary trees are frequently used to represent arithmetic expressions, in which theleaves correspond to numbers and the other vertices represent binary operations such as+ , − , × , or ÷ .

Facts:

1. The number of binary trees with n vertices is the Catalan number Cn (see §3.1.3)given by the formula

Cn =1

n+ 1

(2n

n

)=

(2n)!

(n+ 1)!n!for n ≥ 0.

See Table 4. This is sequence A000108 in [OEIS].

Table 4: The Catalan numbers.

n Cn n Cn

1 1 17 129,644,790

2 2 18 477,638,700

3 5 19 1,767,263,190

4 14 20 6,564,120,420

5 42 21 24,466,267,020

6 132 22 91,482,563,640

7 429 23 343,059,613,650

8 1,430 24 1,289,904,147,324

9 4,862 25 4,861,946,401,452

10 16,796 26 18,367,353,072,152

11 58,786 27 69,533,550,916,004

12 208,012 28 263,747,951,750,360

13 742,900 29 1,002,242,216,651,368

14 2,674,440 30 3,814,986,502,092,304

15 9,694,845 31 14,544,636,039,226,909

16 35,357,670 32 55,534,064,877,048,198

2. The number of ordered trees with n vertices is the Catalan number Cn−1. See Table 4.

3. The number of full binary trees with 2n+ 1 vertices is also Cn. See Table 4.

Page 31: Combinatorics - Routledge

REFERENCES 719

REFERENCES

Printed Resources:

[Ca89] A. Cayley, A theorem on trees, Quarterly Journal of Pure and Applied Mathe-

matics 23 (1889), 376–378.

[GrYeZh13] J. Gross, J. Yellen, and P. Zhang, Handbook of Graph Theory, 2nd ed.,Chapman and Hall/CRC, 2013.

[HaPa73] F. Harary and E. M. Palmer, Graphical Enumeration, Academic Press, 1973.

[PoRe87] G. Polya and R. C. Read, Combinatorial Enumeration of Groups, Graphs, and

Chemical Compounds, Springer-Verlag, 1987.

[Ro11] K. H. Rosen, Discrete Mathematics and Its Applications, 7th ed., McGraw-Hill,2011.

[Se80] J. P. Serre, Trees, Springer-Verlag, 1980.

[Ta83] R. E. Tarjan, Data Structures and Network Algorithms, SIAM, 1983.

[We01] D. B. West, Introduction to Graph Theory, 2nd ed., Prentice-Hall, 2001.

Web Resources:

[OEIS] oeis.org (The On-Line Encyclopedia of Integer Sequences.)

www.cs.stonybrook.edu/~algorith/ (The Stony Brook Algorithm Repository.)

Page 33: Combinatorics - Routledge

ANALYTIC COMBINATORICS

#

This chapter is excerpted from

Introduction to Enumerative and Analytic Combinatorics, Second Edition

by Miklos Bona.

© 2015 Taylor & Francis Group. All rights reserved.

2

Learn more

Page 34: Combinatorics - Routledge

7

Analytic combinatorics

CONTENTS

7.1 Exponential growth rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3737.1.1 Rational functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374

7.1.1.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3747.1.1.2 Theoretical background . . . . . . . . . . . . . . . . . . . . . . 374

7.1.2 Singularity analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3807.1.2.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3807.1.2.2 Analytic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3817.1.2.3 The complex versions of some well-known

functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3867.1.2.4 Singularities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3887.1.2.5 The main theorem of exponential

asymptotics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3897.2 Polynomial precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391

7.2.1 Rational functions again . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3917.2.1.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3927.2.1.2 Multiple singularities in rational functions . . . 393

7.3 More precise asymptotics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3967.3.1 Entire functions divided by (1− x) . . . . . . . . . . . . . . . . . . . . . 3967.3.2 Rational functions one more time . . . . . . . . . . . . . . . . . . . . . . . 399

7.4 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4007.5 Chapter review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4017.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4027.7 Solutions to exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4057.8 Supplementary exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414

It often occurs in enumerative combinatorics that obtaining an exact formulathat answers a question is difficult, or time consuming, or even impossible,while it is much easier to obtain a formula that approximates the exact solutionup to a specified level of precision. In this chapter, we consider examples ofthis phenomenon, and methods to apply in these situations. Unless otherwisenoted, all power series in this chapter are assumed to have complex coefficients.

373

Page 35: Combinatorics - Routledge

374 Introduction to Enumerative and Analytic Combinatorics

7.1 Exponential growth rates

As we will see, it is often reasonably easy to prove that a sequence growsroughly at the speed of the powers of a fixed positive real number. We startour excursion to analytic combinatorics at such sequences.

7.1.1 Rational functions

7.1.1.1 Motivation

What is larger, the number of compositions of 1000 into parts that are equalto 1 or 4, or the number of compositions of 1000 that are equal to 2 or 3?

If an denotes the number of the former, and bn denotes the number of thelatter, then it is easy to prove by the methods of Chapter 3 that

A(x) =∑n≥0

anxn =

1

1− x− x4, (7.1)

and

B(x) =∑n≥0

bnxn =

1

1− x2 − x3. (7.2)

In theory, nothing prevents us from finding the partial fraction decompo-sitions of A(x) and B(x), deducing exact formulas for an and bn, and thencomparing the values of a1000 and b1000. However, in practice, that proce-dure would be exceedingly cumbersome. The partial fraction decompositionsof A(x) and B(x) would contain fractions with complex numbers, and theexact formulas obtained for an and bn would not be particularly pleasant.Comparing the values for n = 1000 could pose another problem.

It is therefore a natural question to ask if we can proceed in a simpler way.Is there a way to decide which of the two sequences will grow faster simply byperusing their generating functions, and not computing the actual numbersan and bn?

Fortunately, the answer to that question is in the affirmative. In this sectionwe develop the tools to see why and how.

7.1.1.2 Theoretical background

The following definition will be our crucial tool in describing how fast a givensequence grows.

Definition 7.1 Let s0, s1, s2, . . . be an infinite sequence of complex numbers.Let α be a real number. We say that the sequence has exponential growth rateα if

Page 36: Combinatorics - Routledge

Analytic combinatorics 375

1.the sequence of the numbers sn does not have an infinite subse-quence r1, r2, · · · for which

limn≥∞

n√|rn| > α,

and

2.the sequence of the numbers sn does have an infinite subsequencer1, r2, · · · for which

limn≥∞

n√|rn| = α.

In other words, α is the largest number so that there is an infinite subse-quence of the sequence s1, s2, · · · , (or, in what follows, the sequence sn) forwhich the limit of the absolute values of the nth roots of the elements is α.Yet in other words, α = lim supn≥1

n√|sn|.

Example 7.2 Let sn = n · 2n. Then the sequence of the numbers sn hasexponential growth rate 2.

Solution: This follows from the fact that n√sn = 2 n

√n→ 2. ♦

Example 7.3 Let sn = 2n/n100. Then the sequence of the numbers sn hasexponential growth rate 2.

Solution: This follows from the fact that n√sn = 2/

n√n100 → 2. ♦

The two examples above show that two sequences can differ by a largepolynomial factor and still have the same exponential growth rate. This isbecause polynomial factors are much smaller than exponential ones. Indeed, aslimn→∞

n√|p(n)| = 1 for any nonzero polynomial p(n), multiplying or dividing

a sequence by any nonzero polynomial will not change its growth rate. Notethat it follows that, if fn = p(n) for some nonzero polynomial p, then theexponential order of the sequence fn is 1.

Example 7.4 Let sn = 3n + (−3)n. Then the sequence of the numbers snhas exponential growth rate 3.

Note that, in the last example, every other term is 0, but that does notaffect the exponential growth rate of the sequence. It is the infinite subse-quence with the highest growth rate that provides the growth rate of thewhole sequence. In this case, that is the subsequence rn = s2n.

It goes without saying that not all sequences have a finite growth rate.Recall that the notation f(x) ∼ g(x) means that limx→∞ f(x)/g(x) = 1.As sequences are functions whose domain is the set of natural numbers, thisdefinition is meaningful for sequences as well.

Page 37: Combinatorics - Routledge

376 Introduction to Enumerative and Analytic Combinatorics

Example 7.5 Let an = n!. Then the sequence an has an infinite growth rate.

Solution: This can be proved by Stirling’s formula,which states that n! ∼(n/e)n

√2πn, so

√an ∼ n/e, which clearly diverges to infinity. We first

mentioned this formula in (1.13). Alternatively, one can use the fact thatan+1/an = n+ 1, which also diverges to infinity. ♦

This is not to say that if an ≥ n! holds for the elements of a sequence,then we cannot ask interesting questions about the sequence that involve ex-ponential growth rate. For instance, we can ask how much faster the sequencegrows than the sequence of factorials, by asking for the exponential growthrate of the sequence an/n!. This will be a particularly appropriate questionin cases when the exponential generating function of the sequence an can becomputed.

The reader is asked to prove the following propositions in SupplementaryExercise 2.

Proposition 7.6 Let the sequence fn have exponential growth rate a, andlet the sequence gn have exponential growth rate b, and let us assume that bothsequences consist of complex numbers. Let us assume that a > b. Then thesequence fn + gn has exponential growth rate a.

Note that Proposition 7.6 is not true without the condition that a > b. Acounterexample is fn = (−2)n and gn = (−2)n+1. Nevertheless, the followingweaker statement always holds.

Proposition 7.7 Let the sequence fn have exponential growth rate a, andlet the sequence gn have exponential growth rate b, and let us assume that bothsequences consist of complex numbers. Let us assume that a ≥ b. Then theexponential growth rate of fn + gn is at most a.

Proof: Let us assume the contrary, that is, that the sequence fn + gn has aninfinite subsequence si (where i ∈ I for some infinite set I of positive integers)that satisfies the inequality limi→∞ n

√si = a′ > a.

Consider the infinite subsequence si = fi + gi. Let I1 ⊆ I be the set ofindices for which |fi| ≥ |gi|, and let I2 ⊆ be the set of indices for which|fi| < |gi|. As I is infinite, so is at least one of I1 and I2. Let us assumewithouth loss of generality that I1 is infinite.

Now notice that, if i ∈ I1, then

|si| = |fi + gi| ≤ |fi|+ |gi| ≤ 2|fi|,

which implies that the sequence fi (where i ∈ I1) has exponential order atleast a′, contradicting our hypothesis. ♦

Now we start putting the growth rate of a sequence in the context ofgenerating functions. Note that, unless otherwise stated, all power series in

Page 38: Combinatorics - Routledge

Analytic combinatorics 377

this section are taken over the field of complex numbers, that is, they havecomplex coefficients. We are only assuming that the reader is familiar withboth ways of writing a complex number z, namely, the Cartesian way, whichsets z = x+iy, where x and y are real numbers, and the polar coordinate way,which sets z = reiφ, where r is a nonnegative real number and φ, called theargument of z, is an angle measured in radians. The reader is probably familiarwith basic complex arithmetics, that is, the reader knows how to add, subtract,multiply, and divide complex numbers, how to take their powers, and how tocompute their absolute values. We also assume that the reader is familiar withEuler’s formula, stating that

eiφ = cosφ+ i sinφ (7.3)

for all real numbers φ.Recall that a rational function is the ratio of two polynomials.

Definition 7.8 Let F (x) = P (x)/Q(x) be a rational function so that P (x)and Q(x) do not have any roots in common. Then the complex number x0 isa singular point of F (x) if Q(x0) = 0.

Example 7.9 The rational function

F (x) =x2 + 3x+ 2

(x− 1)2(x2 + 1)

has singular points x0 = 1, x0 = i, and x0 = −i.

Singular points of a rational function written in simplest terms are just theroots of the denominator. Still, the name singular point is worth introducingsince it will have a meaning for functions that are not rational functions aswell.

If r1 is a root of the polynomial Q(x), then we say that r1 is a root ofsmallest modulus of Q(x) if there is no root r2 of Q(x) that satisfies |r1| > |r2|.

The following theorem describes an easy way to find the exponentialgrowth rate of the sequence of coefficients of a rational function.

Theorem 7.10 Let

S(x) =∑n≥0

snxn =

P (x)

Q(x)

be a rational function with Q(0) 6= 0, let us assume that P (x) and Q(x) donot have any roots in common, and let us also assume that Q(x) has a uniqueroot r1 of smallest modulus.

Then the exponential growth rate of the sequence of the coefficients sn isequal to |z1|, where z1 = 1/r1.

Page 39: Combinatorics - Routledge

378 Introduction to Enumerative and Analytic Combinatorics

Note that the theorem holds even without the assumption that Q(x) has aunique root of smallest modulus, but it would be a bit cumbersome to provethat with our current tools. We will prove that version of the theorem in thenext section.

Proof: We can assume without loss of generality that Q(x) has constantterm 1. Indeed, dividing a power series by a constant does not change theexponential growth rate of its coefficients.

Now let Q(x) = (1−z1x)d1(1−z2x)d2 · · · (1−zkx)dk . In other words, let dibe the multiplicity of ri as a root of Q(x). Note that this equation is equivalentto Q(x) = C(r1 − x)d1(r2 − x)d2 · · · (rk − x)dk .

We can assume that the degree of Q(x) is larger than that of P (x). Thereader is asked to prove this simple fact in Exercise 1.

Then, just as the reader has seen in calculus, S(x) = P (x)/Q(x) has apartial fraction decomposition of the form

S(x) =C1,1

1− z1x+

C1,2

(1− z1x)2+ . . .+

C1,d1

(1− z1x)d1+ (7.4)

+C2,1

1− z2x+

C2,2

(1− z2x)2+ . . .+

C2,d2

(1− z2x)d2+ . . . (7.5)

+Ck,1

1− zkx+

Ck,2(1− zkx)2

+ . . .+Ck,dk

(1− zkx)dk, (7.6)

where the Ci,j are constants.Indeed, multiplying both sides by Q(x), we get an equality involving two

polynomials, one of which is obviously the polynomial P (x). Equating coeffi-cients of xn for all n, we can determine the values of each of the Ci,j .

So S(x) is a sum of a few power series, each of which is of the formCi,j/(1− zix)j . Which of these summands has a coefficient sequence with thehighest exponential growth rate? We know from the general version of thebinomial theorem (Theorem 3.2) that

1

(1− zix)j= (1− zix)−j =

∑n≥0

zni

(j + n− 1

j − 1

)xn.

As(j+n−1j−1

)is just a polynomial of degree j − 1 in n, it follows that the

exponential growth rate of the power series of this type is |zi|, for any j.Therefore, the sequence sn (the sequence of coefficients of S(x)) is the sum

of various sequences whose exponential growth rates |zi| we know, namely,

sn =

k∑i=1

dj∑j=1

Ci,jzni

(j + n− 1

j − 1

).

Recall that r1 is the only root of Q(x) that is of smallest modulus, so|z1| > |zi| for any i 6= 1. Therefore, the sum gn of all these sequences that do

Page 40: Combinatorics - Routledge

Analytic combinatorics 379

not involve z1 (those for which i 6= 1) has an exponential growth rate less than|z1| by Proposition 7.7. On the other hand, the sum fn of sequences that doinvolve z1 has exponential order |z1| since it simply equals zn1 times a nonzeropolynomial. Then our claim follows by Proposition 7.6. ♦

It is high time that we returned to the combinatorial example that wementioned at the beginning of Section 7.1.1.1. That question involved de-ciding whether the coefficients of A(x) = 1/(1 − x − x4) or the coefficientsof B(x) = 1/(1 − x2 − x3) grow faster. Theorem 7.10 tells us that, tofind these growth rates, we have to find the roots of smallest modulus ofthe two denominators. Using our favorite software package, we find that,for A(x), that root is about r1 = 0.7245, whereas for B(x), it is aboutr1 = 0.7549. Therefore, the exponential growth rate of the sequence an isequal to z1 = 1/0.7245 = 1.3803, whereas the exponential growth rate of thesequence bn is z1 = 1/0.7549 = 1.3247, so the sequence of the numbers angrows faster.

Let us consider further examples of finding the exponential growth rate ofa combinatorially defined sequence.

Example 7.11 Let hn be the number of words of length n over the alphabet{A,B,C} that do not contain the subword ABC in consecutive positions. Findthe exponential growth rate of the sequence of the numbers hn.

Solution: If we take a word w counted by hn and add one letter to its end,we get a word counted by hn+1, except when w ends in AB and the letter weadd to the end of w is C. This leads to the recurrence relation

hn+1 = 3hn − hn−2

for n ≥ 2, while h0 = 1, h1 = 3, and h2 = 9. Setting H(x) =∑n≥0 hnx

n, thedisplayed recurrence relation leads to the functional equation

H(x)− 9x2 − 3x− 1 = 3x(H(x)− 3x− 1)− x3H(x),

H(x) =1

1− 3x+ x3.

As any mathematical software package tells us, the root of smallest modulusof the denominator of H(x) is at x1 = 0.3473, so the exponential growth rateof the sequence of the numbers hn is 1/0.3473 = 2.8794. ♦

So the exponential growth rate of the sequence hn is a little bit below 3,which confirms our intuition, since the numbers of all words of length n overa 3-element alphabet has exponential growth rate 3.

This is a good time to mention that, in the rest of this chapter, we will oftenneed to find the root of a polynomial p(x) that is closest to 0, for polynomialsof degree larger than 2. In such situations, we will simply get that root froma software package.

Page 41: Combinatorics - Routledge

380 Introduction to Enumerative and Analytic Combinatorics

Example 7.12 We flip a fair coin n times. Let an be the number of pos-sible outcome sequences that do not contain four consecutive heads. Find theexponential order of the sequence of the numbers an.

Solution: We use Theorem 3.25. Let us first consider the acceptable outcomesequences that contain at least one tail. Each such sequence can be broken upinto three segments, namely the segment before the last tail, the last tail, andthe part after the last tail, which must be all heads, and must be of length atmost three.

If an acceptable outcome sequence does not contain a tail, then it is oflength at most three, and there is only one such sequence for each such length.

By Theorem 3.25, this leads to the functional equation

A(x) = A(x) · x · (1 + x+ x2 + x3) + 1 + x+ x2 + x3,

A(x) =x3 + x2 + x+ 1

1− x− x2 − x3 − x4.

The root of smallest modulus of the denominator is 0.5188, so the exponentialgrowth rate of the sequence of coefficients of an is 1/0.5188 ≈ 1.9276. ♦

We point out that limn→∞ 1.9276n/2n = 0, so the probability that a se-quence of length n of fair coin flips will contain four consecutive heads con-verges to 1 as n goes to infinity. The exponential growth rate of the numberof sequences without four consecutive heads is less than 2 (the exponentialgrowth rate for unrestricted coin flip sequences), but not by much. The readeris invited to explain what happens if we count sequences that do not contain kconsecutive heads instead of four consecutive heads. How will the exponentialgrowth rate of the sequence change? You are asked to answer this question inExercise 22.

7.1.2 Singularity analysis

It turns out that the concept of singular points can be extended to a class offunctions that is much larger than rational functions, and it is a very usefulnotion in that large class as well. This is the subject of this section.

7.1.2.1 Motivation

Example 7.13 A group of n tourists arrives at a restaurant. They sit downaround an unspecified number of circular tables. Then the manager counts thetables at which at least one tourist is sitting, finds that there are k of them,and numbers them from 1 through k. Let hn be the number of different waysall this can happen if two arrangements are considered identical if each personhas the same left neighbor in both of them, and each person sits at the sametable in both of them. Find the exponential growth rate of the sequence hn/n!.

Page 42: Combinatorics - Routledge

Analytic combinatorics 381

The alert reader may notice that the problem only differs from Example3.31 in that now the tables are numbered. It turns out that this is an impor-tant difference. (Recall that without numbering the tables, each arrangementis equivalent to a permutation. If we do number the tables, the number ofpossibilities clearly increases; the question is by how much, in the exponentialsense.)

Let hn be the number of arrangements we are trying to count. We willuse the compositional formula of exponential generating functions (Theorem3.36). We first partition the set of tourists into an unspecified number of non-empty blocks, then we put a cycle on each block, and then we linearly orderthe set of blocks. Therefore, ak = (k − 1)! if k ≥ 1, and bk = k!, so we have

A(x) =∑k≥1

(k − 1)!xk

k!=∑k≥1

xk

k= ln

(1

1− x

),

and

B(x) =∑k≥0

k!xk

k!=∑k≥0

xk =1

1− x.

Therefore, by the compositional formula, we have

H(x) = B(A(x)) =1

1− ln(

11−x

) . (7.7)

So we have obtained an explicit formula for the generating function H(x),but what good is it? We see that H(x) is not a rational function, so themethod of partial fractions will not work. Fortunately, there are stronger toolsavailable.

7.1.2.2 Analytic functions

In what follows, all functions are from C to C. A neighborhood of a point x0is any set that contains a circle centered at x0. The point x is a boundarypoint of the set S if all neighborhoods of x contain points that are in S andalso contain points that are not in S. A set is open if it contains none of itsboundary points, and closed if it contains all of them. Of course, many setsare neither open nor closed.

A set S in which any two points can be connected by a set of straight linesso that all those lines belong to S is called connected. A connected open setis called a domain, and a domain, together with a (possibly empty) subset ofits boundary points is called a region.

The main definition of this section is the following.

Definition 7.14 A function f that is defined in a region R is called analyticat x0 if it can be written as a convergent power series

f(x) =∑n≥0

an(x− x0)n (7.8)

Page 43: Combinatorics - Routledge

382 Introduction to Enumerative and Analytic Combinatorics

in a neighborhood U ⊆ R of x0, that is, if at all points x ∈ U , the sum on theright-hand side of (7.8) is convergent and is equal to f(x).

If R is a region, then we say that f is analytic in U if f is analytic at allpoints of R.

Example 7.15 The function f(x) = 1/(1− 2x) is analytic at x0 = 0.

Solution: We show that we can choose U to be the open circle centered at 0whose radius is 1/2. Indeed, let |x| < 0.5. Then we have

f(x) =1

1− 2x

=∑n≥0

2nxn,

and the last sum, which is a geometric series, converges since |2x| < 1. ♦

Clearly, f(x) = 1/(1 − 2x) is not analytic (or even defined) at x = 0.5.However, it turns out that x = 0.5 is the only point in the complex planewhere this function is not analytic.

Example 7.16 Let x0 6= 0.5. Then f(x) = 1/(1− 2x) is analytic at x0.

Solution: We have

f(x) =1

1− 2x

=1

1− 2x0 − (2x− 2x0)

=1

1− 2x0· 1

1− 2x−2x0

1−2x0

=1

1− 2x0·∑n≥0

(2x− 2x01− 2x0

)n=

∑n≥0

2n

(1− 2x0)n+1(x− x0)n.

Note that the last form of f(x) is just as it is required to be by (7.8), sincethe coefficient an = 2n

(1−2x0)n+1 does not depend on the changing x, just on

the fixed x0 and the index n. The last form of f(x) is 1/(1 − 2x0) times ageometric series, and as such, it is convergent if the quotient of that series hasabsolute value less than 1, that is, when∣∣∣∣ 2

1− 2x0(x− x0)

∣∣∣∣ < 1∣∣∣∣ x− x00.5− x0

∣∣∣∣ < 1.

Page 44: Combinatorics - Routledge

Analytic combinatorics 383

In other words, the power series form of f(x) about x0 is convergent wheneverx is closer to x0 than 0.5 is to x0, that is, when x is inside the circle centeredat x0 and of radius |x0 − 0.5|. This shows that f is analytic at x0, since wehave found a region around x0 where f(x) was representable in the form (7.8).If x0 = 0.5, then no x can be closer to x0 than 0.5, and so there is no circlecentered at x0 in which f(x) is convergent, hence f(x) is not analytic at thatpoint. ♦

So we have found that the function f(x) = 1/(1 − 2x) is analytic in ev-ery point where it is defined. This is not some exceptional property of thatfunction; this is true for all rational functions, as you are asked to prove in Sup-plementary Exercise 1. For instance, the rational function g(x) = 1

1−2x + 11−3x

is analytic everywhere, except at the points x0 = 1/2 and x1 = 1/3.It is an important property of power series that they are convergent inside

a (possibly infinite) circle and divergent outside that circle. This is true forpower series about any point, but for the sake of simplicity, we prove it forpower series about 0, which is the special case that we will use in applications.Recall that the series

∑n≥0 an is called absolutely convergent if the inequality∑

n≥0 |an| <∞ holds. You should spend a minute convincing yourself that, if∑n≥0 an is absolutely convergent, then it is also convergent.

Theorem 7.17 Let f(x) =∑n≥0 fnx

n be a power series. If f is not ab-solutely convergent for all x, then there exists a real number r so that f(x)is absolutely convergent if |x| < r, and f(x) is not absolutely convergent for|x| > r.

Proof: Let r be the least upper bound of the absolute values of all num-bers for which f(x) is absolutely convergent. Then, by the comparison test,∑n≥0 |fn||xn| is convergent if |x| < r, and not convergent if |x| > r, proving

our claim. ♦

The number r defined in Theorem 7.17 is called the convergence radius, orradius of convergence of f , while the circle of radius r centered at the originis called the circle of convergence of f .

Example 7.18 As we have seen in the discussion following the solution ofExample 7.16, the convergence radius of f(x) = 1/(1− 2x) is 0.5.

It is a well-known theorem in complex analysis that f is analytic at x0 ifand only if f is complex differentiable at x0, that is, the limit

limδ→0

f(x0 + δ)− f(x0)

δ

exists. Here δ is a complex number, and the limit is independent of the wayin which δ goes to 0.

Page 45: Combinatorics - Routledge

384 Introduction to Enumerative and Analytic Combinatorics

Figure 7.1The small circle c lies entirely inside the larger circle C.

The following lemma will be crucial in determining the exponential growthrate of the sequence of coefficients of power series. Roughly speaking, it showshow closely the the properties “convergent” and “analytic” are connected forpower series.

Lemma 7.19 Let f(x) =∑n≥0 fnx

n be a power series that is absolutelyconvergent at the positive real number m. Then f is analytic in each point ofthe open circle C given by |x| < m.

Note that the statement of the lemma is not obvious. Let x0 be a point inC. Then it does follow from the absolute convergence of f at m and Theorem7.17 that f(x0) is absolutely convergent as a power series about 0. However,the lemma claims that f can be represented by a convergent power series aboutx0. Also note that most combinatorial generating functions have nonnegativereal coefficients, and for such functions, the condition that f is absolutelyconvergent at m is equivalent to the condition that f is convergent at m.

Proof: Let x0 be a complex number in the circle C. Then there exists asmaller open circle c with center x0 and radius r < m − |x0| that is entirelyinside C. Indeed, we can just keep shrinking a circle centered at x0 until itsradius becomes smaller than m − |x0|. See Figure 7.1 for an illustration. Weclaim that, inside c, the function f can be written as a convergent power seriesabout x0, which will by definition imply that f is analytic at x0.

Let x be a point inside c, and let us notice that x = x0+(x−x0). Therefore,by the binomial theorem, we have

f(x) =∑n≥0

fn[x0 + (x− x0)]n =∑n≥0

n∑k=0

(n

k

)xn−k0 (x− x0)k. (7.9)

Note that, with the given conditions, the series on the far right-hand side of

Page 46: Combinatorics - Routledge

Analytic combinatorics 385

(7.9) is absolutely convergent, that is, the series∑n≥0

|fn|n∑k=0

(n

k

) ∣∣xn−k0

∣∣ |(x− x0)|k =∑n≥0

|fn|[|x0|+ |x− x0|]n

is convergent. This is because |x0| + |x − x0| < |x0| + m − |x0| = m, so|x0|+ |x− x0| is inside the circle of convergence of f .

Because of the absolute convergence we just mentioned, we can change theorder of summation in the power series on the far right-hand side of (7.9), andget the absolutely convergent power series

f(x) =∑k≥0

∑n≥0

fn

(n

k

)xn−k0

(x− x0)k.

This is a power series about x0 that is absolutely convergent, hence it isconvergent, proving our claim. (Note that, for each k, the coefficient of (x−x0)k

is a well-defined complex number, since it is a partial sum of an absolutelyconvergent sum.) ♦

We point out that the “converse” of Lemma 7.19 is not true. That is, iff(x) =

∑n≥0 fnx

n is divergent at some x, it can still happen that f(x) isanalytic at x. Recall that, in Example 7.16, we showed that f(x) = 1/(1−2x)is analytic in every point, except at x0 = 1/2. On the other hand, the powerseries form of f about 0, f(x) =

∑n≥0 2nxn, is only convergent when |x| <

1/2.It is a direct consequence of Theorem 7.17 and Lemma 7.19, that if f(x) is a

power series that is analytic at x = 0, and f has a convergence radius r about0, then f is analytic in the open circle |z| < r. The following fundamentaltheorem of complex analysis shows that this circle cannot be made any largerwithout losing the analytic property of f , in the following sense.

Theorem 7.20 Let f(x) be a power series that is analytic at x = 0, and letf have a finite convergence radius r. Then f has a singularity of modulus r.

We do not prove this theorem here since its proof requires Cauchy’s co-efficient formula, which in turn requires complex integration. The interestedreader can consult page 240 of [30] for a proof of this theorem and its followinginteresting version. If f(x) satisfies the conditions of Theorem 7.20, and onlynonnegative coefficients, then we can say even more. In that case, the positivereal number r is actually a singularity of f . Note that power series with non-negative coefficients are important for us, since all combinatorial generatingfunctions are in their class.

If f and g are both analytic at x0, then it is easy to see that so are thefunctions f +g, f −g, and fg. Furthermore, f/g is analytic at x0 if g(x0) 6= 0.This is true since the rules that we learned about the derivatives of f + g,f − g, fg, and f/g in real analysis hold in complex analysis as well.

Page 47: Combinatorics - Routledge

386 Introduction to Enumerative and Analytic Combinatorics

7.1.2.3 The complex versions of some well-known functions

The reader is certainly familiar with the functions ex, sinx, cosx, and sinx,tanx, as well as lnx and

√x if x is a real number. It turns out that all these

functions have an extension to the set of complex numbers. However, justas we have to be somewhat careful in the case of real numbers (we mustexclude negative numbers from the domain of

√x, nonpositive numbers from

the domain of lnx, and so on), we must be careful for complex numbers aswell. The goal is to extend these functions so that they are defined on a domainD that is as large as possible, the extended functions are analytic in D, andon real numbers the extended functions agree with their usual value.

Let z ∈ C, and let z = x + iy, where x and y are real numbers. As aconsequence of basic algebraic identities, we have

ez = ex+iy = ex · eiy = ex(cos y + i sin y).

In order to define sin z and cos z, let us notice that, by Euler’s formula(7.3), we have

eiy = cos y + i sin y,

ande−iy = cos y − i sin y

for all real numbers y. Therefore, adding two equations and dividing by two,we get that cos y = (eiy + e−iy)/2, while subtracting the second equationfrom the first and dividing by 2i, we get sin y = (eiy − e−iy)/2i for all realnumbers y. We use these equations to define sin and cos for complex numbers,by setting

cos z =eiz + e−iz

2

and

sin z =eiz − e−iz

2i.

We can then define tan z = sin z/ cos z, sec z = 1/ cos z, and so on.It is then straightforward to prove that ez, sin z, and cos z have the same

power series as their real versions. Those power series converge for all realnumbers; therefore, by Lemma 7.19, they are analytic everywhere. Functionsthat are analytic in the entire complex plane are called entire functions.

We have to be a little bit more careful when we extend the functions√x

and lnx to complex numbers. Clearly, in order to extend√x to the domain

of complex numbers, we want to define√z to be a complex number s so that

the equalitys2 = z (7.10)

holds. The problem is that there are two such complex numbers s for eachcomplex number z. Indeed, if z = reiφ, with r ∈ R, then both s1 =

√reiφ/2

and s2 =√rei(π+(φ/2)) are solutions of (7.10). However, we want z →

√z

Page 48: Combinatorics - Routledge

Analytic combinatorics 387

to be a function, and therefore we have to choose one of them to be√z.

Furthermore, we want z →√z to be an analytic function, so we have to make

these choices carefully. For instance, as we said, a function that is analytic atz0 is complex differentiable at z0, so in particular it is continuous at z0.

It turns out that there does not exist a function f(z) that is defined on allcomplex numbers, is analytic everywhere, satisfies f(x) =

√x if x ∈ R, and

satisfies f(z)2 = z for all z ∈ C. We leave the proof of this fact to textbooksin complex analysis, though readers are certainly welcome to think about iton their own. For the purposes of this book, we make the following definition.

Definition 7.21 Let z be a complex number that is not a negative real num-ber. This means that z = reiφ for some nonnegative real number r and a realnumber φ ∈ (−π, π). Then we set

√z =√reiφ/2.

Note that√z defined as above is sometimes called the principal square

root of z.

Example 7.22 If z = 4i = 4eiπ/4, then√z = 2eiπ/8.

It can be proved that the function f(z) =√z defined above is analytic

at z0 if and only if z0 is not a nonpositive real number. It is clear that f(z)is not analytic at negative real numbers, since it is not even defined there.Furthermore, and this is important for us,

√z is also not analytic at z0 = 0,

since there is no neighborhood U of that point so that f is defined in all ofU . It follows that, for instance, the function g(z) =

√1− 4z is not analytic at

z = 1/4.Note that the values of

√z1 and

√z2 are very different if |z1| = |z2|, and

z1 is a little bit above the negative half-axis, while z2 is a little bit below thathalf-axis. This gives an intuition about why the square root function does nothave an analytic extension to the entire complex plane.

In other words, we managed to extend the square root function to the slitcomplex plane, that is, the complex plane minus a half line. We chose thathalf line to be the half line of negative real numbers, which was arbitrary. Anyother half line starting at the origin would work, but the obtained functionwould never be analytic at the origin, since it would never be defined in a fullneighborhood of the origin.

The situation with logarithmic functions is similar. If we want to definethe natural logarithm of the complex number z, we are looking for a complexnumber s = x+ iy so that

z = es = ex · eiy = ex(cos y + i sin y). (7.11)

However, if we change y by 2kπ for some integer π, then cos y + i sin ydoes not change. So there are infinitely many complex numbers s that satisfy(7.11). Therefore, we again need new restrictions in order to make “ complexlogarithm” a function.

Page 49: Combinatorics - Routledge

388 Introduction to Enumerative and Analytic Combinatorics

Definition 7.23 Let z ∈ C. If s = x + iy so that x ∈ R, while y ∈ [−π, π)and z = ex+iy holds, then we say that s is the logarithm of z, and we write

Log(z) = s.

In other words, we define the complex logarithm for nonzero complex num-bers in an infinite band of height 2π that is closed at the bottom and open atthe top. Note that Log(0) is not defined since ex 6= 0 for any real numbers x.

Example 7.24 As −e = e1−πi by Euler’s formula (7.3), we have Log(−e) =1− πi.

Note that Log(z) is sometimes called the principal branch of the complexlogarithm. We write Log(z) to distinguish the complex logarithm from its realversion, lnx. Note in particular that, keeping the notation of Definition 7.23,the equality

Log(z) = ln(ex) + y

holds, so if z ∈ R, then Log(z) = ln z. In particular, formula (7.7) remainstrue if we replace ln by Log in it.

It is again not difficult to prove that the function Log(z) is analytic in allnonzero points z = x+ iy that satisfy z ∈ R and y ∈ (−π, π).

7.1.2.4 Singularities

If f is not analytic at a point z0, then we say that z0 is a singularity or singularpoint of f . Note that this definition generalizes the way in which we definedsingularities of rational functions. Singularities of power series are crucial toolsin finding the growth rate of their coefficients.

There are numerous reasons that may cause f not to be analytic at z0. If fis given in power series form about a point z0, then of course f is not analyticat z0 if it is not convergent there. If f is given in a closed form, then of courseit can happen that f is not defined in a certain point z0, because the formulafor f involves a division by 0 at z0. Then f is certainly not analytic at z0.

Example 7.25 The function f(z) = 1(1−z)(1−2z) has singularities at z1 = 1

and z2 = 1/2.

Example 7.26 The function f(z) =√

1− 4z has a singularity at z = 1/4.

Indeed, we have just seen that the square root function is not analytic at 0.

Example 7.27 The function f(z) = Log(1− z) has a singularity at z = 1.

Indeed, we saw in Definition 7.23 that Log(0) is not even defined.

Page 50: Combinatorics - Routledge

Analytic combinatorics 389

7.1.2.5 The main theorem of exponential asymptotics

We have seen in Theorem 7.10 that if f is a power series that correspondsto a rational function, and f has a unique singularity of smallest modulus r1,then the exponential growth rate of the coefficients of f agrees with the 1/|r1|.Crucially, this holds for a much larger class of functions. This is the content ofthe next theorem, which is sometimes called the main theorem of exponentialasymptotics.

Theorem 7.28 Let f(x) =∑n≥0 fnx

n be a power series that is analytic at0, and let M be the modulus of a singularity of f that is closest to 0. Thenthe sequence fn has exponential growth rate 1/M .

Proof: Let us first assume that the sequence fn has exponential growth rateα < 1/M . Let α1 be such that α < α1 < 1/M . Then, for all but a finitenumber of indices n, the inequality |fn| ≤ αn1 holds. So, for these indices andfor every complex number x of modulus M , the inequality

|fnxn| ≤ αn1Mn = (α1M)n

holds. Let M1 be a positive real number that is “just a tiny bit larger” thanM . Formally speaking, let M1 > M so that M1α1 < 1 still holds. Such anumber M1 always exists, since Mα1 < 1.

Then the inequality α1M1 < 1 implies that f(x) =∑n≥0 fnx

n is conver-gent at all points x of modulus M1, so in particular, f(x) is convergent at thepositive real number M1 > M . Therefore, by Lemma 7.19, we know that f isanalytic at all points z with modulus less than M1. This is a contradiction,since f has a singularity of modulus M .

Now let us assume that the sequence fn has exponential growth rate β >1/M . Then there is a positive constant c so that there are infinitely manyindices n so that |fn| > cβn. Then, for all those indices n, the inequality∣∣∣∣fn · ( 1

β

)n∣∣∣∣ > c

holds, which implies that∑n≥0 fnx

n is divergent at the positive real number1/β < M . That means that M > 1/β > r, where r is the radius of convergenceof f . That is a contradiction, since by Theorem 7.20, we have M = r. ♦

Now we are in a position to answer the question that we asked in Example7.13. In order to find the exponential growth rate of the sequence hn/n!, allwe need to do is to find the singularity of H(x) that is of smallest modulus.It is easy to see that H(x) will have a singularity at x = 1, and another onewhen 1 = ln(1/(1 − x), that is, when e = 1/(1 − x), or x = 1 − e−1. Clearly,the latter is the singularity of smallest modulus, showing that the exponentialgrowth rate of the sequence hn/n! is

1

1− e−1=

e

e− 1∼ 1.582.

Page 51: Combinatorics - Routledge

390 Introduction to Enumerative and Analytic Combinatorics

So numbering the tables increases the exponential growth rate of the numberof possibilities by 1.582.

Example 7.29 Let rn be the number of lattice paths from (0, 0) to (n, n)that use only the steps (1, 0), (0, 1), and (1, 1) that never go above the maindiagonal. Find the exponential growth rate of the sequence rn.

Solution: We have seen in Exercise 24 of Chapter 3 that

R(x) =∑n≥0

rnxn =

1− x−√

1− 6x+ x2

2x.

It is easy to check that x = 0 is a root of multiplicity one of both the numeratorand the denominator of R(x), so R(x) is analytic at x = 0. Therefore, thesingularity of smallest modulus of R(x) is the smallest root of the expressionunder the square root sign, namely, M = 3 − 2

√2. Therefore, by Theorem

7.28, the sequence rn (the Schroder numbers) has exponential growth rate1/M = 3 + 2

√2 ∼ 5.828. ♦

Example 7.30 Let hn be the number of ways an n-person race can end iftwo-way and three-way ties are allowed. Find the exponential order of thesequence hn/n!.

Solution: In other words, hn is the number of ways to partition [n] into anynumber of blocks of size at most three, then to put an order on the set ofthe blocks. We can use the compositional formula of exponential generatingfunctions to compute H(x) =

∑n≥0 hn

xn

n! . There is no task to carry out oneach block, other than making sure that its size is at most three. This means

that ak = 1 if 1 ≤ k ≤ 3, and ak = 0 otherwise, so A(x) = x+ x2

2 + x3

3 . As the

blocks are to be linearly ordered, we have bm = m!, so B(x) =∑m≥0m!x

m

m! =1/(1− x). Therefore, the compositional formula implies

H(x) = B(A(x)) =1

1− x− x2

2 −x3

3

. (7.12)

Using a software package, we find that the root of the denominator that isclosest to the origin is at M ∼ 0.6725, so the exponential growth rate of thesequence hn/n! is 1/M ∼ 1.487. ♦

Finally, let us take a moment to mention the new, more general version ofTheorem 7.10, which is now a special case of Theorem 7.28.

Theorem 7.31 Let

S(x) =∑n≥0

snxn =

P (x)

Q(x)

Page 52: Combinatorics - Routledge

Analytic combinatorics 391

be a rational function with Q(0) 6= 0, and let us assume that P (x) and Q(x)do not have any roots in common. Let r1 be a root of Q(x) that is of smallestmodulus.

Then the exponential growth rate of the sequence of the coefficients sn isequal to |z1|, where z1 = 1/r1.

Note that, in contrast to Theorem 7.10, we no longer need the conditionthat Q(x) has a unique root of smallest modulus.

7.2 Polynomial precision

Sometimes it is possible to determine the growth rate of a sequence not onlywith “exponential ,” but also with “polynomial precision,” and sometimeseven more precisely. In this section, we will see examples of this phenomenon.

7.2.1 Rational functions again

Let us assume that two functions f(x) =∑n≥0 fnx

n and g(x) =∑n≥0 gnx

n

agree in their singularity s of smallest modulus. By Theorem 7.28, that meansthat their sequence of coefficients has the same exponential growth rate. Thisdoes not mean that fn ∼ gn, and there could be two reasons for that.

It can happen that it is the multiplicity of s that differs in f and g. Anexample for this is when f(x) = 1/(1 − 3x) and g(x) = 1/(1 − 3x)2. In thefirst case, we have f(x) =

∑n≥0 3nxn, while in the second case, we have the

somewhat different formula g(x) =∑n≥0(n + 1)3nxn. So gn/fn = n + 1 for

all n, which implies that gn/fn →∞.It could also happen that the type of s as a singularity is different in f

and g, for example, when f(x) = 1/(1 − x), g(x) = 1 −√

1− x, or evenh(x) = ln(1/(1 − x)). All three functions have a singularity of multiplicity 1at x = 1, but the type of that singularity is different in each case. In f(x),it is caused by a division by 0 in a rational function; in g(x), it is caused bythe fact that the square root function is not analytic at 0; and in h(x), it iscaused by the fact that logarithm as a function is not analytic at 0.

Note that f(x) =∑n≥0 x

n, g(x) =∑n≥1

(2n−3)!!2n·n! (by the binomial theo-

rem, with exponent 1/2), and h(x) =∑n≥1

xn

n , so the coefficient sequencesare quite different in size, even though they all have exponential growth rate1.

The analysis of how the type of a singularity influences that growth rate ofthe coefficient sequence of a power series goes beyond the scope of this book.However, for rational functions, we will analyze the effect of the multiplicitiesof singularities of rational functions.

Page 53: Combinatorics - Routledge

392 Introduction to Enumerative and Analytic Combinatorics

7.2.1.1 Motivation

Let us assume that we want to know the number of ways to pay n dollarsusing only 1-dollar, 2-dollar, and 5-dollar bills. We have seen in Example 3.17that, if hn denotes the number of ways to do that, then

H(x) =∑n≥0

hnxn =

1

(1− x)(1− x2)(1− x5). (7.13)

So H(x) has a singularity at z whenever the first, second, or fifth power of zis equal to 1. Clearly, all these singularities are at distance 1 from 0, so, byTheorem 7.28, the exponential order of the numbers hn is 1.

This is not a very satisfying result. Let us, for instance, consider the fol-lowing. Let gn be the number of ways to pay n dollars using only 1-dollar,2-dollar, 5-dollar, and 10-dollar bills. Then clearly,

G(x) =∑n≥0

gnxn =

1

(1− x)(1− x2)(1− x5)(1− x10). (7.14)

The numbers g(n) also have exponential order 1, since all singularities of theirgenerating function are of modulus 1. Still, it is clear that, for large n, thenumber gn will be much larger than the number hn, since pairs of 5-dollarbills can be turned into 10-dollar bills.

What this shows is that two sequences can be quite different even if theyhave the same exponential growth rate. The exponential growth rate is notsubtle enough to express smaller differences between two sequences.

Therefore, we introduce a new, more refined way to measure the growthrate of sequences. We will say that we have described the growth rate of asequence fn at polynomial precision if we found the exponential growth rateα of fn, together with the largest real number k so that fn has an infinitesubsequence fni for which

fni ∼ Cαnnk (7.15)

holds, for some constant C. In other words,

limn→∞

fni

αnnk= C.

Note that not all sequences will fit in this framework. For instance, thesequence fn = ln(n+ 1) will not, since it grows slower than any nonconstantpolynomial. However, the growth of many sequences can be determined atpolynomial precision.

Example 7.32 Let fn = (n3 + 3)2n/(2n2 − 7). Then the formula

fn ∼1

2· 2n · n

describes the growth rate of fn at polynomial precision.

Page 54: Combinatorics - Routledge

Analytic combinatorics 393

Example 7.33 Let fn =(2nn

)/(n+ 1), that is, let fn denote the nth Catalan

number. Then the formula

fn ∼1√π· 4n · n−3/2

describes the growth rate of fn at polynomial precision.

Solution: This follows from Stirling’s formula, stating that n! ∼ (n/e)n√

2πn,

and the fact that(2nn

)= (2n)!

n!n! . The reader is invited to work out the compu-tational details. ♦

7.2.1.2 Multiple singularities in rational functions

The following theorem helps us describe the growth of the sequence of coeffi-cients of a rational function at polynomial precision.

Theorem 7.34 Let

f(x) =∑n≥0

fnxn =

P (x)

Q(x)

be a rational function so that P (x) and Q(x) do not have roots in common, andlet Q(0) = 1. Let the roots of Q(x) be r1, r2, · · · , rk, and let the multiplicity ofri as a root of Q(x) be ai. Let us further assume that, if Q(x) has more thanone root of smallest modulus, then one of those roots has a higher multiplicitythan all the other roots of smallest modulus.

Then there exist polynomials p1, p2, · · · , pk so that, if n is large enough,then

fn =

k∑i=1

pi(n)r−ni . (7.16)

Furthermore, the degree of pi is ai − 1.Therefore, the growth rate of fn at polynomial precision is C(1/|rt|)nnat−1,

where C is a constant, rt is a root of Q(x) that has smallest modulus, and,among roots of smallest modulus, has maximal multiplicity at.

Proof: Set zi = 1/ri. As f is a rational function, it has a partial fractiondecomposition, as we have seen in Section 7.1.1. That is,

f(x) = p(x) +C1,1

1− z1x+

C1,2

(1− z1x)2+ . . .+

C1,a1

(1− z1x)a1(7.17)

+C2,1

1− z1x+

C2,2

(1− z1x)2+ . . .+

C2,a2

(1− z1x)a2+ . . . (7.18)

+Ck,1

1− zkx+

Ck,2(1− zkx)2

+ . . .+Ck,ak

(1− zkx)ak, (7.19)

Page 55: Combinatorics - Routledge

394 Introduction to Enumerative and Analytic Combinatorics

where p(x) is a polynomial function which is the zero polynomial if the degreeof P is less than the degree of Q, and the Ck,i are constants.

If n is large enough, then p(x) does not contain a term of degree n orhigher, so p(x) will not contribute to the coefficient fn of xn.

Just as we have seen in the proof of Theorem 7.10, we notice that thebinomial theorem implies

1

(1− zix)j= (1− zix)−j (7.20)

=∑n≥0

(−jn

)zni (−1)n (7.21)

=∑n≥0

(n+ j − 1

j − 1

)zni (7.22)

=∑n≥0

(n+ j − 1

j − 1

)r−ni . (7.23)

Now fix i, and consider the ith row of (7.17). Each summand in that row isof the required form (a polynomial times a power of the root ri with a negativeexponent); therefore, their sum is also of the required form. The exponentialgrowth rate of such a sequence is largest when ri is smallest, that is, whenri is a root of smallest modulus. Furthermore, we have just seen that thepolynomial that occurs in the sum form of 1

(1−zix)j is of degree j − 1, where

j is the multiplicity of ri as a root of Q. So, on the set of roots of smallestmodulus, this degree is maximized when ri is the unique root of smallestmodulus that has maximal multiplicity. ♦

Note that Theorem 7.34 remains true if we drop the condition that thereis a root of Q of smallest modulus that has a higher multiplicity than all otherroots of smallest modulus, but the proof is a little bit more complicated.

Now we can solve the initial example of this section. In that example,Q(x) = (1 − x)(1 − x2)(1 − x5), whereas P (x) = 1. So P (x) and Q(x) haveno roots in common (P has no roots at all), and the root r1 = 1 of Q(x) hasmultiplicity three, while the other five roots of Q(x) have multipilicity 1. SoTheorem 7.34 applies, and it yields

hn = p1(n) +6∑i=2

pir−ni ,

where p1 is a polynomial of degree two, while all the other pi are constants(polynomials of degree 0). Note that, for all i, we have |ri| = 1, so |r−ni | = 1,and so ∣∣∣∣∣

6∑i=2

pir−ni

∣∣∣∣∣ ≤6∑i=2

∣∣pir−ni ∣∣ =

6∑i=2

|pi| = C.

Page 56: Combinatorics - Routledge

Analytic combinatorics 395

That is, the term∑6i=2 pir

−ni will never have absolute value more than the

constant∑6i=2 |pi| = C, meaning that, for large n, the value of hn will be very

close to the value of the quadratic polynomial p1(n).It follows from (7.17) and (7.20) that p1(n) = C1

∑n≥0

(n+22

)for some

constant C1. Given the relatively simple form of P (x)/Q(x), the exact valueof C1 can be determined, even without actually computing the whole par-tial fraction decomposition of P (x)/Q(x). You will be asked to do so in theExercises. A technique we will cover in Section 7.3 may be helpful.

Note that, if all the roots of Q(x) are of multiplicity 1, then (7.16) simplifiesto

fn =

k∑i=1

pir−ni ,

where the pi are constants.

Example 7.35 A utitility crew is painting a row of n poles proceeding fromeast to west. In their first shift, they paint each pole red or blue or black. Intheir second shift, they paint each pole gray or orange. In their third and lastshift, they paint each pole yellow or green or pink. Let hn be the number ofways in which the crew can proceed. Find the growth rate of hn at polynomialprecision.

Solution: Let H(x) =∑n≥0 hnx

n. It follows from the product formula (The-orem 3.14) of ordinary generating functions that

H(x) =1

1− 3x· 1

1− 2x· 1

1− 3x.

Therefore, H(x) is a rational function and the roots of its denominator arer1 = 1/3 with multiplicity 2, and r2 = 1/2 with multiplicity 1. So Theorem7.34 shows that

hn = p1(n)3n + p2(n)2n,

where p1(n) is a polynomial of degree 1, and p2 is a constant. Therefore,there exists a constant C so that hn ∼ Cn3n. ♦ We point out that in the

previous example, there were no lower bounds on the number of poles thatthe crew had to paint each day. However, if there were such bounds, thatwould not have changed the asymptotics of hn, as only the numerator, andnot the denominator, of H(x) would have changed.

Example 7.36 Let sn be the number of ways to schedule the next n days ofthe US congress with the following constraints.

1.The schedule must contain exactly three sessions of at least oneday each, and

Page 57: Combinatorics - Routledge

396 Introduction to Enumerative and Analytic Combinatorics

2.there has to be a break of at least one day between any two sessions,and

3.when Congress is in session, each day must be devoted either to aplenary meeting or to committee work.

Find the growth rate of the sequence sn at polynomial precision.

Solution: Just as in the preceding example, we use the product formula(Theorem 3.14). The schedule will start with a break of any (possibly 0)length, and there is only one way to schedule a break of length k, leading tothe generating function A(x) = 1/(1 − x). After this, there will be a sessionof length at least one, leading to the generating function B(x) = 2x/(1− 2x),since there are 2k ways to schedule a session of k days. Following this session,there will be a break of length at least 1, leading to the generating functionC(x) = x/(1−x). Continuing in this way, and noting that, after the third andlast session, there will be a break of any (possibly zero) length, the productformula yields

S(x) =∑n≥0

snxn =

1

1− x· 2x

1− 2x· x

1− x· 2x

1− 2x· x

1− x· 2x

1− 2x· 1

1− x.

Therefore,

S(x) =8x5

(1− x)4(1− 2x)3.

So r1 = 1/2 is a root of multiplicity 3, and r2 = 1 is a root of multiplicity4. Hence, by Theorem 1, sn = p1(n)2n + p2(n), where p1 is a polynomial ofdegree 2, and p2 is a polynomial of degree 3. This implies that there exists aconstant C so that sn ∼ Cn22n. ♦

7.3 More precise asymptotics

7.3.1 Entire functions divided by (1− x)

Some power series have a sequence of coefficients that is convergent as a se-quence, and we can compute the limit of that sequence without computingthe coefficients themselves.

Recall that we call a permutation a derangement if it does not contain any1-cycles. Similarly, let us call a permutation a 2-derangement if it does notcontain any 1-cycles or 2-cycles. Let D2,n be the number of 2-derangementsof length n. What can we say about the ratio D2,n/n!? In other words, whatis the probability that a randomly selected permutation of length n is a 2-derangement?

Page 58: Combinatorics - Routledge

Analytic combinatorics 397

Let D2(x) =∑n≥0D2,n

xn

n! be the exponential generating function of thenumbers D2,n, where we set D2,0 = 1. We can obtain D(x) using the expo-nential formula. Indeed, to get a permutation counted by D2,n, we need topartition [n] into blocks of size at least two, then put a k-cycle on each blockof size k. There are (k − 1)! ways to do that if k ≥ 3, and 0 ways otherwise.This leads to the generating function

A(x) =∑k≥3

(k − 1)!xk

k!=∑k≥3

xk

k

= ln

(1

1− x

)− x− x2

2.

Therefore, by the exponential formula,

D(x) = eA(x) =e−x−

x2

2

1− x. (7.24)

So, we have an explicit formula for D(x), but how do we use it? Writing upan explicit formula for the numbers D2,n is too complicated, since the numer-ator of D(x) involves two summation signs, and the division by 1 − x wouldmean further summation. It is clear that D(x) has only one singularity, atx = 1, but all that means is that the coefficients of D(x), that is, the numbersD2,n/n!, have exponential growth rate 1. That is not too surprising, since allsequences that converge to a positive constant have exponential growth rate1. In order to achieve our goal, that is, to find limn→∞

D2,n

n! , we need to learna new technique. The following theorem is our main tool toward that goal.

Theorem 7.37 Let f be an entire function, and let

f(x)

1− x=∑n≥0

anxn.

Then an ∼ f(1). In other words, limn→∞ an = f(1).

Proof: Note that

f(x)

1− x=f(x)− f(1)

1− x+

f(1)

1− x=f(x)− f(1)

1− x+ f(1)

∑n≥0

xn. (7.25)

Observe that the function F (x) = f(x)−f(1)1−x is an entire function. Indeed,

as f(x) is an entire function, it converges everywhere, so we have f(x) =

Page 59: Combinatorics - Routledge

398 Introduction to Enumerative and Analytic Combinatorics∑n≥0 fnx

n, and, in particular, f(1) =∑n fn. Therefore,

F (x) =f(x)− f(1)

1− x

=

∑n≥0 fn(xn − 1)

1− x= −

∑n≥0

fn(1 + x+ · · ·+ xn−1

)

=∑n≥0

− ∑k≥n+1

fk

xn.

In the last form of F (x), all coefficients are convergent sums, since even thesum

∑k≥0 fk = f(1) is finite. For that same reason, the sequence of partial

(tail) sums∑k≥n+1 fk converges to 0 as n goes to infinity.

In order to prove our claim, let us now compare the coefficient of xn inthe far left and far right terms of (7.25). In the far left, it is, by definition, an.The far right expression is a sum, the second summand of which has coefficientf(1) for each power of x, and the first summand of which has a sequence ofcoefficients that (as we just proved) converges to 0. ♦

Corollary 7.38 As n goes to infinity, the probability that a randomly se-lected permutation of length n is a 2-derangement converges to e−3/2 ∼0.22313.

Proof: Just use Theorem 7.37 with f(x) = e−x−x2/2. ♦

It is also straightforward to recover the result that we proved in Chapter4, namely, that, for large n, roughly 1/e of all permutations of length n arederangements. Indeed, if Dn denotes the number of derangments of length n,then we have seen in (4.11) that

∑n≥0

Dnxn

n!=

e−x

1− x.

So using Theorem 7.37 with f(x) = e−x, we get that Dn

n! ≈ e−1.

Example 7.39 Let hn be the number of ways to partition [n] into two blocksA and B so that B can be empty, but A cannot, and then to take a partitionof A and a permutation of the elements of B. Find limn→∞

hn

n! .

Solution: It follows from a routine application of the exponential formulathat the exponential generating function for the number of partitions of [n]

Page 60: Combinatorics - Routledge

Analytic combinatorics 399

is G(x) = eex−1. (Indeed, we do not put any structure on the blocks, except

that the blocks are required to be nonempty.) We can now use the productsformula of exponential generating functions with A(x) = ee

x−1 − 1 since Acannot be empty, and B(x) =

∑n≥0 n!x

n

n! = 1/(1− x).This leads to

H(x) = A(x)B(x) =ee

x−1 − 1

1− x.

As the numerator A(x) of H(x) is clearly an entire function, Theorem 7.37applies and so limn→∞ hn/n! = A(1) = ee−1 − 1 ≈ 4.5749. ♦

7.3.2 Rational functions one more time

If h(x) =∑n≥0 hnx

n is a rational function, then we can, in theory, computeits partial fraction decomposition and obtain an exact formula for the numbershn. Sometimes this is too cumbersome, and a rather precise estimate can beobtained without computing that exact formula.

Recall that, in Section 7.2.1, we studied the power series

H(x) =∑h≥0

hnxn =

1

(1− x)(1− x2)(1− x5),

and proved that there exists a constant C so that

hn ∼ C · n2, (7.26)

since all singularities of H(x) are of modulus 1, and the singularity x = 1 hasmultiplicity three.

Now we will discuss a simple method to compute the constant C in (7.26).Our tool is the following theorem, which is an enhanced version of Theorem7.34.

Theorem 7.40 Let

f(x) =∑n≥0

fnxn =

P (x)

Q(x)

be a rational function so that P (x) and Q(x) do not have roots in common,and Q(0) 6= 0. Let us assume that Q(x) has a root r1 of smallest modulus thatis of higher multiplicity a1 than any other roots of Q(x) that are of highestmodulus.

Then we have

fn ∼K

(a1 − 1)!· na1−1|r1|−n (7.27)

whereK = lim

x→r1(1− z1x)a1f(x),

with z1 = 1/r1.

Page 61: Combinatorics - Routledge

400 Introduction to Enumerative and Analytic Combinatorics

Proof: The proof is somewhat similar to that of Theorem 7.37. The keyobservation is that the difference between the functions f(x) and K

(1−z1x)a1is

relatively small in a neighborhood of r1.In order to see this, let us introduce the notation f(x) = g(x)/(1− z1x)a1 .

In other words, g(x) is all of f(x) except those factors involving z1. Considerthe rational function

T (x) = f(x)− K

(1− z1x)a1=

g(x)−K(1− z1x)a1

.

Crucially, T (r1) = 0, since, by definition, K = limr1 g(x), and g(x) is contin-uous at r1. Therefore, the polynomial in the numerator of T (x) is divisible by1−z1x, and so we can simplify T (x) by at least one factor (1−z1x). However,that implies, by Theorem 7.34, that the coefficients of T (x) grow at least alinear factor slower than the coefficients of f(x). Therefore, the coefficients off(x) and that of f(x)−T (x) = K

(1−z1x)a1are asymptotically equal. In symbols,

fn ∼ [xn]K

(1− z1x)a1

∼(n+ a1 − 1

a1 − 1

)r−ni ,

proving our claim. The reader may revisit (7.20) for more details on the lastcomputation. ♦

Example 7.41 Continuing with our example from Section 7.2.1, let f(x) =1

(1−x)(1−x2)(1−x5) . As we have discussed, we have r1 = 1 and a1 = 3. This

yields

K = limx→1

(1− x)3f(x) =1

(1 + x)(1 + x+ x2 + x3 + x4)=

1

10.

Since a1 = 3, Theorem 7.40 implies that

fn ∼n2

20.

7.4 Notes

Our goal in this chapter was to introduce the reader to some techniques in an-alytic combinatorics, even though we assumed that the reader has not taken acourse in complex analysis. Therefore, we did not cover any topics that needed

Page 62: Combinatorics - Routledge

Analytic combinatorics 401

complex integration. In particular, that meant that we could not use famoustheorems such as the residue theorem or Cauchy’s coefficient formula. For thatreason, one important problem that we did not address in this chapter was tofind the growth rate of the coefficients of entire functions, that is, functions

that have no singularities, such as ex, or ex+x2

2 , the exponential generatingfunction of involutions of length n, or ee

x−1, the exponential generating func-tion of partitions of [n]. It goes without saying that a completely new methodis needed for such functions, since there are no singularities to analyze.

If the reader wants to learn the relevant material in complex analysis, thereader should consult a textbook on that topic, such as Complex Analysis bySerge Lang [50], or Complex Variables and Applications by Ruel V. Churchilland James Ward Brown [23].

Once the reader is familiar with the mentioned important theorems incomplex analysis, Section 5.4 of the classic book generatingfunctionology [83](where both the single word of the title and its lowercase first letter werecoined by the author Herb Wilf) provides a quick introduction into a techiquethat enables us to compute the growth rate of the coefficients of some en-tire functions. As its name shows, the book Analytic Combinatorics [30] byPhilippe Flajolet and Robert Sedgewick is a high-level, comprehensive treat-ment of the area. Among the many useful skills one can acquire by readingthat book, we just mention one. In this chapter, we have seen how to find esti-mates of polynomial precision for the growth rate of the coefficient sequence ofcertain power series whose singularities were of the rational type, that is, theywere caused by the presence of a nonconstant polynomial in the denominator.In [30], one can learn how to obtain similar results for power series whose sin-gularities are of the square root type, like

√1− 2x− 3x2 or 1/

√1− 6x+ x2,

and also for power series whose singularities are of the logarithmic type, suchas ln(1− x) or 1/ ln(1− 2x).

7.5 Chapter review

1. The exponential growth rate of the sequence a0, a1, · · · is equal tolim sup n

√|an|.

2. The exponential growth rate of the sequence of coefficients fn of apower series F (x) =

∑n≥0 fnx

n is equal to 1/M , where M is theminimal distance between 0 and any singularity of F .

3. If F (x) is a rational function, we can get more precise estimatesof the growth rate of the sequence fn from the multiplicities of thesingularities of F that are of smallest modulus.

Page 63: Combinatorics - Routledge

402 Introduction to Enumerative and Analytic Combinatorics

7.6 Exercises

1. Let P (x), Q(x), A(x), and R(x) be polynomials so that P (x) =Q(x)A(x) +R(x), where the degree of R(x) is less than the degreeof Q(x). In other words, R(x) is the remainder of P (x) when dividedby Q(x).

Show that the coefficients of the rational functions P (x)/Q(x) andR(x)/Q(x) have the same exponential growth rate.

2. Use an argument from analysis (no software packages) to show thatthe root r0 of smallest modulus of 1 − xk − x`, where k and ` arerelatively prime positive integers, is a positive real number.

3. Use an argument from analysis (no software packages) to show thatthe root r0 of smallest modulus of the polynomial Qa(x) = 1−x−x4is smaller than that of the polynomial Qb(x) = 1− x2 − x3.

4. Let hn be the number of surjections from [n] to [k] where k variesfrom 1 to n. Set h0 = 1. Find an explicit formula for H(x) =∑n≥0 hn

xn

n! , then find the exponential growth rate of the coefficientshn/n! of H(x).

5. Explain what the result of the previous exercise means by compar-ing the numbers of surjections defined on [n] and the number ofbijections on [n].

6. Decreasing nonplane 1-2 trees were defined in Section 5.5.2.2. Foreasy reference, such a tree on vertex set [n] is a tree in which eachvertex has at most two children, and each child has a label that isless than the label of its parent. The trees are not plane trees, sothere is no left child or right child. Let Tn be the number of suchtrees. Note that T0 = T1 = T2 = 1, while T3 = 2 and T4 = 5.See Figure 7.2 for an illustration. Let T (x) =

∑n≥0 Tn

xn

n! be theexponential generating function of the sequence of the numbers Tn.Find the exponential growth rate of the sequence Tn/n!.

7. Recall that the Stirling number of the second kind, S(n, k), de-notes the number of partitions of [n] into k blocks. Let Fk(x) =∑n≥k S(n, k)xk. In other words, Fk(x) is the generating function

of the Stirling numbers S(n, k) with k fixed.

(a) Prove that, if k ≥ 2, then

Fk(x) =x

1− kxFk−1(x).

(b) Compute the exponential growth rate of the sequence{S(n, k)}n≥k.

Page 64: Combinatorics - Routledge

Analytic combinatorics 403

Figure 7.2The five rooted 1-2 trees on vertex set [4].

Figure 7.3The four plane 1-2 trees on four unlabeled vertices.

8. Let tn be the number of rooted plane trees on n unlabeled verticesin which each vertex has at most two children, and let t0 = 0. SeeFigure 7.3 for an illustration. Find the exponential growth rate ofthe sequence of the numbers tn.

9. Let Tn be the number of binary plane trees on n unlabeled vertices.In such trees, each vertex has at most two children, and a child ofa vertex can be a left child or a right child, even if it is an onlychild. Figure 7.4 shows the five binary plane trees on three vertices.Set T0 = 1. Find the exponential growth rate of the sequence of thenumbers Tn. Where have you seen these numbers?

10. Let bn be the number of rooted plane trees on n unlabeled verticesin which any non-leaf vertex can have any number of children. Thesetrees were formally defined in Definition 5.26. Set b0 = 0. Find theexponential growth rate of the sequence of the numbers bn.

Page 65: Combinatorics - Routledge

404 Introduction to Enumerative and Analytic Combinatorics

Figure 7.4The five binary plane trees on three vertices.

11. Let mn be the number of ways to have a group of n people split intononempty subsets, to have each subset sit down around a circulartable, then to arrange the tables in a circle. Find the exponentialgrowth rate of the sequence mn/n!. Two arrangements are consid-ered identical if each person has the same left neighbor in them,and each table has the same left neighbor in them.

12. Let tn be the number of undirected graphs on vertex set [n] in whicheach connected component is a cycle of length at least three. Findthe exponential generating function for the numbers tn, then findthe exponential growth rate of the sequence tn/n!.

13. Let pn be the number of undirected graphs on vertex set [n] inwhich each connected component is a path. Find the exponentialgrowth rate of the sequence pn/n!. (Components that consist of asingle vertex are allowed.)

14. A baseball coach asks his n players to split into a few subsets thatconsist of at least one person each, then he asks that the set ofgroups stand around a cycle. (There is no structure imposed oneach set of players.) Let cn be the number of ways in which thiscan happen. Find the exponential order of the sequence cn/n!. Twoarrangements are considered the same if the partition of the playersis the same in both, and each set of players has the same set as itsleft neighbor in both.

15. A football coach partitions the set of his n players into blocks ofplayers so that each block consists of an odd number of players.Then he asks each block to form a line. Let Ln be the number ofways in which this can happen. Find the exponential growth rateof the sequence Ln/n!. (There is no structure imposed on the set ofblocks.)

16. Let us modify the situation described in the previous exercise byimposing a linear order on the blocks of players (so that there isnow a first block, a second block, and so on). In other words, wearrange the set of blocks in a line. Let wn be the number of waysthat the combined task can be carried out. Find the exponentialgrowth rate of the sequence wn/n!.

17. A group of football players stand in a line. The coach walks by the

Page 66: Combinatorics - Routledge

Analytic combinatorics 405

line and splits the line into a few segments. (The coach has theoption to leave the entire line as one segment.) Then she asks eachsegment to choose three captains. Let bn be the number of waysin which this can happen. Find the exponential growth rate of thesequence of the numbers bn.

18. Let f(n) be the number of words of n letters over the alphabet{A,B} that do not contain a subword ABA in consecutive positions.Find the exponential growth rate of the sequence f(n).

19. Consider the undirected cycle Cn on vertex set [n], and let us calla subset S of its vertices a maximal independent set if there is noedge between any two vertices in S, but adding any new vertex to Swould destroy that property. For n ≥ 3, let Pn denote the numberof maximal independent sets of Cn. Find the exponential growthrate of the sequence Pn.

20. Let An be the number of all independent sets of any size in the pathon vertex set [n]. Find the exponential growth rate of the sequenceAn. An independent set is a set of vertices so that there are no edgesbetween vertices of the set.

21. Let n ≥ 3, and let Bn be the number of all independent sets of anysize in the circle Cn on vertex set n. Find the exponential growthrate of the numbers Bn.

22. Generalizing Example 7.12, let an,k be the number of outcome se-quences of n coin flips that do not contain k consecutive heads. Findthe closed form of the exponential generating function Ak(x) =∑n≥0 an,kx

n, and explain how its singularity of smallest moduluswill change if k changes.

23. A decreasing plane 1-2 tree on vertex set [n] is a plane tree whosevertices are bijectively labeled by the elements of [n] so that eachvertex has a smaller label than its parent. Note that the only differ-ence between these trees and the decreasing binary trees that wereintroduced in Definition 5.31 is that, in decreasing plane 1-2 trees,if a child is the only child of its parent, then it does not have a“direction,” that is, it is not a left child or a right child. Set h0 = 0,and let hn be the number of decreasing plane 1-2 trees for n ≥ 1.Find the exponential growth rate of the sequence hn/n!. You mayuse a software package to solve any differential equations that youneed for your solution.

Page 67: Combinatorics - Routledge

406 Introduction to Enumerative and Analytic Combinatorics

7.7 Solutions to exercises

1. This is becauseP (x)

Q(x)= A(x) +

R(x)

Q(x),

so those two rational functions only differ in a polynomial, that is,their coefficients of xn only differ for a finite number of exponentsn.

2. Let us assume that z is not a positive real number, and zk+z` = 1.Then, by the triangle inequality, we have |z|k + |z|` > 1. Considerthe increasing function f(t) = tk + tell defined on the positive reals.As f(|z|) > 1, and f(0) = 0, it follows from the continuity of f thatthere exists a t ∈ (0, |z|) for which f(t) = 1.

The triangle inequality is strict, unless zk and z` are vectors thatpoint into the same direction, that is, unless zk−` is a positive realnumber. However, as 1 = zk + z` = (1 + zk−`)z`, that would implythat z` is also a positive real number. That means that both ` andk − ` are multiples of 2π/Arg(z), a contradiction.

3. It suffices to prove that, for all positive real numbers x, the in-equality x4 + x > x3 + x2 holds. That inequality holds since it isequivalent to

x4 + x− x3 − x2 > 0

(x+ 1)x(x− 1)2 > 0,

which obviously holds for all positive real numbers x. Now we knowfrom the previous exercise that the root of smallest modulus of bothQa(x) and Qb(x) is a positive real number. Let r0 be that root ofQa(x), and let r1 be that root of Qb(x). Then r0 + r40 = 1, and itfollows from the inequality that we just proved that r21 + r31 < 1.As f(x) = x2 + x3 is obviously an increasing function for positivex, the statement is proved.

4. We use the compositional formula of exponential generating func-tions, with A = ex − 1 and B(x) = 1/(1 − x). Indeed, we split [n]into k blocks, and then there is no task to carry out on these blocksother than making sure that they are nonempty. Then, we orderthe set of these blocks linearly, and we map the elements of the firstblock into 1, the elements of the second block into 2, and so on.There are k! ways to linearly order k blocks, showing that bk = k!,

and so B(x) =∑k≥0 k! · x

k

k! = 1/(1− x).

Therefore, the compositional formula yields

H(x) = B(A(x)) =1

1−A(x)=

1

1− (ex − 1)=

1

2− ex.

Page 68: Combinatorics - Routledge

Analytic combinatorics 407

The function ex is an entire function; therefore, the only way inwhich H(x) can have a singularity is by ex = 2, There are infinitelymany complex numbers x that satisfy ex = 2, but the one with thesmallest modulus is the real number ln 2. Therefore, the exponentialorder of the numbers hn is 1/ ln 2 ≈ 1.4427. Note that the numbershn are called the surjection numbers.

5. As the number of bijections on [n] is n!, the ratio hn/n! is the ratioof all surjections defined on [n] (and mapping to any [k]) and thebijections on [n]. The result of the previous exercise says that, forlarge n, there will be about 1.4427n times as many surjections asbijections.

6. We have seen in Section 5.5.2.2 that T (x) =∑n≥0 Tn

xn

n! = secx+tanx. As both secx and tanx have their singularities of smallestmodulus at distance π/2 from 0, it follows that the exponentialgrowth rate of the sequence Tn/n! is 2/π.

7. (a) Consider the recurrence relation proved in Theorem 2.10. Mul-tiply both sides by xn, then sum over all n ≥ k to getFk(x) = xFk−1(x) + kxFk(x), which is equivalent to our claim.

(b) Note that F1(x) = x/(1 − x). Then the recurrence we provedin part (a) and induction on k leads to the explicit formula

Fk(x) =xk

(1− x)(1− 2x) · · · (1− kx).

So the singularity of smallest modulus of Fk(x) is at x0 = 1/k,proving that the exponential growth rate of the sequence of itscoefficients is k.

8. Let t(x) be the generating function of the sequence. Removing theroot of such a tree, we get either the empty set, or one such tree,or the ordered pair of two such trees. This leads to the functionalequation

t(x) = x+ xt(x) + xt(x)2.

This is a quadratic equation for t(x), whose solutions are

t1,2(x) =1− x±

√(x− 1)2 − 4x2

2x.

We know that t(0) = 0, so we need the solution that satisfies thatrequirement, that is, the one with the negative sign before the squareroot.

This yields

t(x) =1− x−

√1− 2x− 3x2

2x.

So the singularity of t(x) that is of smallest modulus is at 1/3,

Page 69: Combinatorics - Routledge

408 Introduction to Enumerative and Analytic Combinatorics

hence the exponential growth rate of the sequence tn is 3. It mayseem at first that x = 0 is a singularity of t. However, we havedefined t(0) = 0, and that definition keeps t analytic at 0. That isthe only definition of t(0) that achieves that, since limx→0 t(x) = 0.Note that the numbers tn = Mn−1, where the numbers Mn arethe Motzkin numbers that we saw in the solution of Exercise 23 ofChapter 3. .

A word on terminology: We say that x = 0 is a removable singularity

of the function s(x) = 1−x−√1−2x−3x2

2x since s becomes analytic at0 if we define its value at 0 properly. For general s, this is possible ifand only if s is analytic in a neighborhood of 0 except at 0 itself, andlimx→0 s(x) = L exists and is finite. In that case, setting s(0) = Lwill make s analytic at 0. For instance, s(x) = − ln(1 − x)/x hasa removable singularity at 0, since limx→0 s(x) = 1. So we can sets(0) = 1.

9. Removing the root of such a tree (which we can do if the tree is notempty), we get an ordered pair of such trees, some or both of whichmay be empty. This leads to the functional equation

T (x)− 1 = xT (x)2.

Solving this quadratic equation for T (x), we get

T (x) =1±√

1− 4x

2x.

We know that T (0) = 1, so we need the solution that satisfiesthat requirement, that is, the one with the negative sign before the

square root. Therefore, T (x) = 1−√1−4x2x , and the singularity of the

smallest modulus of T (x) is 1/4, hence the exponential growth rateof the sequence Tn is 4. Note that x = 0 is not a singularity, sincewe have defined T (0) = 1, which equals limx→0 T (x). Just as inthe previous exercise, the reader should explain why x = 0 is not asingular point of T . In other words, 0 is a removable singularity of1−√1−4x2x (and not a singularity of T (x)).

It follows from the closed form of the generating function T (x) thatthe numbers Tn are the Catalan numbers.

10. We proved in Section 5.5.2.1 that

B(x) =1−√

1− 4x

2,

so B(x) has only one singularity, at x = 1/4. Therefore, the ex-ponential order of the sequence bn is 4. Note that bn = cn−1, the(n− 1)st Catalan number.

Page 70: Combinatorics - Routledge

Analytic combinatorics 409

11. We use the compositional formula of exponential generating func-tions. The inside function is ln(1/(1− x)) and the outside functionis 1 + ln(1/(1− x)). Therefore, we get

M(x) = 1 + ln(1− ln(1/(1− x)).

Clearly, M(x) has a singularity at x = 1, and also when 1 = ln(1−ln(1/(1 − x)), which occurs if 1 = ln(1/(1 − x)), that is, when1/(1 − x) = e, or x = 1 − e−1. This second singularity is closer to0 than the first, so the exponential growth rate of the sequence ofthe mn is 1/(1− e−1) = 1 + 1

e−1 ≈ 1.582.

12. We will use the exponential formula. There are (k−1)! ways to puta directed cycle on k vertices, so there are (k− 1)!/2 ways to put anundirected cycle on them, for k ≥ 3. Therefore,

A(x) =∑k≥3

(k − 1)!

2· x

k

k!

=∑k≥3

xk

2k

=1

2ln

(1

1− x

)− x

2− x2

4.

Therefore, the exponential formula implies that

T (x) =∑n≥0

tnxn

n!= exp(A(x)) =

e−x2−

x2

4

√1− x

.

So T (x) has only one singularity, at x = 1, and therefore the expo-nential growth rate of the sequence tn/n! is 1.

13. This is similar to the previous exercise. For n ≥ 2, there are n!/2ways to put an undirected path on n vertices, whereas there is oneway to put a path on one vertex. This yields

A(x) = x+1

2

∑n≥2

n!

2

xn

n!= x+

1

2

1

1− x− x

2− 1

2=

1

2(1− x)+x− 1

2.

As A(x) has only one singular point, at x = 1, so does P (x) =∑n≥0 pnx

n = exp(A(x)), so the sequence of the numbers pn/n! hasexponential growth rate 1.

14. We apply the compositional formula of exponential generating func-tions. The inside function is A(x) =

∑n≥1

xn

n! = ex − 1, since thereis no structure on each set of players. As the sets of players are ar-ranged in a cycle, the outside function is B(x) = 1 +

∑n≥1 x

n/n =

Page 71: Combinatorics - Routledge

410 Introduction to Enumerative and Analytic Combinatorics

1 + ln(1/(1− x)). Therefore, the compositional formula implies

H(x) =∑n≥0

hnxn

n!= B(A(x)) = 1 + ln

(1

1− (ex − 1)

)

= 1 + ln

(1

2− ex

).

So the singularity of smallest modulus is at r1 = ln 2; therefore, theexponential gowth rate of the coefficients hn/n! is 1/ ln 2 ≈ 1.4427.

15. As there is no structure imposed on the set of blocks, we use the

exponential formula. We have A(x) =∑n≥0

x2n+1

(2n+1)! (2n + 1)! =

x/(1− x2). Therefore, the exponential formula implies

L(x) =∑n≥0

Lnxn

n!= exp(A(x)) = exp

(x

1− x2

),

so L(x) has two singularities, both of modulus 1. Hence the expo-nential gowth rate of the coefficients Ln/n! is 1.

16. Now we have to use the compositional formula for exponential gen-erating functions, with A(x) being the same as in the previous ex-ercise, but B(x) =

∑n≥0 n!x

n

n! = 1/(1− x). We obtain

W (x) =∑n≥0

wnxn

n!=

1

1− x1−x2

=1− x2

1− x− x2.

The singularity of smallest modulus is r0 = (√

5 − 1)/2, so weobtain the exponential growth rate of the sequence wn/n! as 1/r0 =(√

5 + 1)/2 ≈ 1.618.

17. As the players are standing in a line, we need to use ordinary gen-erating functions, namely, Theorem 3.25. The inside function is

A(x) =∑k≥3

(k

3

)xk

= x3∑k≥3

(k

3

)xk−3

=x3

6·(

1

1− x

)′′′=

x3

(1− x)4.

Hence Theorem 3.25 yields

B(x) =∑n≥0

bnxn =

1

1−A(x)=

(1− x)4

1− 4x+ 6x2 − 5x3 + x4.

Page 72: Combinatorics - Routledge

Analytic combinatorics 411

So B(x) is a rational function. Its singularity of smallest modulusis at r1 = 0.4503, so the exponential growth rate of the coefficientsbn is 1/r1 ≈ 2.2207.

18. We will make repeated use of Theorem 3.25. Let f(0) = 1, andlet F (x) =

∑n≥0 f(n)xn. If an allowed word starts with a letter

B, then that letter B can be followed by any allowed word. Suchwords are counted by the generating function xF (x). Otherwise, letus look for the first letter B in our word w. This letter B is immedi-ately preceded by a string of letters A, so it cannot be immediatelyfollowed by a letter A. Therefore, after the first letter B, the wordw either ends or continues with another letter B, and then withany allowed word. In the first case, w is counted by the generatingfunction

∑n≥2 x

n = x2/(1−x) since w is just a nonempty sequenceof letters A, and then a single B. In the second case, w is counted by

the generating function x2

1−x · x · F (x). Finally, w can be the emptyword, which has generating function 1, or the word that consists ofletters A only, which has generating function x/(1− x).

This leads to the functional equation

F (x) = xF (x) +x2

1− x+

x2

1− x· x · F (x) + 1 +

x

1− x.

Solving this equation, we get

F (x) =1 + x2

1− 2x+ x2 − x3.

The singularity of F (x) that has smallest modulus is r1 ≈ 0.5698,so the exponential growth rate of the sequence f(n) is 1/r1 ≈ 1.755.

19. We claim that P (n) = P (n− 3) +P (n− 2) if n ≥ 6, with P (3) = 3,P (4) = 2, and P (5) = 5. In order to prove this claim, let n ≥ 6. Leti be the smallest vertex in S, and let j be the second smallest vertexin S. Then either j − i = 2 or j − i = 3. In either case, contractthe entire path i, i+ 1, · · · j into one vertex, call that vertex i, anddecrease the label of all vertices larger than j by j − i. Form a newset S′ from the new vertex i and the images of the other vertices thatwere in S. Then S′ is a maximal independent set in the obtainedCn−2 or Cn−3. Furthermore, this construction is bijective, since,starting with a maximal independent set T of a Cn−2 or Cn−3, wecan find its preimage by finding the smallest i vertex in T , and thenreplacing it by a path of three or four vertices, the two endpointsof which are in the preimage of T .

In order to find the generating function P (x) =∑n≥0 P (n)xn, we

may set P (2) = 2, P (1) = 0, and P (0) = 3 to keep the recurrence

Page 73: Combinatorics - Routledge

412 Introduction to Enumerative and Analytic Combinatorics

true for all values of n ≥ 3. Set P (x) =∑n≥0 P (n)xn. Then the

recurrence leads to the functional equation

P (x)− 2x2 − 3 = x3P (x) + x2(P (x)− 3),

P (x) =−x2 + 3

1− x2 − x3.

Finding the singularity of smallest modulus of this rational function,we conclude that the exponential growth rate of the numbers P (n)is 1.3247. The numbers P (n) are called the Perrin numbers.

20. Let A(x) =∑n≥0Anx

n. Clearly, we have A0 = 1, A1 = 2, (notethat the empty set is independent as well), and An = An−1 +An−2for n ≥ 2, since there are An−1 such sets not containing n, andAn−2 such sets containing n. This leads to the functional equation

A(x)− 2x− 1 = x(A(x)− 1) + x2A(x),

A(x) =x+ 1

1− x− x2,

hence the exponential growth rate of the sequence An is (√

5+1)/2.Note that the number An is the (n+ 1)st Fibonacci number.

21. Independent sets S of the path on vertex set [n] will be independentsets in Cn if and only if they do not contain both 1 and n. If S doescontain both 1 and n, then the rest of S is an independent set inthe path from vertex 3 to vertex n− 2, so in a labeled path of n− 4vertices, if n ≥ 5. So for n ≥ 5, we have Bn = An − An−4. SettingB0 = B1 = B2 = 0, and noting that B3 = 4 and B4 = 7, we have(with B(x) =

∑n≥0Bnx

n),

B(x) = A(x)(1− x4

)− 1− 2x− 3x2 − x3,

so B(x) has the same set of singularities as A(x), hence the sequenceBn has the same exponential growth rate as the sequence An, andwe have computed that one in the solution of the previous exercise.

Note that the numbers Bn are called the Lucas numbers and theysatisfy the recurrence relation Bn + Bn+1 = Bn+2 for n ≥ 3, withthe initial conditions mentioned above.

22. Analogously to the solution of Example 7.12, we get the functionalequation

Ak(x) = Ak(x)x(1 + x+ · · ·+ xk−1

)+(1 + x+ · · ·+ xk−1

).

This yields the closed formula

Ak(x) =

(1 + x+ · · ·+ xk−1

)1− x− x2 − · · · − xk

.

Page 74: Combinatorics - Routledge

Analytic combinatorics 413

That is, the singularity of smallest modulus of Ak(x) is the root offk(x) = x + · · · + xk−1 − 1 that is closest to 0. It is easy to prove,and you are asked to do so in Supplementary Exercise 4 in moregeneral circumstances, that fk(x) has a unique such root, and thatroot is a positive real number rk. It follows that rk+1 < rk, sincefk+1 has an additional summand over fk, namely, xk. Therefore,the exponential growth rate of the sequence an,k+1 is larger thanthat of the sequence an,k. This is what we expected, since it is easierto avoid a sequence of k+ 1 consecutive heads than it is to avoid kconsecutive heads.

23. The procedure is quite similar to the one that we applied in Section5.5.2.2 to find the number of nonplane decreasing 1-2 trees on vertexset [n]. Let H(x) =

∑n≥0 hnx

n/n!. If n ≥ 2, then removing theroot of a plane decreasing 1-2 tree in vertex set [n], we either getan ordered sequence of two trees with combined vertex set [n − 1],or just one tree with vertex set [n − 1]. If n = 1, then we get theempty set. This leads to the differential equation

H ′(x) = H(x) +H(x)2 + 1.

Using the initial condition H(0) = 0, we can solve this differentialequation with our favorite software package. After simplification,we get the answer

H(x) = −1

2+

√32

tan

(√3

18(9x+

√3π

).

Therefore, the singularities of smallest modulus of H(x) are at thepoints for which √

3

18(9x+

√3π) = ±pi/2.

If the right-hand side is π/2, we get x = 2·√3

9 π, whereas if the

right-hand side is −π/2, we get x = − 4·√3

9 π. So the former is thesingularity of smallest modulus and therefore, the sequence hn/n!has exponential growth rate

12·√3

9 π=

3√

3

2π≈ 0.827.

Note that this growth rate is about halfway between that of thecorresponding growth rate 2/π for decreasing nonplane 1-2 treesthat we computed in Exercise 6 and the corresponding growth rate 1for decreasing binary trees that follows from the exact enumerationformula we got for such trees in Proposition 5.32.

Page 75: Combinatorics - Routledge

414 Introduction to Enumerative and Analytic Combinatorics

7.8 Supplementary exercises

1. Prove that all rational functions are analytic in all points wherethey are defined.

2. Prove Proposition 7.6.

3. Let Q(x) be a polynomial with real coefficients so that Q(x) has aunique root r of smallest modulus. Prove that r is a real number.

4. Let P (x) =(∑n

i=1 aixi)−m be a polynomial such that all ai are

positive real numbers (1 ≤ i ≤ n), and m is also a positive realnumber. Prove that P (x) has a unique root of smallest modulus,and that root is a positive real number.

5. Let f be a power series with nonnegative real coefficients. Let usassume that there exists a complex number z of modulus r so thatthe sum f(z) is divergent. Prove that then f(r) is divergent.

6. Let F (x) =∑n≥0 fnx

n = p(x)(1−x)2 , where p(x) is a polynomial so

that p(1) 6= 0. Prove that limn→∞(fn/(n+ 1)) = p(1).

7. Will the claim of the previous exercise remain true if we drop thecondition that p(1) 6= 0?

8. Let fn be the number of compositions of the integer n that do notcontain parts equal to 2 or 3. Find the exponential growth rate ofthe sequence fn.

9. Let f(n) be the number of ways to pay n dollars using only 1-, 2-,5-, 10-, 20-, 50-, and 100-dollar bills. Find the asymptotics of thesequence f(n) with polynomial precision.

10. Let f(n) be defined as in the previous exercise. Find a positive realnumber α, a positive constant K, and a positive integer k so that

f(n) ∼ K · αn

nk.

11. Let A(x) =∑n≥0 anx

n be a power series so that, for all n ≥ 0, theequality

n∑k=0

akan−k = 5n

holds. Find the exponential growth rate of the sequence an.

12. Let cn be the number of surjections from [n] to [k] where k variesfrom 1 to bn/2c in which each element of [k] has a preimage ofsize at least two. Set c0 = 1. Find an explicit formula for C(x) =∑n≥0 cn

xn

n! , then find the exponential growth rate of the coefficientsof C(x).

Page 76: Combinatorics - Routledge

Analytic combinatorics 415

13. Let k ≥ 2 be a fixed positive integer, and let ck(n) be the numberof permutations of length n in which each cycle length is divisibleby k. Find the exponential growth rate of the sequence ck(n).

14. Let rn be the number of rooted nonplane trees on n unlabeled ver-tices in which each vertex has at most two children, and set r0 = 0.Find the exponential growth rate of the sequence rn.

15. Let Hn be the number of permutations of length n that do notcontain a 2-cycle. Find an explicit formula for H(x) =

∑n≥0Hn

xn

n! ,then find limn→∞Hn/n!.

16. Let Kn be the number of permutations of length n in which ev-ery cycle length is even. Find the exponential growth rate of thesequence Kn/n!.

17. Let k ≥ 2 be a fixed positive integer. Find the exponential growthrate for the numbers ak(n) of all compositions of n into parts thatare congruent to 1 modulo k.

18. A group of n tourists arrives at the starting point of a ride at anamusement park. Each car in the ride can seat either one or twopeople. Let f(n) be the number of ways in which tourists go on thisride if they are to go in a string of consecutive cars. (The order oftwo people in the same car is insignificant.) Find the exponentialorder of the numbers f(n)/n!.

19. A group of n tourists arrives at a restaurant. They sit down aroundcircular tables in groups of three or four people, after which the onlyserver at the restaurant will visit all tables in some order. Let g(n)be the number of ways all this can happen. Find the exponentialorder of the numbers g(n)/n!.

20. A group of n tourists arrives at a restaurant. They sit down aroundcircular tables in groups of size of at least one and at most three.The circular tables themselves are arranged in a circle. Let g(n) bethe number of ways in which this can happen. Find the exponentialorder of the numbers g(n)/n!.

21. Let B(n) denote the number of all partitions of the n-element set.Prove that, for any fixed real number k, the exponential growth rateof the numbers B(n) (the Bell numbers) is larger than k.

22. Recall from Section 2.3 that the number of partitions of the integern is denoted by p(n), and that∑

n≥0

p(n)xn =∏i≥1

1

1− xi

holds, where we set p(0) = 1.

(a) Use the methods learned in this chapter to determine the ex-ponential growth rate of the sequence {p(n)}n≥0.

Page 77: Combinatorics - Routledge

416 Introduction to Enumerative and Analytic Combinatorics

(b) Use the methods learned in this chapter to prove that p(n)grows faster than any polynomial P , that is, prove thatlimn→∞ P (n)/p(n) = 0.

23. Let k > 2 be a fixed positive integer, and let tn be the number ofrooted plane trees on n unlabeled vertices in which each vertex hasat most k children. Set t0 = 0. Find the exponential growth rate ofthe sequence of the numbers tn.

24. Let fn be the number of ways to partition the set [n] into twononempty intervals [1, i] and [i+ 1, n], then to partition the first in-terval into two nonempty blocks, and to partition the second intervalinto three nonempty blocks. Find the growth rate of the sequencefn at polynomial precision.

25. Let pn be the probability that a randomly selected permutation oflength n does not have a fixed point. Let fn be the probability thata randomly selected function from [n] to [n] has exactly one fixedpoint. Is it true that

limn→∞

pn = limn→∞

fn?

Page 78: Combinatorics - Routledge

COUNTING PROBLEMS IN GRAPH THEORY

#

This chapter is excerpted from

Combinatorics, Second Edition

by Nicholas Loehr.

© 2017 Taylor & Francis Group. All rights reserved.

3

Learn more

Page 79: Combinatorics - Routledge

3

Counting Problems in Graph Theory

Graph theory is a branch of discrete mathematics that studies networks composed of anumber of sites (vertices) linked together by connecting arcs (edges). This chapter studiessome enumeration problems that arise in graph theory. We begin by defining fundamentalgraph-theoretic concepts such as walks, paths, cycles, vertex degrees, connectivity, forests,and trees. This leads to a discussion of various counting problems involving different kindsof trees. Aided by ideas from matrix theory, we count walks in a graph, spanning trees ofa graph, and Eulerian tours. We also investigate the chromatic polynomial of a graph; thispolynomial counts the number of ways of coloring the vertices such that no two verticesjoined by an edge receive the same color.

3.1 Graphs and Digraphs

Intuitively, a graph is a mathematical model for a network consisting of a collection ofnodes and connections that link certain pairs of nodes. For example, the nodes could becities and the connections could be roads between cities. The nodes could be computers andthe connections could be network links between computers. The nodes could be species in anecosystem and the connections could be predator-prey relationships between species. Thenodes could be tasks and the connections could be dependencies among the tasks. Thereare many such applications that lead naturally to graph models. We now give the formalmathematical definitions underlying such models.

3.1. Definition: Graphs. A graph is an ordered triple G = (V,E, ǫ), where: V = V (G) isa finite, nonempty set called the vertex set of G; E = E(G) is a finite set called the edge setof G; and ǫ : E → P(V ) is a function called the endpoint function such that, for all e ∈ E,ǫ(e) is either a one-element subset of V or a two-element subset of V . If ǫ(e) = {v}, we callthe edge e a loop at vertex v. If ǫ(e) = {v, w}, we call v and w the endpoints of e and saythat e is an edge from v to w. We also say that v and w are adjacent in G, v and w arejoined by e, and e is incident to v and w.

We visualize a graphG = (V,E, ǫ) by drawing a collection of dots labeled by the elementsv ∈ V . For each edge e ∈ E with ǫ(e) = {v, w}, we draw a line or curved arc labeled ebetween the two dots labeled v and w. Similarly, if ǫ(e) = {v}, we draw a loop labeled ebased at the dot labeled v.

3.2. Example. The left drawing in Figure 3.1 represents the graph defined formally by theordered triple

G1 = ({1, 2, 3, 4, 5}, {a, b, c, d, e, f, g, h, i}, ǫ),where ǫ acts as follows:

ǫ(a) = {1, 4}, ǫ(b) = {4, 3}, ǫ(c) = {2, 3}, ǫ(d) = {1, 2}, ǫ(e) = {1, 2},ǫ(f) = {3}, ǫ(g) = {2, 5}, ǫ(h) = {4, 5}, ǫ(i) = {4, 5}.

103

Page 80: Combinatorics - Routledge

104 Combinatorics, Second Edition

i

1 G2 G3

1

2

3

4

5

a

b

c

d e

f

g

h i

2

3

4

5

1

6

0

12

3

4

56

7

a

bc

d

efg h

jk

l

m

G

FIGURE 3.1A graph, a simple graph, and a digraph.

Edge f is a loop at vertex 3; edges h and i both go between vertices 4 and 5; vertices 1 and4 are adjacent, but vertices 2 and 4 are not.

In many applications, there are no loop edges, and there is never more than one edgebetween the same two vertices. This means that the endpoint function ǫ is a one-to-onemap into the set of two-element subsets of V . So we can identify each edge e with its set ofendpoints ǫ(e). This leads to the following simplified model in which edges are not explicitlynamed and there is no explicit endpoint function.

3.3. Definition: Simple Graphs. A simple graph is a pair G = (V,E), where V is afinite nonempty set and E is a set of two-element subsets of V . We continue to use all theterminology introduced in Definition 3.1.

3.4. Example. The center drawing in Figure 3.1 depicts the simple graph G2 with vertexset V (G2) = {0, 1, 2, 3, 4, 5, 6} and edge set

E(G2) = {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {1, 6}, {2, 6}, {1, 4}}.

To model certain situations (such as predator-prey relationships, or one-way streets ina city), we need to introduce a direction on each edge. This leads to the notion of a digraph(directed graph).

3.5. Definition: Digraphs. A digraph is an ordered triple D = (V,E, ǫ), where V is afinite nonempty set of vertices, E is a finite set of edges, and ǫ : E → V ×V is the endpointfunction. If ǫ(e) is the ordered pair (v, w), we say that e is an edge from v to w.

In a digraph, an edge from v to w is not an edge from w to v when v 6= w, since(v, w) 6= (w, v). On the other hand, in a graph, an edge from v to w is also an edge from wto v, since {v, w} = {w, v}.

3.6. Example. The right drawing in Figure 3.1 displays a digraph G3. In this digraph,ǫ(j) = (4, 5), ǫ(a) = (1, 1), and so on. There are three edges from 2 to 3, but no edges from3 to 2. There are edges in both directions between vertices 1 and 5.

As before, we can eliminate specific reference to the endpoint function of a digraph ifthere are no multiple edges with the same starting vertex and ending vertex.

Page 81: Combinatorics - Routledge

Counting Problems in Graph Theory 105

3.7. Definition: Simple Digraphs. A simple digraph is an ordered pair D = (V,E),where V is a finite, nonempty set and E is a subset of V ×V . Each ordered pair (v, w) ∈ Erepresents an edge in D from v to w. Note that we do allow loops (v = w) in a simpledigraph.

When investigating structural properties of graphs, the names of the vertices and edgesare often irrelevant. The concept of graph isomorphism lets us identify graphs that are thesame except for the names used for the vertices and edges.

3.8. Definition: Graph Isomorphism. Given two graphs G = (V,E, ǫ) and H =(W,F, η), a graph isomorphism from G to H consists of two bijections f : V → W andg : E → F such that, for all e ∈ E, if ǫ(e) = {v, w} then η(g(e)) = {f(v), f(w)} (weallow v = w here). Digraph isomorphisms are defined similarly: ǫ(e) = (v, w) impliesη(g(e)) = (f(v), f(w)). We say G and H are isomorphic, written G ∼= H , iff there exists agraph isomorphism from G to H .

In the case of simple graphs G = (V,E) and H = (W,F ), a graph isomorphism can beviewed as a bijection f : V → W that induces a bijection between the edge sets E and F .More specifically, this means that for all v, w ∈ V , {v, w} ∈ E iff {f(v), f(w)} ∈ F .3.9. Example. Let G = (V,E) = ({1, 2, 3, 4}, {{1, 2}, {1, 3}, {1, 4}}) and H = (W,F ) =({a, b, c, d}, {{a, c}, {b, c}, {c, d}}). The map f : V → W such that f(1) = c, f(2) = a,f(3) = b, and f(4) = d is a graph isomorphism, as is readily verified, so G ∼= H . In fact,for any bijection g : V → W , g is a graph isomorphism iff g(1) = c. By the Product Rule,there are 3! = 6 graph isomorphisms from G to H .

3.2 Walks and Matrices

We can travel through a graph by following several edges in succession. Formalizing thisidea leads to the concept of a walk.

3.10. Definition: Walks, Paths, Cycles. Let G = (V,E, ǫ) be a graph or digraph. Awalk in G is a sequence

W = (v0, e1, v1, e2, v2, . . . , vs−1, es, vs)

where s ≥ 0, vi ∈ V for all i, ei ∈ E for all i, and ei is an edge from vi−1 to vi for 1 ≤ i ≤ s.We say that W is a walk of length s from v0 to vs. The walk W is closed iff v0 = vs. Thewalk W is a path iff the vertices v0, v1, . . . , vs are pairwise distinct (which forces the edgesei to be distinct as well). The walk W is a cycle iff s > 0, v1, . . . , vs are distinct, e1, . . . , esare distinct, and v0 = vs. A k-cycle is a cycle of length k. In the case of simple graphs andsimple digraphs, the edges ei are determined uniquely by their endpoints. So, in the simplecase, we can regard a walk as a sequence of vertices (v0, v1, . . . , vs) such that there is anedge from vi−1 to vi in G for 1 ≤ i ≤ s.3.11. Remark. When considering cycles in a digraph, we often identify two cycles that arecyclic shifts of one another (unless we need to keep track of the starting vertex of the cycle).Similarly, we identify cycles in a graph that are cyclic shifts or reversals of one another.

3.12. Example. In the graph G1 from Figure 3.1,

W1 = (2, c, 3, f, 3, b, 4, h, 5, i, 4, i, 5)

Page 82: Combinatorics - Routledge

106 Combinatorics, Second Edition

q

23

5 61

4

a

b

c

d

e

fg jh

k

m

np

FIGURE 3.2Digraph used to illustrate adjacency matrices.

is a walk of length 6 from vertex 2 to vertex 5. In the simple graph G2 in the same figure,W2 = (1, 6, 2, 3, 4, 5) is a walk and a path of length 5, whereas C = (6, 5, 4, 3, 2, 6) is a 5-cycle. We often identify C with the cycles (5, 4, 3, 2, 6, 5), (6, 2, 3, 4, 5, 6), etc. In the digraphG3,

W3 = (1, a, 1, g, 5, h, 2,m, 4, j, 5, h, 2, d, 3)

is a walk from vertex 1 to vertex 3; (5, h, 2,m, 4, j, 5) is a 3-cycle; (4, l, 4) is a 1-cycle; and(5, f, 1, g, 5) is a 2-cycle. Observe that 1-cycles are the same as loop edges, and 2-cyclescannot exist in simple graphs. For any vertex v in a graph or digraph, (v) is a walk oflength zero from v to v, which is a path but not a cycle.

We can now formulate our first counting problem: how many walks of a given lengthare there between two given vertices in a graph or digraph? We will develop an algebraicsolution to this problem in which concatenation of walks is modeled by multiplication ofcertain matrices.

3.13. Definition: Adjacency Matrix. Let G be a graph or digraph with vertex setX = {xi : 1 ≤ i ≤ n}. The adjacency matrix of G (relative to the given indexing of thevertices) is the n× n matrix A whose i, j-entry A(i, j) is the number of edges in G from xito xj .

3.14. Example. The adjacency matrix for the digraph G in Figure 3.2 is

A =

1 0 1 0 0 00 0 0 1 1 00 0 0 0 1 00 0 3 0 1 00 1 0 2 0 00 0 0 0 0 2

.

3.15. Example. If G is a graph, edges from v to w are the same as edges from w to v.So, the adjacency matrix for G is a symmetric matrix (A(i, j) = A(j, i) for all i, j). If Gis a simple graph, the adjacency matrix consists of all 1’s and 0’s with zeroes on the main

Page 83: Combinatorics - Routledge

Counting Problems in Graph Theory 107

6

1

2

3

4

5

FIGURE 3.3A simple graph.

diagonal. For example, the adjacency matrix of the simple graph in Figure 3.3 is

0 0 0 1 1 10 0 0 1 1 10 0 0 1 1 11 1 1 0 0 01 1 1 0 0 01 1 1 0 0 0

.

Recall from linear algebra the definition of the product of two matrices.

3.16. Definition: Matrix Multiplication. Suppose A is an m × n matrix and B is ann× p matrix. Then AB is the m× p matrix whose i, j-entry is

(AB)(i, j) =

n∑

k=1

A(i, k)B(k, j) for 1 ≤ i ≤ m, 1 ≤ j ≤ p. (3.1)

Matrix multiplication is associative, so we can write a product of three or more (compat-ible) matrices without any parentheses. The next theorem gives a formula for the generalentry in such a product.

3.17. Theorem: Product of Several Matrices. Assume A1, . . . , As are matrices suchthat Ai has dimensions ni−1×ni. Then A1A2 · · ·As is the n0×ns matrix whose k0, ks-entryis

(A1A2 · · ·As)(k0, ks) =

n1∑

k1=1

n2∑

k2=1

· · ·ns−1∑

ks−1=1

A1(k0, k1)A2(k1, k2)A3(k2, k3) · · ·As(ks−1, ks)

(3.2)for all k0 and ks such that 1 ≤ k0 ≤ n0 and 1 ≤ ks ≤ ns.

Proof. We use induction on s. The case s = 1 is immediate, and the case s = 2 is thedefinition of matrix multiplication (after a change in notation). Assume s > 2 and that(3.2) is known to hold for the product B = A1A2 · · ·As−1. We can think of the givenproduct A1A2 · · ·As−1As as the binary product BAs. Therefore, using (3.1), the k0, ks-entry of A1A2 · · ·As is

(BAs)(k0, ks) =

ns−1∑

k=1

B(k0, k)As(k, ks)

=

ns−1∑

k=1

n1∑

k1=1

· · ·ns−2∑

ks−2=1

A1(k0, k1)A2(k1, k2) · · ·As−1(ks−2, k)

As(k, ks)

=

n1∑

k1=1

· · ·ns−2∑

ks−2=1

ns−1∑

k=1

A1(k0, k1)A2(k1, k2) · · ·As−1(ks−2, k)As(k, ks).

Page 84: Combinatorics - Routledge

108 Combinatorics, Second Edition

Replacing k by ks−1 in the innermost summation, we obtain the result.

Taking all Ai’s in the theorem to be the same matrix A, we obtain the following formulafor the entries of the powers of a given square matrix.

3.18. Corollary: Powers of a Matrix. Suppose A is an n× n matrix. For each integers > 0 and all i, j in the range 1 ≤ i, j ≤ n,

As(i, j) =

n∑

k1=1

· · ·n∑

ks−1=1

A(i, k1)A(k1, k2) · · ·A(ks−2, ks−1)A(ks−1, j). (3.3)

The preceding formula may appear unwieldy, but it is precisely the tool we need to countwalks in graphs.

3.19. The Walk Rule. Let G be a graph or digraph with vertex set X = {x1, . . . , xn},and let A be the adjacency matrix of G. For all i, j between 1 and n and all s ≥ 0, thei, j-entry of As is the number of walks of length s in G from xi to xj .

Proof. The result holds for s = 0, since A0 = In (the n × n identity matrix) and there isexactly one walk of length zero from any vertex to itself. Now suppose s > 0. A walk oflength s from xi to xj will visit s − 1 intermediate vertices (not necessarily distinct fromeach other or from xi or xj). Let (xi, xk1

, . . . , xks−1, xj) be the ordered list of vertices visited

by the walk. To build such a walk, we choose any edge from xi to xk1in A(i, k1) ways; then

we choose any edge from xk1to xk2

in A(k1, k2) ways; and so on. By the Product Rule, thetotal number of walks associated to this vertex sequence is A(i, k1)A(k1, k2) · · ·A(ks−1, j).This formula holds even if there are no walks with this vertex sequence, since some termin the product will be zero in this case. Applying the Sum Rule produces the right side of(3.3), and the result follows.

3.20. Example. Consider again the adjacency matrix A of the digraph G in Figure 3.2.Some matrix computations show that

A2 =

1 0 1 0 1 00 1 3 2 1 00 1 0 2 0 00 1 0 2 3 00 0 6 1 3 00 0 0 0 0 4

, A3 =

1 1 1 2 1 00 1 6 3 6 00 0 6 1 3 00 3 6 7 3 00 3 3 6 7 00 0 0 0 0 8

.

So, for example, there are six walks of length 2 from vertex 5 to vertex 3, and there areseven walks of length 3 that start and end at vertex 4. By looking at A9 = (A3)3, we findthat there are 1074 walks of length 9 from vertex 2 to vertex 4, but only 513 walks of length9 from vertex 4 to vertex 2.

3.3 Directed Acyclic Graphs and Nilpotent Matrices

Next we consider the question of counting all walks (of any length) between two verticesin a digraph. The question is uninteresting for graphs, since the number of walks betweentwo distinct vertices v, w in a graph is either zero or infinity. This follows since a walk isallowed to repeatedly traverse a particular edge along a path from v to w, which leads to

Page 85: Combinatorics - Routledge

Counting Problems in Graph Theory 109

arbitrarily long walks from v to w. Similarly, if G is a digraph that contains a cycle, weobtain arbitrarily long walks between two vertices on the cycle by going around the cycleagain and again. To rule out these possibilities, we restrict attention to the following classof digraphs.

3.21. Definition: DAGs. A DAG is a digraph with no cycles. (The acronym DAG standsfor “directed acyclic graph.”)

To characterize adjacency matrices of DAGs, we need another concept from matrixtheory.

3.22. Definition: Nilpotent Matrices. An n× n matrix A is called nilpotent iff As = 0for some integer s ≥ 1. The least such integer s is called the index of nilpotence of A.

Note that if As = 0 and t ≥ s, then At = 0 also.

3.23. Example. The zero matrix is the unique n×nmatrix with index of nilpotence 1. The

square of the nonzero matrix A =

[0 10 0

]is zero, so A is nilpotent of index 2. Similarly,

given any real x, y, z, the matrix

B =

0 x y0 0 z0 0 0

satisfies

B2 =

0 0 xz0 0 00 0 0

and B3 = 0,

so we obtain examples of matrices that are nilpotent of index 3. The next result generalizesthis example.

3.24. Theorem: Nilpotence of Strictly Triangular Matrices. Suppose A is an n× nstrictly upper-triangular matrix, which means A(i, j) = 0 for all i ≥ j. Then A is nilpotentof index at most n. A similar result holds for strictly lower-triangular matrices.

Proof. It suffices to show that An is the zero matrix. Fix k0 and kn between 1 and n. By(3.3), we have

An(k0, kn) =

n∑

k1=1

· · ·n∑

kn−1=1

A(k0, k1)A(k1, k2) · · ·A(kn−1, kn).

We claim that each term in this sum is zero. Otherwise, there would exist k1, . . . , kn−1 suchthat A(kt−1, kt) 6= 0 for each t between 1 and n. But since A is strictly upper-triangular,we would then have

k0 < k1 < k2 < · · · < kn.

This cannot occur, since every kt is an integer between 1 and n.

The next theorem reveals the connection between nilpotent matrices and DAGs.

3.25. Theorem: DAGs and Nilpotent Matrices. Let G be a digraph with vertex setX = {x1, . . . , xn} and adjacency matrix A. G is a DAG iff A is nilpotent. When G is aDAG, there exists an ordering of the vertex set X for which A is a strictly lower-triangularmatrix.

Page 86: Combinatorics - Routledge

110 Combinatorics, Second Edition

Proof. Assume first that G is not a DAG, so that G has at least one cycle. Let xi be anyfixed vertex involved in this cycle, and let c ≥ 1 be the length of this cycle. By going aroundthe cycle zero or more times, we obtain walks from xi to xi of lengths 0, c, 2c, 3c, . . .. Bythe Walk Rule, it follows that the (i, i)-entry of Akc is at least 1, for all k ≥ 0. This factprevents any positive power of A from being the zero matrix, so A is not nilpotent.

Conversely, assume that A is not nilpotent. Then, in particular, An 6= 0, so there existindices k0, kn with An(k0, kn) 6= 0. Using the Walk Rule again, we deduce that there is awalk in G visiting a sequence of vertices

(xk0, xk1

, xk2, . . . , xkn−1

, xkn).

Since G has only n vertices, not all of the n+1 vertices listed here are distinct. If we choosei minimal and then j > i minimal such that xki = xkj , then there is a cycle in G visitingthe vertices (xki , xki+1

, . . . , xkj ). So G is not a DAG.We prove the statement about lower-triangular matrices by induction on n. A DAG with

only one vertex must have adjacency matrix [0], so the result holds for n = 1. Suppose n > 1and the result is known for DAGs with n − 1 vertices. Create a walk (v0, e1, v1, e2, v2, . . .)in G by starting at any vertex and repeatedly following any edge leading away from thecurrent vertex. Since G has no cycles, the vertices vi reached by this walk are pairwisedistinct. Since there are only n available vertices, our walk must terminate at a vertex vjwith no outgoing edges. Let x′1 = vj . Deleting x′1 and all edges with x′1 as one endpointproduces an (n − 1)-vertex digraph G′ that is also a DAG, as one immediately verifies.By induction, there is an ordering x′2, . . . , x

′n of the vertices of G′ such that the associated

adjacency matrix A′ is strictly lower-triangular. Now, relative to the ordering x′1, x′2, . . . , x

′n

of the vertices of G, the adjacency matrix of G has the form

0 0 · · · 0∗... A′

,

where each ∗ denotes some nonnegative integer. This matrix is strictly lower-triangular.

The next result leads to a formula for counting walks of any length in a DAG.

3.26. Theorem: Inverse of I − A for Nilpotent A. Suppose A is a nilpotent n × nmatrix with As = 0. Let I be the n× n identity matrix. Then I −A is an invertible matrixwith inverse

(I −A)−1 = I +A+A2 +A3 + · · ·+As−1.

Proof. Let B = I +A+A2 + · · ·+As−1. By the distributive law for matrices,

(I −A)B = IB −AB = (I +A+A2 + · · ·+As−1)− (A+A2 + · · ·+As−1 +As) = I −As.

Since As = 0, we see that (I − A)B = I. A similar calculation shows that B(I − A) = I.Therefore B is the two-sided matrix inverse of I −A.

3.27. Remark. The previous result for matrices can be remembered by noting the analogyto the Geometric Series Formula for real or complex numbers: whenever |r| < 1,

(1− r)−1 =1

1− r = 1 + r + r2 + · · ·+ rs−1 + rs + · · · .

Page 87: Combinatorics - Routledge

Counting Problems in Graph Theory 111

8

1 2

3 4 5

6

7

FIGURE 3.4Example of a DAG.

3.28. The Path Rule for DAGs. Let G be a DAG with vertex set {x1, . . . , xn} andadjacency matrix A. For all i, j between 1 and n, the total number of paths from xi to xjin G (of any length) is the i, j-entry of (I −A)−1.

Proof. By the Walk Rule, the number of walks of length t ≥ 0 from xi to xj is At(i, j).Because G is a DAG, we have At = 0 for all t ≥ n. By the Sum Rule, the total numberof walks from xi to xj is

∑n−1t=0 A

t(i, j). By Theorem 3.26, this number is precisely thei, j-entry of (I −A)−1. Finally, one readily confirms that every walk in a DAG must in factbe a path.

3.29. Example. Consider the DAG shown in Figure 3.4. Its adjacency matrix is

A =

0 0 1 1 0 0 1 00 0 0 1 1 1 0 00 0 0 0 0 0 1 10 0 0 0 0 1 1 00 0 0 0 0 2 0 00 0 0 0 0 0 2 10 0 0 0 0 0 0 10 0 0 0 0 0 0 0

.

Using a computer algebra system, we compute

(I −A)−1 =

1 0 1 1 0 1 5 70 1 0 1 1 4 9 130 0 1 0 0 0 1 20 0 0 1 0 1 3 40 0 0 0 1 2 4 60 0 0 0 0 1 2 30 0 0 0 0 0 1 10 0 0 0 0 0 0 1

.

So, for example, there are 13 paths from vertex 2 to vertex 8, and 4 paths from vertex 5 tovertex 7.

Page 88: Combinatorics - Routledge

112 Combinatorics, Second Edition

3.4 Vertex Degrees

The next definition introduces notation that records how many edges lead into or out ofeach vertex in a digraph.

3.30. Definition: Indegree and Outdegree. Let G = (V,E, ǫ) be a digraph. For eachv ∈ V , the outdegree of v, denoted outdegG(v), is the number of edges e ∈ E leading awayfrom v; the indegree of v, denoted indegG(v), is the number of edges e ∈ E leading to v. Asource is a vertex of indegree zero. A sink is a vertex of outdegree zero.

3.31. Example. Let G3 be the digraph on the right in Figure 3.1. We have

(indegG3(1), . . . , indegG3

(7)) = (2, 2, 4, 2, 2, 0, 1);

(outdegG3(1), . . . , outdegG3

(7)) = (3, 4, 0, 3, 2, 1, 0).

Vertex 6 is the only source, whereas vertices 3 and 7 are sinks. A loop edge at v contributes1 to both the indegree and outdegree of v. The sum of all the indegrees is 13, which isalso the sum of all the outdegrees, and is also the number of edges in the digraph. Thisphenomenon is explained in the next theorem.

3.32. Theorem: Degree Sum Formula for Digraphs. In any digraph G = (V,E, ǫ),

v∈VindegG(v) = |E| =

v∈VoutdegG(v).

Proof. For each v ∈ V , let Ev be the set of edges e ∈ E ending at v, meaning thatǫ(e) = (w, v) for some w ∈ V . By definition of indegree, |Ev| = indegG(v) for each v ∈ V .The set E of all edges is the disjoint union of the sets Ev as v varies through V . By theSum Rule, |E| =∑v∈V |Ev| =

∑v∈V indegG(v). The formula involving outdegree is proved

similarly.

Next we give analogous definitions and results for graphs.

3.33. Definition: Degree. Let G = (V,E, ǫ) be a graph. For each v ∈ V , the degree ofv in G, denoted degG(v), is the number of edges in E having v as an endpoint, where anyloop edge at v is counted twice. The degree multiset of G, denoted deg(G), is the multiset[degG(v) : v ∈ V ]. G is called k-regular iff every vertex in G has degree k. G is regular iff Gis k-regular for some k ≥ 0.

3.34. Example. For the graph G1 in Figure 3.1, we have

(degG1(1), . . . , degG1

(5)) = (3, 4, 4, 4, 3); deg(G1) = [4, 4, 4, 3, 3].

The graph in Figure 3.3 is 3-regular. In both of these graphs, the sum of all vertex degreesis 18, which is twice the number of edges in the graph.

3.35. Theorem: Degree Sum Formula for Graphs. For any graph G = (V,E, ǫ),

v∈VdegG(v) = 2|E|.

Proof. First assume G has no loop edges. Let X be the set of pairs (v, e) such that v ∈ V ,e ∈ E, and v is an endpoint of e. We count X in two ways. On one hand, X is the disjointunion of sets Xv, where Xv consists of pairs in X with first component v. The second

Page 89: Combinatorics - Routledge

Counting Problems in Graph Theory 113

component of such a pair can be any edge incident to v, so |Xv| = degG(v). By the SumRule, |X | =∑v∈V |Xv| =

∑v∈V degG(v). On the other hand, we can build an object (v, e)

in X by first choosing e (in any of |E| ways) and then choosing one of the two endpoints vof e (2 ways, since G has no loop edges). So |X | = 2|E| by the Product Rule, and the resultholds in this case.

Next, if G has k loop edges, let G′ be G with these loops deleted. Then

v∈VdegG(v) =

v∈VdegG′(v) + 2k,

since each loop edge increases some vertex degree in the sum by 2. Using the result forloopless graphs, ∑

v∈VdegG(v) = 2|E(G′)|+ 2k = 2|E(G)|,

since G has k more edges than G′.

Vertices of low degree are given special names.

3.36. Definition: Isolated Vertices and Leaves. An isolated vertex in a graph is avertex of degree 0. A leaf is a vertex of degree 1.

The following result will be used later in our analysis of trees.

3.37. The Two-Leaf Lemma. Suppose G is a graph. One of the following three alterna-tives must occur: (i) G has a cycle; (ii) G has no edges; or (iii) G has at least two leaves.

Proof. Suppose that G has no cycles and G has at least one edge; we prove that G has twoleaves. Since G has no cycles, we can assume G is simple. Let P = (v0, v1, . . . , vs) be a pathof maximum length in G. Such a path exists, since G has only finitely many vertices andedges. Observe that s > 0 since G has an edge, and v0 6= vs. Note that deg(vs) ≥ 1 sinces > 0. Assume vs is not a leaf. Then there exists a vertex w 6= vs−1 that is adjacent to vs.Now, w is different from all vj with 0 ≤ j < s− 1, since otherwise (vj , vj+1, . . . , vs, w = vj)would be a cycle in G. But this means (v0, v1, . . . , vs, w) is a path in G longer than P ,contradicting maximality of P . So vs must be a leaf. A similar argument shows that v0 isalso a leaf.

3.5 Functional Digraphs

We can obtain structural information about functions f : V → V by viewing these functionsas certain kinds of digraphs.

3.38. Definition: Functional Digraphs. A functional digraph on V is a simple digraphG with vertex set V such that outdegG(v) = 1 for all v ∈ V .

A function f : V → V can be thought of as a set Ef of ordered pairs such that for eachx ∈ V , there exists exactly one y ∈ V with (x, y) ∈ Ef , namely y = f(x). Then (V,Ef ) is afunctional digraph on V . Conversely, a functional digraph G = (V,E) determines a uniquefunction g : V → V by letting g(v) be the other endpoint of the unique edge in E departingfrom v. These comments establish a bijection between the set of functions on V and the setof functional digraphs on V .

Page 90: Combinatorics - Routledge

114 Combinatorics, Second Edition

10

12 4 17 15 3 8 5

6

9

7

11 13 14 16

2

1

FIGURE 3.5A functional digraph.

3.39. Example. Figure 3.5 displays the functional digraph associated to the followingfunction:

f(1) = 15; f(2) = 16; f(3) = 8; f(4) = 17; f(5) = 5;f(6) = 5; f(7) = 4; f(8) = 3; f(9) = 6; f(10) = 4;f(11) = 10; f(12) = 4; f(13) = 10; f(14) = 1; f(15) = 12;f(16) = 1; f(17) = 15.

Our next goal is to understand the structure of functional digraphs. Consider the digraphG = (V,E) shown in Figure 3.5. Some of the vertices in this digraph are involved in cycles,which are drawn at the bottom of the figure. These cycles have length 1 or greater, and anytwo distinct cycles involve disjoint sets of vertices. The other vertices in the digraph all feedinto these cycles at different points. We can form a set partition of the vertex set of thedigraph by collecting together all vertices that feed into a particular vertex on a particularcycle. Each such collection can be viewed as a smaller digraph that has no cycles. We willshow that these observations hold for all functional digraphs. To do this, we need a fewmore defintions.

3.40. Definition: Cyclic Vertices. Let G be a functional digraph on V . A vertex v ∈ Vis called cyclic iff v belongs to some cycle of G; otherwise, v is called acyclic.

3.41. Example. The cyclic elements for the functional digraph in Figure 3.5 are 3, 4, 5,8, 12, 15, and 17.

Let f : V → V be the function associated to the functional digraph G. Then v ∈ Vis cyclic iff f i(v) = v for some i ≥ 1, where f i denotes the composition of f with itselfi times. This fact follows since the only possible cycle involving v in G must look like(v, f(v), f2(v), f3(v), . . .).

3.42. Definition: Rooted Trees. A digraph G is called a rooted tree with root v0 iff G isa functional digraph and v0 is the unique cyclic vertex of G.

3.43. Theorem: Structure of Functional Digraphs. Let G be a functional digraph ona nonempty set V with associated function f : V → V . Let C ⊆ V denote the set of cyclicvertices of G. C is nonempty, and each v ∈ C belongs to exactly one cycle of G. Also, thereexists a unique indexed set partition {Sv : v ∈ C} of V such that the following hold for allv ∈ C: (i) v ∈ Sv; (ii) x ∈ Sv and x 6= v implies f(x) ∈ Sv; (iii) if g : Sv → Sv is definedby setting g(x) = f(x) for x 6= v and g(v) = v, then the functional digraph of g is a rootedtree with root v.

Page 91: Combinatorics - Routledge

Counting Problems in Graph Theory 115

Proof. First, suppose v ∈ C. Since every vertex of G has exactly one outgoing edge, theonly possible cycle involving v must be (v, f(v), f2(v), . . . , f i(v) = v). So each cyclic vertex(if any) belongs to a unique cycle of G. This implies that distinct cycles of G involve disjointsets of vertices and edges.

Next we define a surjection r : V → C. The existence of r will show that C 6= ∅, sinceV 6= ∅. Fix u ∈ V . By repeatedly following outgoing arrows, we obtain for each k ≥ 0 aunique walk (u = u0, u1, u2, . . . , uk) in G of length k. Since V is finite, there must exist i < jwith ui = uj . Take i minimal and then j minimal with this property; then (ui, ui+1, . . . , uj)is a cycle in G. We define r(u) = ui, which is the first element on this cycle reached fromu. It can be checked that r(u) = u for all u ∈ C; this implies that r is surjective. On theother hand, if u 6∈ C, the definition of r shows that r(u) = r(u1) = r(f(u)).

How shall we construct a set partition with the stated properties? For each v ∈ C,consider the fiber Sv = r−1({v}) = {w ∈ V : r(w) = v}; then {Sv : v ∈ C} is a setpartition of V indexed by C. The remarks at the end of the last paragraph show that thisset partition satisfies (i) and (ii). To check (iii) for fixed v ∈ C, first note that the map gdefined in (iii) does map Sv into Sv by (i) and (ii). Suppose W = (w0, w1, . . . , wk) is a cyclein the functional digraph for g. Since r(w0) = v, we will eventually reach v by followingoutgoing arrows starting at w0. On the other hand, following these arrows keeps us on thecycle W , so some wi = v. Since g(v) = v, the only possibility is that W is the 1-cycle (v).Thus (iii) holds for each v ∈ C.

To see that {Sv : v ∈ C} is unique, let P = {Tv : v ∈ C} be another set partitionwith properties (i), (ii), and (iii). It is enough to show that Sv ⊆ Tv for each v ∈ C. Fixv ∈ C and z ∈ Sv. By (ii), every element in the sequence (z, f(z), f2(z), . . .) belongs to thesame set of P , say Tw. Then v = r(z) = f i(z) ∈ Tw, so (i) forces w = v. Thus z ∈ Tv asneeded.

We can informally summarize the previous result by saying that every functional digraphuniquely decomposes into disjoint rooted trees feeding into one or more disjoint cycles. Thereare two extreme cases of this decomposition that are especially interesting — the case wherethere are no trees (i.e., C = V ), and the case where the whole digraph is a rooted tree (i.e.,|C| = 1). We study these types of functional digraphs in the next two sections.

3.6 Cycle Structure of Permutations

The functional digraph of a bijection (permutation) has special structure, as we see in thenext example.

3.44. Example. Figure 3.6 displays the digraph associated to the following bijection:

h(1) = 7; h(2) = 8; h(3) = 4; h(4) = 3; h(5) = 10;h(6) = 2; h(7) = 5; h(8) = 6; h(9) = 9; h(10) = 1.

We see that the digraph for h contains only cycles; there are no trees feeding into thesecycles. To see why this happens, compare this digraph to the digraph for the non-bijectivefunction f in Figure 3.5. The digraph for f has a rooted tree feeding into the cyclic vertex15. Accordingly, f is not injective since f(17) = 15 = f(1). Similarly, if we move backwardthrough the trees in the digraph of f , we reach vertices with indegree zero (namely 2, 7, 9,11, 13, and 14). The existence of such vertices shows that f is not surjective. Returning to

Page 92: Combinatorics - Routledge

116 Combinatorics, Second Edition

61 7 5 10 3 4 9 2 8

FIGURE 3.6Digraph associated to a permutation.

the digraph of h, consider what happens if we reverse the direction of all the edges in thedigraph. We obtain another functional digraph corresponding to the following function:

h′(1) = 10; h′(2) = 6; h′(3) = 4; h′(4) = 3; h′(5) = 7;h′(6) = 8; h′(7) = 1; h′(8) = 2; h′(9) = 9; h′(10) = 5.

One sees immediately that h′ is the two-sided inverse for h, so that h is bijective.

The next theorem explains the observations in the last example.

3.45. Theorem: Cycle Decomposition of Permutations. Let f : V → V be a functionwith functional digraph G. The map f is a bijection iff every v ∈ V is a cyclic vertex in V .In this situation, G is a disjoint union of cycles.

Proof. Suppose u ∈ V is a non-cyclic vertex. By Theorem 3.43, u belongs to a rooted treeSv whose root v belongs to a cycle of G. Following edges outward from u will eventuallylead to v; let y be the vertex in Sv just before v on this path. Let z be the vertex justbefore v in the unique cycle involving v. We have y 6= z, but f(y) = v = f(z). Thus, f isnot injective.

Conversely, suppose all vertices in V are cyclic. Then the digraph G is a disjoint union ofdirected cycles. So every v ∈ V has indegree 1 as well as outdegree 1. Reversing the directionof every edge in G therefore produces another functional digraph G′. Let f ′ : V → V be thefunction associated to this new digraph. For all a, b ∈ V , we have b = f(a) iff (a, b) ∈ E(G)iff (b, a) ∈ E(G′) iff a = f ′(b). It follows that f ′ is the two-sided inverse for f , so that f andf ′ are both bijections.

Recall that S(n, k), the Stirling number of the second kind, is the number of set partitionsof an n-element set into k blocks. Let c(n, k) be the number of permutations of an n-elementset whose functional digraph consists of k disjoint cycles. We will show that c(n, k) =s′(n, k), the signless Stirling number of the first kind. Recall from Recursion 2.58 that thenumbers s′(n, k) satisfy s′(n, k) = s′(n− 1, k − 1) + (n− 1)s′(n− 1, k) for 0 < k < n, withinitial conditions s′(n, 0) = 0 for n > 0 and s′(n, n) = 1 for n ≥ 0.

3.46. Theorem: Recursion for c(n, k). For 0 < k < n, we have

c(n, k) = c(n− 1, k − 1) + (n− 1)c(n− 1, k).

The initial conditions are c(n, 0) = 0 for n > 0 and c(n, n) = 1 for n ≥ 0. Therefore,c(n, k) = s′(n, k) for 0 ≤ k ≤ n.Proof. The identity map is the unique permutation of an n-element set with n cycles (whichmust each have length 1), so c(n, n) = 1 for n ≥ 0. The only permutation with zero cyclesis the empty function on the empty set, so c(n, 0) = 0 for n > 0. Now suppose 0 < k < n.Let A,B,C be the sets of permutations counted by c(n, k), c(n− 1, k− 1), and c(n− 1, k),respectively. Note that A is the disjoint union of the two sets

A1 = {f ∈ A : f(n) = n} and A2 = {f ∈ A : f(n) 6= n}.

Page 93: Combinatorics - Routledge

Counting Problems in Graph Theory 117

For each f ∈ A1, we can restrict f to the domain {1, 2, . . . , n− 1} to obtain a permutationof these n− 1 elements. Since f has k cycles, one of which involves n alone, the restrictionof f must have k − 1 cycles. Since f ∈ A1 is uniquely determined by its restriction to{1, 2, . . . , n− 1}, we have a bijection from A1 onto B.

On the other hand, let us build a typical element f ∈ A2 by making two choices.First, choose a permutation g ∈ C in c(n − 1, k) ways. Second, choose an element i ∈{1, 2, . . . , n− 1} in n− 1 ways. Let j be the unique number such that g(j) = i. Modify thedigraph for g by removing the arrow from j to i and replacing it by an arrow from j ton and an arrow from n to i. Informally, we are splicing n into the cycle just before i. Letf be the permutation associated to the new digraph. Evidently, the splicing process doesnot change the number of cycles of g, and f satisfies f(n) 6= n. Thus, f ∈ A2, and everyelement of A2 arises uniquely by the choice process we have described. By the Sum Ruleand Product Rule,

c(n, k) = |A| = |A1|+ |A2| = c(n− 1, k − 1) + (n− 1)c(n− 1, k).

So c(n, k) and s′(n, k) satisfy the same recursion and initial conditions. A routine inductionproof now shows that c(n, k) = s′(n, k) for all integers n, k ≥ 0.

3.7 Counting Rooted Trees

Our goal in this section is to count rooted trees (see Definition 3.42) with a fixed root vertex.

3.47. The Rooted Tree Rule. For all n > 1, there are nn−2 rooted trees on the vertexset {1, 2, . . . , n} with root 1.

Proof. Let B be the set of rooted trees mentioned in the theorem. Let A be the set of allfunctions f : {1, 2, . . . , n} → {1, 2, . . . , n} such that f(1) = 1 and f(n) = n. The ProductRule shows that |A| = nn−2. It therefore suffices to define maps φ : A→ B and φ′ : B → Athat are mutual inverses. To define φ, fix f ∈ A. Let Gf be the functional digraph associatedwith f , which has directed edges (i, f(i)) for 1 ≤ i ≤ n. By Theorem 3.43, we can decomposethe vertex set {1, 2, . . . , n} of this digraph into some disjoint cycles C0, C1, . . . , Ck and(possibly) some trees feeding into these cycles. For 0 ≤ i ≤ k, let ℓi be the largest vertex incycle Ci, and write Ci = (ri, . . . , ℓi). We can choose the indexing of the cycles so that thenumbers ℓi satisfy ℓ0 > ℓ1 > ℓ2 > · · · > ℓk. Since f(1) = 1 and f(n) = n, 1 and n belongto cycles of length 1, so that ℓ0 = r0 = n, C0 = (n), ℓk = rk = 1, Ck = (1), and k > 0.To obtain φ(f), we modify the digraph Gf by removing all edges of the form (ℓi, ri) andadding new edges (ℓi, ri+1), for 0 ≤ i < k. It can be checked that φ(f) is always a rootedtree with root 1.

3.48. Example. Suppose n = 20 and f is the function defined as follows:

f(1) = 1; f(2) = 19; f(3) = 8; f(4) = 17; f(5) = 5;f(6) = 5; f(7) = 4; f(8) = 3; f(9) = 6; f(10) = 1;f(11) = 18; f(12) = 4; f(13) = 18; f(14) = 20; f(15) = 15;f(16) = 1; f(17) = 12; f(18) = 4; f(19) = 20; f(20) = 20.

We draw the digraph of f in such a way that all vertices involved in cycles occur in a hori-zontal row at the bottom of the figure, and the largest element in each cycle is the rightmostelement of its cycle. We arrange these cycles so that these largest elements decrease from

Page 94: Combinatorics - Routledge

118 Combinatorics, Second Edition

10

20

14 19

2 11 13

18 7

4 1712 15 3 8 5 1

166

9

FIGURE 3.7A functional digraph with cycles arranged in canonical order.

10

20

14 19

2 11 13

18 7

4 1712 15 3 8 5 1

166

9

FIGURE 3.8Conversion of the digraph to a rooted tree.

left to right; in particular, vertex n is always at the far left, and vertex 1 at the far right.See Figure 3.7. To compute φ(f), we cut the back-edges leading left from ℓi to ri (whichare loops if ℓi = ri) and add new edges leading right from ℓi to ri+1. See Figure 3.8.

Continuing the proof, let us see why φ is invertible. Let T be a rooted tree on {1, 2, . . . , n}with root 1. Following outgoing edges from nmust eventually lead to the unique cyclic vertex1. Let P = (v0, v1, . . . , vs) be the vertices encountered on the way from v0 = n to vs = 1.We recursively recover the numbers ℓ0, ℓ1, . . . , ℓk as follows. Let ℓ0 = n. Define ℓ1 to be thelargest number in P following ℓ0. In general, after ℓi−1 has been found, define ℓi to be thelargest number in P following ℓi−1. After finitely many steps, we will get ℓk = 1 for somek. Next, let r0 = n, and for i > 0, let ri be the vertex immediately following ℓi−1 on thepath P . Modify T by deleting the edges (ℓi, ri+1) and adding edges of the form (ℓi, ri), for0 ≤ i < k. It can be verified that every vertex in the resulting digraph G′ has outdegreeexactly 1, and there are loop edges in G′ at vertex 1 and vertex n. Thus, G′ is a functionaldigraph that determines a function f = φ′(T ) ∈ A. It follows from the definition of φ′ thatφ′ is the two-sided inverse of φ.

3.49. Example. Suppose n = 9 and T is the rooted tree shown on the left in Figure 3.9.We first redraw the picture of T so that the vertices on the path P from n to 1 occur ina horizontal row at the bottom of the picture, with n on the left and 1 on the right. Werecover ℓi and ri by the procedure above, and then delete the appropriate edges of T andadd appropriate back-edges to create cycles. The resulting functional digraph appears on

Page 95: Combinatorics - Routledge

Counting Problems in Graph Theory 119

3

redraw

create cycles

1

23

5 7

8 9

4

6

8

5

4

96 7 2 1

3

8

5

4

96 7 2 1

FIGURE 3.9Conversion of a rooted tree to a functional digraph.

the bottom right in Figure 3.9. So φ′(T ) is the function g defined as follows:

g(1) = 1; g(2) = 2; g(3) = 2; g(4) = 9; g(5) = 9;g(6) = 7; g(7) = 6; g(8) = 9; g(9) = 9.

3.8 Connectedness and Components

In many applications of graphs, we need to know whether every vertex is reachable fromevery other vertex.

3.50. Definition: Connectedness. Let G = (V,E, ǫ) be a graph or digraph. G is con-nected iff for all u, v ∈ V , there is a walk in G from u to v.

3.51. Example. The graph G1 in Figure 3.1 is connected, but the simple graph G2 andthe digraph G3 in that figure are not connected.

Connectedness can also be described using paths instead of walks.

3.52. Theorem: Walks and Paths. Let G = (V,E, ǫ) be a graph or digraph, and letu, v ∈ V . There is a walk in G from u to v iff there is a path in G from u to v.

Proof. Let W = (v0, e1, v1, . . . , es, vs) be a walk in G from u to v. We describe an algorithmto convert the walk W into a path from u to v. If all the vertices vi are distinct, then theedges ei must also be distinct, so W is already a path. Otherwise, choose i minimal suchthat vi appears more than once in W , and then choose j maximal such that vi = vj . ThenW1 = (v0, e1, v1, . . . , ei, vi, ej+1, vj+1, . . . , es, vs) is a walk from u to v of shorter length than

Page 96: Combinatorics - Routledge

120 Combinatorics, Second Edition

13

1

2

3

4

5

67

8

9

10

11

12

FIGURE 3.10Converting a walk to a path.

W . If W1 is a path, we are done. Otherwise, we repeat the argument to obtain a walk W2

from u to v that is shorter than W1. Since the lengths keep decreasing, this process musteventually terminate with a path Wk from u to v. (Wk has length zero if u = v.) Theconverse is immediate, since every path in G from u to v is a walk in G from u to v.

3.53. Example. In the simple graph shown in Figure 3.10, consider the walk

W = (11, 10, 1, 2, 10, 3, 4, 8, 11, 8, 12, 10, 6, 9, 7, 13, 9, 12, 8, 5).

First, the repetition v0 = 11 = v8 leads to the walk

W1 = (11, 8, 12, 10, 6, 9, 7, 13, 9, 12, 8, 5).

Eliminating the multiple visits to vertex 8 leads to the walk

W2 = (11, 8, 5).

W2 is a path from 11 to 5.

3.54. Corollary: Connectedness and Paths. A graph or digraph G = (V,E, ǫ) is con-nected iff for all u, v ∈ V , there is at least one path in G from u to v.

By looking at pictures of graphs, it becomes visually evident that any graph decomposesinto a disjoint union of connected pieces, with no edge joining vertices in two separate pieces.These pieces are called the (connected) components of the graph. The situation for digraphsis more complicated, since there may exist directed edges between different components. Togive a formal development of these ideas, we introduce the following equivalence relation.

3.55. Definition: Interconnection Relation. Let G = (V,E, ǫ) be a graph or digraph.Define a binary relation ↔G on the vertex set V by setting u↔G v iff there exist walks inG from u to v and from v to u.

In the case of graphs, note that u ↔G w iff there is a walk in G from u to w, since thereversal of such a walk is a walk in G from w to u. Now, for a graph or digraph G, let usverify that ↔G is indeed an equivalence relation on V . First, for all u ∈ V , (u) is a walk oflength 0 from u to u, so u ↔G u, and ↔G is reflexive on V . Second, the symmetry of ↔G

is automatic from the way we defined↔G: u↔G v implies v ↔G u for all u, v ∈ V . Finally,

Page 97: Combinatorics - Routledge

Counting Problems in Graph Theory 121

to check transitivity, suppose u, v, w ∈ V satisfy u ↔G v and v ↔G w. Let W1, W2, W3,and W4 be walks in G from u to v, from v to w, from v to u, and from w to v, respectively.Then the concatenation of W1 followed by W2 is a walk in G from u to w, whereas theconcatenation of W4 followed by W3 is a walk in G from w to u. Hence u↔G w, as needed.

3.56. Definition: Components. Let G = (V,E, ǫ) be a graph or digraph. The componentsof G are the equivalence classes of the interconnection equivalence relation↔G. Componentsare also called connected components or (in the case of digraphs) strong components.

Since ↔G is an equivalence relation on V , the components of G form a set partitionof the vertex set V . Given a component C of G, consider the graph or digraph (C,E′, ǫ′)obtained by retaining those edges in E with both endpoints in C and restricting ǫ to thisset of edges. One may check that this graph or digraph is connected.

3.57. Example. The components of the graph G2 in Figure 3.1 are {0} and {1, 2, 3, 4, 5, 6}.The components of the digraph G3 in that figure are {1, 2, 4, 5}, {3}, {6}, and {7}.

The next theorems describe how the addition or deletion of an edge affects the compo-nents of a graph.

3.58. Theorem: Edge Deletion and Components. Let G = (V,E, ǫ) be a graph withcomponents {Ci : i ∈ I}. Let e ∈ E be an edge with endpoints v, w ∈ Cj . Let G

′ = (V,E′, ǫ′)where E′ = E−{e} and ǫ′ is the restriction of ǫ to E′. (a) If e appears in some cycle of G,then G and G′ have the same components. (b) If e appears in no cycle of G, then G′ hasone more component than G. More precisely, the components of G′ are the Ck with k 6= j,together with two disjoint sets A and B such that A ∪B = Cj , v ∈ A, and w ∈ B.

Proof. For (a), let (v0, e1, v1, e2, . . . , vs) be a cycle of G containing e. Cyclically shifting andreversing the cycle if needed, we can assume v0 = v = vs, e1 = e, and v1 = w. Statement (a)will follow if we can show that the interconnection relations ↔G and ↔G′ coincide. First,for all y, z ∈ V , y ↔G′ z implies y ↔G z since every walk in the smaller graph G′ is also awalk in G. On the other hand, does y ↔G z imply y ↔G′ z? We know there is a walk Wfrom y to z in G. If W does not use the edge e, W is a walk from y to z in G′. Otherwise,we can modify W as follows. Every time W goes from v = vs = v0 to w = v1 via e, replacethis part of the walk by the sequence (vs, es, . . . , e2, v1) obtained by taking a detour aroundthe cycle. Make a similar modification each time W goes from w to v via e. This producesa walk in G′ from y to z.

For (b), let us compute the equivalence classes of ↔G′ . First, fix z ∈ Ck where k 6= j.The set Ck consists of all vertices in V reachable from z by walks in G. It can be checkedthat none of these walks can use the edge e, so Ck is also the set of all vertices in V reachablefrom z by walks in G′. So Ck is the equivalence class of z relative to both ↔G and ↔G′ .

Next, let A and B be the equivalence classes of v and w (respectively) relative to ↔G′ .By definition, A and B are two of the components of G′ (possibly the same component). Wenow show that A and B are disjoint and that their union is Cj . If the equivalence classes Aand B are not disjoint, then they must be equal. By Theorem 3.52, there must be a path(v0, e1, v1, . . . , es, vs) in G

′ from v to w. Appending e, v0 to this path would produce a cyclein G involving the edge e, which is a contradiction. Thus A and B are disjoint.

We now show that A ∪ B ⊆ Cj . If z ∈ A, then there is a walk in G′ (and hence in G)from v to z. Since Cj is the equivalence class of v relative to ↔G, it follows that z ∈ Cj .Similarly, z ∈ B implies z ∈ Cj since Cj is also the equivalence class of w relative to ↔G.Next, we check that Cj ⊆ A ∪B. Let z ∈ Cj , and let W = (w0, e1, w1, . . . , wt) be a walk inG from v to z. If W does not use the edge e, then z ∈ A. If W does use e, then the portionof W following the last appearance of the edge e is a walk from either v or w to z in G′;

Page 98: Combinatorics - Routledge

122 Combinatorics, Second Edition

thus z ∈ A ∪B. Since the union of A, B, and the Ck with k 6= j is all of V , we have foundall the components of G′.

The previous result suggests the following terminology.

3.59. Definition: Cut-Edges. An edge e in a graph G is a cut-edge iff e does not appearin any cycle of G.

3.60. Theorem: Edge Addition and Components. Let G = (V,E, ǫ) be a graph withcomponents {Ci : i ∈ I}. Let G+ = (V,E+, ǫ+) be the graph obtained from G by adding anew edge e with endpoints v ∈ Cj and w ∈ Ck. (a) If v and w are in the same component Cj

of G, then e is involved in a cycle of G+, and G and G+ have the same components. (b) Ifv and w are in different components of G, then e is a cut-edge of G+, and the componentsof G+ are Cj ∪ Ck and the Ci with i 6= j, k.

This theorem follows readily from Theorem 3.58, so we omit the proof.

3.9 Forests

3.61. Definition: Forests. A forest is a graph with no cycles. Such a graph is also calledacyclic.

A forest cannot have any loops or multiple edges between the same two vertices. So wecan assume, with no loss of generality, that forests are simple graphs.

3.62. Example. Figure 3.11 displays a forest.

101

23 4

911

56

7

8

FIGURE 3.11A forest.

Recall from Corollary 3.54 that a graph G is connected iff there exists at least onepath between any two vertices of G. The next result gives an analogous characterization offorests.

3.63. Theorem: Forests and Paths. A graph G is acyclic iff G has no loops and for allu, v in V (G), there is at most one path from u to v in G.

Proof. We prove the contrapositive in both directions. First suppose that G has a cycleC = (v0, e1, v1, . . . , es, vs). If s = 1, G has a loop. If s > 1, then (v1, e2, . . . , es, vs) and(v1, e1, v0) are two distinct paths in G from v1 to v0.

Page 99: Combinatorics - Routledge

Counting Problems in Graph Theory 123

For the converse, we may assume G is simple since non-simple graphs must have cycles oflength 1 or 2. The simple graph G has no loops, so we can assume that for some u, v ∈ V (G),there exist two distinct paths P and Q from u to v in G. Among all such choices of u, v,P , and Q, choose one for which the path P has minimum length. Let P visit the sequenceof vertices (x0, x1, . . . , xs), and let Q visit the sequence of vertices (y0, y1, . . . , yt), wherex0 = u = y0, xs = v = yt, and s is minimal. We must prove G has a cycle.

First note that s > 0; otherwise u = v and Q would not be a path. Second, we assert thatx1 6= y1; otherwise, we would have two distinct paths P ′ = (x1, . . . , xs) and Q

′ = (y1, . . . , yt)from x1 to v with P ′ shorter than P , contradicting minimality of P . More generally, weclaim that xi 6= yj for all i, j satisfying 1 ≤ i < s and 1 ≤ j < t. For if we had xi = yjfor some i, j in this range, then P ′′ = (x0, x1, . . . , xi) and Q′′ = (y0, y1, . . . , yj) would betwo paths from u to xi with P ′′ shorter than P , and P ′′ 6= Q′′ since x1 6= y1. This againcontradicts minimality of P . Since xs = v = yt and x0 = u = y0, it now follows that

(x0, x1, . . . , xs, yt−1, yt−2, . . . , y1, y0)

is a cycle in G.

The following result gives a formula for the number of components in a forest.

3.64. Theorem: Components of a Forest. Let G be a forest with n vertices and kedges. The number of connected components of G is n− k.

Proof. We use induction on k. The result holds for k = 0, since G consists of n isolatedvertices in this case. Assume that k > 0 and the result is already known for forests with nvertices and k − 1 edges. Given a forest G with n vertices and k edges, remove one edge efrom G to get a new graph H . The graph H is acyclic and has n vertices and k − 1 edges.By induction, H has n − (k − 1) = n − k + 1 components. On the other hand, e mustbe a cut-edge since G has no cycles. It follows from Theorem 3.58 that H has one morecomponent than G. Thus, G has n− k components, as needed.

3.10 Trees

3.65. Definition: Trees. A tree is a connected graph with no cycles.

For example, Figure 3.12 displays a tree.

101

23 4

911

56

7

8

FIGURE 3.12A tree.

Page 100: Combinatorics - Routledge

124 Combinatorics, Second Edition

Every component of a forest is a tree, so every forest is a disjoint union of trees. Thenext result is an immediate consequence of the Two-Leaf Lemma 3.37.

3.66. Theorem: Trees Have Leaves. If T is a tree with more than one vertex, then Thas at least two leaves.

3.67. Definition: Pruning. Suppose G = (V,E) is a simple graph, v0 is a leaf in G, ande0 is the unique edge incident to the vertex v0. The graph obtained by pruning v0 from G isthe graph (V −{v0}, E−{e0}).

3.68. Pruning Lemma. If T is an n-vertex tree, v0 is a leaf of T , and T ′ is obtained fromT by pruning v0, then T

′ is a tree with n− 1 vertices.

Proof. First, T has no cycles, and the deletion of v0 and the associated edge e0 will notcreate any cycles. So T ′ is acyclic. Second, let u,w ∈ V (T ′). There is a path from u to win T . Since u 6= v0 6= w, this path will not use the edge e0 or the vertex v0. Thus there is apath from u to w in T ′, so T ′ is connected.

Figure 3.13 illustrates the Pruning Lemma.

delete to get G'

0

v 0

e

FIGURE 3.13Pruning a leaf from a tree produces another tree.

To give an application of pruning, we now prove a fundamental relationship between thenumber of vertices and edges in a tree (this also follows from Theorem 3.64).

3.69. Theorem: Number of Edges in a Tree. If G is a tree with n > 0 vertices, thenG has n− 1 edges.

Proof. We use induction on n. If n = 1, then G must have 0 edges. Fix n > 1, and assumethat the result holds for trees with n− 1 vertices. Let T be a tree with n vertices. We knowthat T has at least one leaf; let v0 be one such leaf. Let T ′ be the graph obtained by pruningv0 from T . By the Pruning Lemma, T ′ is a tree with n − 1 vertices. By induction, T ′ hasn− 2 edges. Hence, T has n− 1 edges.

3.70. Theorem: Characterizations of Trees. Let G be a graph with n vertices. Thefollowing conditions are logically equivalent:(a) G is a tree (i.e., G is connected and acyclic).(b) G is connected and has at most n− 1 edges.(c) G is acyclic and has at least n− 1 edges.(d) G has no loop edges, and for all u, v ∈ V (G), there is a unique path in G from u to v.

Moreover, when these conditions hold, G has exactly n− 1 edges.

Page 101: Combinatorics - Routledge

Counting Problems in Graph Theory 125

Proof. First, (a) implies (b) and (a) implies (c) by Theorem 3.69. Second, (a) is equivalentto (d) by Corollary 3.54 and Theorem 3.63. Third, we prove (b) implies (a). Assume G isconnected with k ≤ n− 1 edges. If G has a cycle, delete one edge on some cycle of G. Theresulting graph is still connected (by Theorem 3.58) and has k−1 edges. Continue to deleteedges in this way, one at a time, until there are no cycles. If we deleted i edges total, theresulting graph is a tree with k − i ≤ n− 1− i edges and n vertices. By Theorem 3.69, wemust have i = 0 and k = n − 1. So no edges were deleted, which means that the originalgraph G is in fact a tree.

Fourth, we prove (c) implies (a). Assume G is acyclic with k ≥ n− 1 edges. If G is notconnected, add an edge joining two distinct components of G. The resulting graph is stillacyclic (by Theorem 3.60) and has k + 1 edges. Continue to add edges in this way, one ata time, until the graph becomes connected. If we added i edges total, the resulting graphis a tree with k + i ≥ n− 1 + i edges and n vertices. By Theorem 3.69, we must have i = 0and k = n− 1. So no edges were added, which means that the original graph G is in fact atree.

3.11 Counting Trees

The next result, often attributed to Cayley, counts n-vertex trees.

3.71. The Tree Rule. For all n ≥ 1, there are nn−2 trees with vertex set {1, 2, . . . , n}.3.72. Example. Figure 3.14 displays all 44−2 = 16 trees with vertex set {1, 2, 3, 4}.

1

1

2

3

4

1

2

3

1

3

2

4

1

3

4

2

1

4

2

3

1

4

3

2

2

1

3

4

2

1

4

2

3

1

4

2

4

1

3

3

1

2

4

3

2

4

4

3

1

1

2

3 4

1

3 4

3

2

1 4

4

2

3

2

FIGURE 3.14The 16 trees with vertex set {1, 2, 3, 4}.

The Tree Rule 3.71 is an immediate consequence of the Rooted Tree Rule 3.47 and thefollowing bijection.

3.73. Theorem: Trees and Rooted Trees. Let V be a finite set and v0 ∈ V . There is abijection from the set A of trees with vertex set V to the set B of rooted trees with vertexset V and root v0.

Page 102: Combinatorics - Routledge

126 Combinatorics, Second Edition

Proof. We define maps f : A→ B and g : B → A that are two-sided inverses. First, givenT = (V,E) ∈ A, construct f(T ) = (V,E′) as follows. For each v ∈ V with v 6= v0, thereexists a unique path from v to v0 in T . Letting e = {v, w} be the first edge on this path,we add the directed edge (v, w) to E′. Also, we add the loop edge (v0, v0) to E′. Since Thas no cycles, the only possible cycle in the resulting functional digraph f(T ) is the 1-cycle(v0). It follows that f(T ) is a rooted tree on V with root v0 (see Definition 3.42).

Next, given a rooted tree S ∈ B, define g(S) by deleting the unique loop edge (v0, v0)and replacing every directed edge (v, w) by an undirected edge {v, w}. The resulting graphg(S) has n vertices and n− 1 edges. To see that g(S) is connected, fix y, z ∈ V . Followingoutgoing edges from y (respectively z) in S produces a directed path from y (respectivelyz) to v0 in S. In the undirected graph g(S), we can concatenate the path from y to v0 withthe reverse of the path from z to v0 to get a walk from y to z. It follows that g(S) is a tree.

It is routine to check that g ◦ f = idA, since f assigns a certain orientation to each edgeof the original tree, and this orientation is then forgotten by g. It is somewhat less routineto verify that f ◦ g = idB; we leave this as an exercise. The key point to be checked is thatthe edge orientations in f(g(S)) agree with the edge orientations in S, for each S ∈ B.

A different bijective proof of the Tree Rule, based on parking functions, is presented in§12.5. We next prove a refinement of the Tree Rule that counts the number of trees suchthat each vertex has a specified degree. We give an algebraic proof first, and then convertthis to a bijective proof in the next section.

3.74. Theorem: Counting Trees with Specified Degrees. Suppose n ≥ 2 andd1, . . . , dn ≥ 0 are fixed integers. If d1 + · · ·+ dn = 2n− 2, then there are

(n− 2

d1 − 1, d2 − 1, . . . , dn − 1

)=

(n− 2)!∏nj=1(dj − 1)!

trees with vertex set {v1, v2, . . . , vn} such that deg(vj) = dj for all j. If d1+· · ·+dn 6= 2n−2,then there are no such trees.

Proof. The last statement holds because any tree T on n vertices has n− 1 edges, and thus∑ni=1 deg(vi) = 2(n − 1). Assume henceforth that d1 + · · · + dn = 2n − 2. We prove the

result by induction on n. First consider the case n = 2. If d1 = d2 = 1, there is exactly onevalid tree, and

(n−2

d1−1,d2−1)= 1. For any other choice of d1, d2 adding to 2, there are no valid

trees, and(

n−2d1−1,d2−1

)= 0.

Now assume n > 2 and that the theorem is known to hold for trees with n− 1 vertices.Let A be the set of trees T with V (T ) = {v1, . . . , vn} and deg(vj) = dj for all j. If dj = 0 forsome j, then A is empty and the formula in the theorem is zero by convention. Now supposedj > 0 for all j. We must have di = 1 for some i, for otherwise d1 + · · ·+ dn ≥ 2n > 2n− 2.Fix an i with di = 1. Note that vi is a leaf in T for every T ∈ A. Now, for each k 6= ibetween 1 and n, define

Ak = {T ∈ A : {vi, vk} ∈ E(T )}.Ak is the set of trees in A in which the leaf vi is attached to the vertex vk. A is the disjointunion of the sets Ak.

Fix k 6= i. Pruning the leaf vi gives a bijection between Ak and the set Bk of alltrees with vertex set {v1, . . . , vi−1, vi+1, . . . , vn} such that deg(vj) = dj for j 6= i, k anddeg(vk) = dk − 1. By induction hypothesis,

|Bk| =(n− 3)!

(dk − 2)!∏

1≤j≤nj 6=i,k

(dj − 1)!.

Page 103: Combinatorics - Routledge

Counting Problems in Graph Theory 127

Therefore, by the Sum Rule and the Bijection Rule,

|A| =∑

k 6=i

|Ak| =∑

k 6=i

|Bk| =∑

k 6=i

(n− 3)!

(dk − 2)!∏

j 6=k,i(dj − 1)!

=∑

k 6=i

(n− 3)!(dk − 1)∏j 6=i(dj − 1)!

=∑

k 6=i

(n− 3)!(dk − 1)∏nj=1(dj − 1)!

(since (di − 1)! = 0! = 1)

=(n− 3)!∏n

j=1(dj − 1)!

k 6=i

(dk − 1).

Now, since di = 1,∑

k 6=i(dk − 1) =∑n

k=1(dk − 1) = (2n − 2) − n = n − 2. Inserting thisinto the previous formula, we see that

|A| = (n− 2)!∏nj=1(dj − 1)!

,

which completes the induction proof.

3.75. Corollary: Second Proof of the Tree Rule. Let us sum the previous formulaover all possible degree sequences (d1, . . . , dn). Making the change of variables ci = di − 1and invoking the Multinomial Theorem 2.11, we see that the total number of trees on thisvertex set is

d1+···+dn=2n−2di≥0

(n− 2

d1 − 1, d2 − 1, . . . , dn − 1

)=

c1+···+cn=n−2ci≥0

(n− 2

c1, c2, . . . , cn

)1c11c2 · · · 1cn

= (1 + 1 + · · ·+ 1)n−2 = nn−2.

3.12 Pruning Maps

We now develop a bijective proof of Theorem 3.74. Suppose n ≥ 2 and d1, . . . , dn arepositive integers that sum to 2n − 2. Let V = {v1, . . . , vn} be a vertex set consisting ofn positive integers v1 < v2 < · · · < vn. Let A be the set of trees T with vertex set Vsuch that deg(vi) = di for all i. Let B be the set of words R(vd1−1

1 vd2−12 · · · vdn−1

n ) (seeDefinition 1.32). Each word w ∈ B has length n − 2 and has dj − 1 copies of vj . To proveTheorem 3.74, it suffices to define a bijection f : A→ B.

Given a tree T ∈ A, we compute f(T ) by repeatedly pruning off the largest leaf of T ,recording for each leaf the vertex adjacent to it in T . More formally, for i ranging from1 to n − 1, let x be the largest leaf of T ; define wi to be the unique neighbor of x in T ;then modify T by pruning the leaf x. This process produces a word w1 · · ·wn−1; we definef(T ) = w1 · · ·wn−2 (note that wn−1 is discarded).

3.76. Example. Let T be the tree shown in Figure 3.15. To compute f(T ), we prune leavesfrom T in the following order: 8, 5, 4, 9, 6, 3, 2, 7. Recording the neighbors of these leaves, wesee that w = f(T ) = 9996727. Observe that the algorithm computes wn−1 = 1, but thisletter is not part of the output word w. Also observe that w ∈ R(102130405061728093) =R(1d1−1 · · · 9d9−1).

Page 104: Combinatorics - Routledge

128 Combinatorics, Second Edition

2

98 6

5

4

3 1

7

FIGURE 3.15A tree with (d1, . . . , d9) = (1, 2, 1, 1, 1, 2, 3, 1, 4).

The observations in the last example hold in general. Given any T ∈ A, repeatedlypruning leaves from T will produce a sequence of smaller graphs, which are all trees by thePruning Lemma 3.68. By Theorem 3.66, each such tree (except the last tree) has at leasttwo leaves, so vertex v1 will never be chosen for pruning. In particular, v1 is always the lastvertex left, so that wn−1 is always v1. Furthermore, if vj is any vertex different from v1,then the number of occurrences of vj in w1w2 · · ·wn−1 is exactly dj − 1. For, every timea pruning operation removes an edge touching vj , we set wi = vj for some i, except whenwe are removing the last remaining edge touching vj (which occurs when vj has becomethe largest leaf and is being pruned). The same reasoning shows that v1 (which never getspruned) appears d1 times in w1 · · ·wn−1. Since wn−1 = v1, every vertex vj occurs dj − 1times in the output word w1 · · ·wn−2.

To see that f is a bijection, we use induction on the number of vertices. The result holdswhen n = 2, since in this case, A consists of a single tree with two nodes, and B consistsof a single word (the empty word). Now suppose n > 2 and the maps f (defined for treeswith fewer than n vertices) are already known to be bijections. Given w = w1 · · ·wn−2 ∈ B,we will show there exists exactly one T ∈ A with f(T ) = w. If such T exists, the leaves ofT are precisely the vertices in V (T ) that do not appear in w. Thus, the first leaf that getspruned when computing f(T ) must be the largest element z of V (T )−{w1, . . . , wn−2}. Byinduction hypothesis, there exists exactly one tree T ′ on the vertex set V (T )−{z} (withthe appropriate vertex degrees) such that f(T ′) = w2 · · ·wn−2. This given, we will havef(T ) = w iff T is the tree obtained from T ′ by attaching a new leaf z as a neighbor ofvertex w1. One readily confirms that this graph is in A (i.e., the graph is a tree with thecorrect vertex degrees). This completes the induction proof. The proof also yields a recursivealgorithm for computing f−1(w). The key point is to use the letters not seen in w (and itssuffixes) to determine the identity of the leaf that was pruned at each stage.

3.77. Example. Given w = 6799297 and V = {1, 2, . . . , 9}, let us compute the tree f−1(w)with vertex set V . The leaves of this tree must be {1, 3, 4, 5, 8}, which are the elements of Vnot seen in w. Leaf 8 was pruned first and was adjacent to vertex 6. So now we must computethe tree f−1(799297) with vertex set V−{8}. Here, leaf 6 was pruned first and was adjacentto vertex 7. Continuing in this way, we deduce that the leaves were pruned in the order8, 6, 5, 4, 3, 2, 9, 7; and the neighbors of these leaves (reading from w) were 6, 7, 9, 9, 2, 9, 7, 1.Thus, f−1(w) is the tree shown in Figure 3.16.

Page 105: Combinatorics - Routledge

Counting Problems in Graph Theory 129

9

1

2

3

4

5

6

7

8

FIGURE 3.16The tree computed by applying f−1 to w = 6799297.

3.13 Bipartite Graphs

Suppose m people are applying for n jobs, and we want to assign each person to a job thathe or she is qualified to perform. We can model this situation with a graph in which thereare two kinds of vertices: a set A of m vertices representing the people, and a disjoint set Bof n vertices representing the jobs. For all a ∈ A and b ∈ B, {a, b} is an edge in the graph iffperson a is qualified to perform job b. All edges in the graph join a vertex in A to a vertexin B. Graphs of this special type arise frequently; they are called bipartite graphs.

3.78. Definition: Bipartite Graphs. A graph G is bipartite iff there exist two sets Aand B such that A∩B = ∅, A∪B = V (G), and every edge of G has one endpoint in A andone endpoint in B. In this case, the sets A and B are called partite sets for G.

3.79. Example. The graph in Figure 3.3 is a bipartite graph with partite sets A = {1, 2, 3}and B = {4, 5, 6}. This graph models the scenario where three people (labeled 1, 2, and3) are all qualified to perform three jobs (labeled 4, 5, and 6). The graph G1 in Figure 3.1is not bipartite due to the loop edge f at vertex 3. However, deleting this edge gives abipartite graph with partite sets A = {1, 3, 5} and B = {2, 4}. The tree in Figure 3.12 isbipartite with partite sets A = {1, 7, 8, 9} and B = {2, 3, 4, 5, 6, 10, 11}. These sets are alsopartite sets for the forest in Figure 3.11, but here we could use other partite sets such asA′ = {1, 5, 6, 9, 10} and B′ = {2, 3, 4, 7, 8, 11}. Thus, the partite sets of a bipartite graphare not unique in general.

The next theorem gives a simple criterion for deciding whether a graph is bipartite.

3.80. Theorem: Bipartite Graphs. A graph G is bipartite iff G has no cycle of oddlength iff G has no closed walk of odd length.

Proof. First assume G is a bipartite graph with partite sets A and B. Let(v0, e1, v1, e2, v2, . . . , es, vs) be any cycle in G; we must show that s is even. By switch-ing A and B if needed, we may assume v0 ∈ A. Since e1 is an edge from v0 to v1, we musthave v1 ∈ B. Since e2 is an edge from v1 to v2, we must have v2 ∈ A. It follows by inductionthat for 0 ≤ i ≤ s, vi ∈ A iff i is even, and vi ∈ B iff i is odd. Since vs = v0 is in A, we seethat s must be even, as needed.

Second, we prove that if G has no cycle of odd length, then G has no closed walkof odd length. Using proof by contrapositive, assume there exists a closed walk of oddlength in G; we prove there must exist a cycle of odd length in G. Choose a closed walk(v0, e1, v1, . . . , es, vs) of odd length with s as small as possible; we claim this walk must bea cycle. Otherwise, there would be an index i with 0 < i < s and v0 = vi = vs. If i is odd,

Page 106: Combinatorics - Routledge

130 Combinatorics, Second Edition

then (v0, e1, v1, . . . , ei, vi) is a closed walk of odd length i < s, contradicting minimalityof s. If i is even, then (vi, ei+1, vi+1, . . . , es, vs) is a closed walk of odd length s − i < s,contradicting minimality of s. Thus the original walk was already a cycle.

Third, we prove that if G has no closed walk of odd length, then G is bipartite. Webegin with the special case where G is connected. Fix a vertex v0 ∈ V (G). Let A be theset of v ∈ V (G) such that there is a walk of even length in G from v0 to v; let B be theset of w ∈ V (G) such that there is a walk of odd length in G from v0 to w. Since G isconnected, every vertex of G is reachable from v0, so V (G) = A ∪B. We claim A ∩B = ∅.For if v ∈ A ∩ B, there are walks W1 and W2 from v0 to v where W1 has even length andW2 has odd length. The concatenation of W1 with the reversal of W2 would give a closedwalk of odd length in G, contrary to our hypothesis on G. Next, we claim every edge of Gmust join a vertex in A to a vertex in B. For if {u, v} is an edge where u, v ∈ A, then weget a closed walk of odd length by taking an even-length walk from v0 to u, followed bythe edge {u, v}, followed by an even-length walk from v to v0. Similarly, we cannot have anedge {u, v} with u, v ∈ B. We have now proved G is bipartite with partite sets A and B.

To treat the general case, let G have components C1, . . . , Cm. Since G has no closedwalks of odd length, the same is true of each component. Thus, the argument in the lastparagraph applies to each component, providing disjoint sets Ai, Bi such that Ci = Ai ∪Bi

and every edge with endpoints in Ci goes from a vertex in Ai to a vertex in Bi. It followsthat A = A1 ∪ · · · ∪Am and B = B1 ∪ · · · ∪Bm are partite sets for G, so G is bipartite.

3.81. Example. The simple graph G2 in Figure 3.1 is not bipartite because (1, 2, 6, 1) is acycle in G2 of length 3.

3.14 Matchings and Vertex Covers

Consider again a job assignment graph where there is a set A of vertices representingpeople, a disjoint set B of vertices representing jobs, and an edge {a, b} whenever persona is qualified for job b. We can model an assignment of people to jobs by a subset M ofthe edge set in which no two edges in M have a common endpoint. This condition meansthat each person can perform at most one of the jobs, and each job can be filled by at mostone person. Ideally, we would like to choose M so that every person gets a job. If that isimpossible, we would like to choose M as large as possible. This discussion motivates thefollowing definition, which applies to any (not necessarily bipartite) graph.

3.82. Definition: Matchings. A matching of a graph G is a set M of edges of G suchthat no two edges in M share an endpoint. Let m(G) be the maximum number of edges inany matching of G.

3.83. Example. The graph G in Figure 3.10 has a matching

M = {{1, 2}, {3, 10}, {4, 8}, {9, 12}, {6, 13}, {5, 7}}

of size 6. There can be no larger matching, since the graph has only 13 vertices. Thus,m(G) = 6.

3.84. Example. Consider the path graph Pn with vertex set {1, 2, . . . , n} and edge set{{i, i+1} : 1 ≤ i < n}. Figure 3.17 shows the path graphs P5 and P6. We can write n = 2k orn = 2k+1 for some integer k ≥ 0. In either case, the setM = {{1, 2}, {3, 4}, {5, 6}, . . . , {2k−

Page 107: Combinatorics - Routledge

Counting Problems in Graph Theory 131

C

5

1 2 3 5

1 2 3 54 6

P6

1 2 3 4 5

1 2 3 4 5

5 6C

P

FIGURE 3.17Path graphs and cycle graphs.

1, 2k}} is a maximum matching of Pn, so m(Pn) = k = ⌊n/2⌋. Similarly, consider the cyclegraph Cn obtained from Pn by adding the edge {1, n}. The matching M is also a maximummatching of Cn, so m(Cn) = k = ⌊n/2⌋.

The next definition introduces a new optimization problem that is closely related to theproblem of finding a maximum matching in a graph.

3.85. Definition: Vertex Covers. A vertex cover of a graph G is a subset C of the vertexset of G such that every edge of G has at least one of its endpoints in C. Let vc(G) be theminimum number of vertices in any vertex cover of G.

3.86. Example. The graph G in Figure 3.10 has vertex cover C = {1, 4, 7, 8, 9, 10, 13}. Forn = 2k or n = 2k + 1, the path graph Pn has vertex cover D = {2, 4, 6, . . . , 2k} of sizek = ⌊n/2⌋. When n = 2k is even, D is also a vertex cover of the cycle graph Cn. Whenn = 2k + 1 is odd, D is not a vertex cover of Cn, but D ∪ {1} is.

In the previous example, some additional argument is needed to determine whetherwe have found vertex covers of the minimum possible size. Similarly, in most cases, it isnot immediately evident that a given matching of a graph has the maximum possible size.However, the next lemma shows that if we are able to build a matchingM of G and a vertexcover C of G having the same size, then M must be a maximum matching and C must bea minimum vertex cover, so that m(G) = |M | = |C| = vc(G).

3.87. Lemma: Matchings and Vertex Covers. Let G be a graph with matching Mand vertex cover C. (a) |M | ≤ |C|, and hence m(G) ≤ vc(G). (b) If |M | = |C|, thenm(G) = |M | = |C| = vc(G), and every vertex in C is an endpoint of some edge in M .

Proof. (a) We define a function f :M → C as follows. Given an edge e ∈M , let v, w be theendpoints of this edge. Since C is a vertex cover, at least one of v or w must belong to C. Letf(e) = v if v ∈ C, and f(e) = w otherwise. We claim f is one-to-one. For suppose e, e′ ∈Msatisfy f(e) = f(e′). Then e and e′ share a common endpoint f(e) = f(e′). Because M isa matching, this forces e = e′. So f is one-to-one, and hence |M | ≤ |C|. Taking M to bea maximum matching and C to be a minimum vertex cover in this result, we deduce thatm(G) ≤ vc(G).

(b) Suppose |M | = |C|. For any matchingM ′ ofG, part (a) shows that |M ′| ≤ |C| = |M |,so M is a maximum matching of G. For any vertex cover C′ of G, part (a) shows that|C′| ≥ |M | = |C|, so C is a minimum vertex cover of G. Thus, m(G) = |M | = |C| = vc(G)in this situation. Moreover, because |M | = |C|, the injective map f : M → C constructedin part (a) must be bijective by Theorem 1.77. Surjectivity of f means that for any vertexv ∈ C, there is an edge e ∈ M with f(e) = v. By definition of f , this means that each

Page 108: Combinatorics - Routledge

132 Combinatorics, Second Edition

vertex in the minimum vertex coverC is an endpoint of some edge in the maximummatchingM .

3.88. Example. For the path graph Pn, we found a matching M and a vertex cover C ofthe same size. By the lemma, M is a maximum matching, C is a minimum vertex cover,and m(Pn) = vc(Pn) = ⌊n/2⌋. Similarly, for n even, we have m(Cn) = vc(Cn) = n/2. But,it can be checked that the odd cycle C5 has m(C5) = 2 and vc(C5) = 3. So, for generalgraphs G, m(G) < vc(G) can occur. We prove in the next section that for a bipartite graphG, m(G) and vc(G) are always equal.

3.15 Two Matching Theorems

3.89. The Konig–Egervary Theorem. For all bipartite graphs G, m(G) = vc(G).

Proof. Let G have vertex set V and edge set E. We proceed by strong induction on |V |+|E|.Fix a bipartite graph G with N = |V | + |E|, and assume that for any bipartite graph G′

with |V (G′)|+ |E(G′)| < N , m(G′) = vc(G′). We will prove m(G) = vc(G) by consideringvarious cases. Case 1: G is isomorphic to a path graph Pn. The examples in the last sectionshow that m(G) = ⌊n/2⌋ = vc(G) in this case. Case 2: G is isomorphic to a cycle graphCn. Since bipartite graphs contain no odd cycles, n must be even, and we saw earlier thatm(G) = n/2 = vc(G) in this case.

Case 3: G is not simple. Now G has no loop edges (being bipartite), so there mustexist multiple edges between some pair of vertices in G. Let G′ be the bipartite graphobtained from G by deleting one of these multiple edges. By the induction hypothesis,m(G′) = vc(G′). On the other hand, we see from the definitions that m(G) = m(G′) andvc(G) = vc(G′), so m(G) = vc(G).

Case 4: G is not connected. Let K1, . . . , Km be the components of G. Form graphsG1, . . . , Gm by letting Gi have vertex set Ki and edge set consisting of all edges in E(G)with both endpoints in Ki. Since G is not connected, m > 1, so the induction hypothesisapplies to the smaller graphs G1, . . . , Gm (which are still bipartite). Let Mi be a maximummatching of Gi, and let Ci be a minimum vertex cover of Gi for each i; then |Mi| = m(Gi) =vc(Gi) = |Ci| for all i. One immediately verifies that M =

⋃mi=1Mi is a matching of G of

size∑m

i=1 |Mi|, and C =⋃m

i=1 Ci is a vertex cover of G of size∑m

i=1 |Ci|. Since |M | = |C|,the Lemma on Matchings and Vertex Covers assures us that m(G) = |M | = |C| = vc(G),as needed.

Case 5: G is simple and connected, but G is not isomorphic to a path Pn or a cycle Cn.It readily follows that there must exist a vertex u in G with deg(u) ≥ 3. Let v be a fixedvertex of G adjacent to u. Case 5a: Every maximum matching of G contains an edge withendpoint v. Let G′ be the graph obtained from G by deleting vertex v and all edges havingv as an endpoint. G′ is still bipartite, and the induction hypothesis applies to show thatm(G′) = vc(G′). Let C′ be a fixed minimum vertex cover ofG′. Then C = C′∪{v} is a vertexcover of G, so vc(G) ≤ |C| = |C′| + 1 = vc(G′) + 1 = m(G′) + 1. On the other hand, anymaximum matchingM ′ of G′ is also a matching of G, but it cannot be a maximum matchingof G by the assumption of Case 5a. So m(G′) < m(G), hence vc(G) ≤ m(G′) + 1 ≤ m(G).We already know m(G) ≤ vc(G), so m(G) = vc(G) follows.

Case 5b: There exists a maximum matchingM of G such that no edge ofM has endpointv. Recall deg(u) ≥ 3 and G is simple. Of the edges touching u, one leads to v, and at mostone other edge appears in the matching M . Thus there must exist an edge f 6∈M such thatu is an endpoint of f but v is not. Let G′ be the graph obtained from G by deleting the edge

Page 109: Combinatorics - Routledge

Counting Problems in Graph Theory 133

f . G′ is still bipartite, and the induction hypothesis applies to show that m(G′) = vc(G′).Because M did not use the edge f , M is a maximum matching of G′ as well as G, som(G) = m(G′). Let C′ be a minimum vertex cover of G′. It suffices to show C′ is also avertex cover of G, for then G will have a matching and a vertex cover of the same size. Everyedge of G except possibly f has an endpoint in C′. Also, since |M | = |C′|, the Lemma onMatchings and Vertex Covers (applied to the graph G′) tells us that every vertex in C′ isthe endpoint of some edge in M . By the assumption in Case 5b, this forces v 6∈ C′. But theedge from u to v is in G′, so u ∈ C′ by definition of a vertex cover. Since u is an endpointof the edge f , we see that C′ is a vertex cover of G, as needed.

The next theorem will use the following notation. Given a set S of vertices in a graphG, a vertex v is a neighbor of S iff there exists w ∈ S and an edge e in G with endpoints vand w. Let N(S) be the set of all neighbors of S. Given a matching M of G and a set A ofvertices of G, we say the matching saturates A iff every vertex in A is the endpoint of someedge in M .

3.90. Hall’s Matching Theorem. Let G be a bipartite graph with partite sets A and B.There exists a matching of G saturating A iff for all S ⊆ A, |S| ≤ |N(S)|.

Proof. First assume there is a matchingM of G saturating A. Fix S ⊆ A. Define a functionf : S → N(S) as follows. For each v ∈ S, there exists an edge e in M having v as oneendpoint (since M saturates A), and this edge is unique (since M is a matching). Let f(v)be the other endpoint of edge e, which lies in N(S). Now f is one-to-one: if f(v) = f(v′)for some v, v′ ∈ S, then the edge from v to f(v) and the edge from v′ to f(v′) = f(v) bothappear in M , forcing v = v′ because M is a matching. So |S| ≤ |N(S)|.

Conversely, assume |S| ≤ |N(S)| for all S ⊆ A. Let C be an arbitrary vertex coverof G. Let A1 = A ∩ C, A2 = A−C, and B1 = B ∩ C. Every edge with an endpoint inA2 must have its other endpoint in B1, since C is a vertex cover of G. This means thatN(A2) ⊆ B1. Taking S = A2 in the assumption, we see that |A2| ≤ |N(A2)| ≤ |B1|. Then|C| = |A1|+|B1| ≥ |A1|+|A2| = |A|. On the other hand, the set A is a vertex cover of G sinceG is bipartite with partite sets A and B. Since |A| ≤ |C| holds for every vertex cover C, wesee that A is a minimum vertex cover of G. By the previous theorem, m(G) = vc(G) = |A|.So there is a matchingM of G consisting of |A| edges. Each of these edges has one endpointin A, and these endpoints are distinct because M is a matching. Thus, M is a matchingthat saturates A.

3.16 Graph Coloring

This section introduces the graph coloring problem and some of its applications.

3.91. Definition: Colorings. Let G = (V,E) be a simple graph, and let C be a finite set.A coloring of G using colors in C is a function f : V → C. A coloring f of G is a propercoloring iff for every edge {u, v} ∈ E, f(u) 6= f(v).

Intuitively, we are coloring each vertex of G using one of the available colors in the setC. For each v ∈ V , f(v) is the color assigned to vertex v. A coloring is proper iff no twoadjacent vertices in G are assigned the same color.

3.92. Definition: Chromatic Functions and Chromatic Numbers. Let G be a simplegraph. For each positive integer x, let χG(x) be the number of proper colorings of G using

Page 110: Combinatorics - Routledge

134 Combinatorics, Second Edition

colors in {1, 2, . . . , x}. The function χG : Z>0 → Z≥0 is called the chromatic function of G.The minimal x such that χG(x) > 0 is called the chromatic number of G.

The chromatic number is the least number of colors required to obtain a proper coloringofG. The function χG is often called the chromatic polynomial of G because of Corollary 3.99below.

3.93. Example. Suppose G is a simple graph with n vertices and no edges. By the ProductRule, χG(x) = xn since we can assign any of the x colors to each vertex. The chromaticnumber for this graph is 1.

3.94. Example. At the other extreme, suppose G is a simple graph with n vertices suchthat there is an edge joining every pair of distinct vertices. Color the vertices one at a time.The first vertex can be colored in x ways. The second vertex must have a color differentfrom the first, so there are x−1 choices. In general, the ith vertex must have a color distinctfrom all of its predecessors, so there are x− (i− 1) choices for the color of this vertex. TheProduct Rule gives χG(x) = x(x− 1)(x− 2) · · · (x−n+1) = (x)↓n. The chromatic numberfor this graph is n. Recall from §2.15 that

(x)↓n=n∑

k=1

s(n, k)xk,

so that the function χG in this example is a polynomial whose coefficients are the signedStirling numbers of the first kind.

3.95. Example: Cycles. Consider the simple graph

G = ({1, 2, 3, 4}, {{1, 2}, {2, 3}, {3, 4}, {4, 1}}).

G consists of four vertices joined in a 4-cycle. We might attempt to compute χG(x) viathe Product Rule as follows. Color vertex 1 in x ways. Then color vertex 2 in x − 1 ways,and color vertex 3 in x− 1 ways. We run into trouble at vertex 4, because we do not knowwhether vertices 1 and 3 were assigned the same color. This example shows that we cannotalways compute χG by the Product Rule alone. In this instance, we can classify propercolorings based on whether vertices 1 and 3 receive the same or different colors. If theyreceive the same color, the number of proper colorings is x(x − 1)(x − 1) (color vertices 1and 3 together, then color vertex 2 a different color, then color vertex 4 a different colorfrom 1 and 3). If vertex 1 and 3 receive different colors, the number of proper colorings isx(x − 1)(x− 2)(x− 2) (color vertex 1, then vertex 3, then vertex 2, then vertex 4). Hence

χG(x) = x(x − 1)(x− 1) + x(x − 1)(x− 2)(x− 2) = x4 − 4x3 + 6x2 − 3x.

The chromatic number for this graph is 2.More generally, consider the cycle graph Cn consisting of n vertices joined in a cycle. It

is routine to establish that the chromatic number of Cn is 1 for n = 1, is 2 for all even n,and is 3 for all odd n > 1. On the other hand, it is not immediately evident how to computethe chromatic function for Cn when n > 4. We will deduce a recursion for these functionsshortly as a special case of a general recursion for computing chromatic functions.

Here is an application that can be analyzed using graph colorings and chromatic num-bers. Suppose we are trying to schedule meetings for a number of committees. If two com-mittees share a common member, they cannot meet at the same time. Consider the graphG whose vertices represent the various committees, and where there is an edge between twovertices iff the corresponding committees share a common member. Suppose there are x

Page 111: Combinatorics - Routledge

Counting Problems in Graph Theory 135

available time slots in which meetings may be scheduled. A coloring of G with x colors rep-resents a particular scheduling of committee meetings to time slots. The coloring is properiff the schedule creates no time conflicts for any committee member. The chromatic numberis the least number of time slots needed to avoid all conflicts, while χG(x) is the number ofdifferent conflict-free schedules using x (distinguishable) time slots.

3.96. Example. Six committees have members as specified in Table 3.1.

Committee MembersA Kemp, Oakley, SaundersB Gray, Saunders, RussellC Byrd, Oakley, QuinnD Byrd, Jenkins, KempE Adams, Jenkins, WilsonF Byrd, Gray, Russell

TABLE 3.1Committee assignments in Example 3.96.

Figure 3.18 displays the graph G associated to this set of committees. To compute χG(x),consider cases based on whether vertices A and F receive the same color. If A and F arecolored the same, the number of proper colorings is x(x − 1)(x − 2)(x − 1)(x − 1) [colorA and F, then C, D, B, and E]. If A and F receive different colors, the number of propercolorings is x(x − 1)(x− 2)(x− 3)(x− 2)(x− 1) [color A, F, C, D, B, E]. Thus,

χG(x) = x(x− 1)2(x − 2)(x− 1 + (x− 2)(x− 3)) = x6 − 8x5 + 26x4 − 42x3 + 33x2 − 10x.

The chromatic number of G is 3.

F

A

BC D

E

FIGURE 3.18Conflict graph for six committees.

We are about to present a general recursion that can be used to compute the chromaticfunction of a simple graph. The recursion makes use of the following construction.

3.97. Definition: Collapsing an Edge. Let G = (V,E) be a simple graph, and lete0 = {v0, w0} be a fixed edge of G. Let z0 be a new vertex. We define a simple graphH called the graph obtained from G by collapsing the edge e0. The vertex set of H is(V−{v0, w0}) ∪ {z0}. The edge set of H is

{{x, y} : x 6= v0 6= y and x 6= w0 6= y and {x, y} ∈ E}∪{{x, z0} : x 6= v0 and {x,w0} ∈ E}∪{{x, z0} : x 6= w0 and {x, v0} ∈ E}.

Page 112: Combinatorics - Routledge

136 Combinatorics, Second Edition

Pictorially, we construct H from G by shrinking the edge e0 until the vertices v0 and w0

coincide. We replace these two overlapping vertices with a single new vertex z0. All edgestouching v0 or w0 (except the collapsed edge e0) now touch z0 instead. See Figure 3.19.

graph after collapsing

0 w0 z0e0

e0

. . .. . .

. . .. . .

original graph

v

FIGURE 3.19Collapsing an edge in a simple graph.

3.98. Theorem: Chromatic Recursion. Let G = (V,E) be a simple graph. Fix anyedge e = {v, w} ∈ G. Let G′ = (V,E−{e}) be the simple graph obtained by deleting theedge e from G, and let G′′ be the simple graph obtained from G by collapsing the edge e.Then

χG(x) = χG′(x)− χG′′(x).

Proof. Fix x ∈ Z>0, and let A, B, and C denote the set of proper colorings of G, G′, andG′′ (respectively) using x available colors. Write B = B1 ∪B2, where B1 = {f ∈ B : f(v) =f(w)} and B2 = {f ∈ B : f(v) 6= f(w)}. Note that B1 consists of the proper colorings ofG′ (if any) in which vertices v and w are assigned the same color. Let z be the new vertexin G′′ that replaces v and w. Given a proper coloring f ∈ B1, we define a correspondingcoloring f ′′ of G′′ by setting f ′′(z) = f(v) = f(w) and f ′′(u) = f(u) for all u ∈ V differentfrom v and w. Since f is proper, it follows from the definition of the edge set of G′′ thatf ′′ is a proper coloring as well. Thus we have a map f 7→ f ′′ from B1 to C. This map isinvertible, since the color of z in a coloring of G′′ determines the common color of v and win a coloring of G′ belonging to B1. We conclude that |B1| = |C|.

On the other hand, B2 consists of the proper colorings of G′ in which vertices v and ware assigned different colors. These are precisely the proper colorings of G (since G has anedge between v and w, and G is otherwise identical to G′). Thus, B2 = A. It follows that

χG(x) = |A| = |B2| = |B| − |B1| = |B| − |C| = χG′(x)− χG′′(x).

3.99. Corollary: Polynomiality of Chromatic Functions. For any graph G, χG(x)is a polynomial in x with integer coefficients. (This justifies the terminology chromaticpolynomial.)

Proof. We use induction on the number of edges in G. If G has k vertices and no edges,the Product Rule gives χG(x) = xk, which is a polynomial in x. Now assume G has m > 0edges. Fix such an edge e, and define G′ and G′′ as in the preceding theorem. G′ has onefewer edge than G. When passing from G to G′′, we lose the edge e and possibly identifyother edges in G (e.g., if both endpoints of e are adjacent to a third vertex). In any case,G′′ has fewer edges than G. By induction on m, we may assume that both χG′(x) andχG′′(x) are polynomials in x with integer coefficients. So χG(x) = χG′(x) − χG′′(x) is alsoa polynomial with integer coefficients.

Page 113: Combinatorics - Routledge

Counting Problems in Graph Theory 137

G”

a

c d

f

h

bG'

delete e

collapse e

a

d

bf

ch

a

c z

bf

e

G

FIGURE 3.20Using the chromatic recursion.

3.100. Remark. We can use the chromatic recursion to compute χG recursively for anygraph G. The base case of the calculation is a graph with k vertices and no edges, whichhas chromatic polynomial xk. If G has more than one edge, G′ and G′′ both have strictlyfewer edges than G. Thus, the recursive calculation will terminate after finitely many steps.However, this is quite an inefficient method for computing χG if G has many vertices andedges. Thus, direct counting arguments using the Sum Rule and Product Rule may bepreferable to repeatedly applying the chromatic recursion.

3.101. Example. Consider the graph G shown on the left in Figure 3.20. We computeχG(x) by applying the chromatic recursion to the edge e = {d, h}. The graphs G′ and G′′

obtained by deleting and collapsing this edge are shown on the right in Figure 3.20. Directarguments using the Product Rule show that

χG′(x) = x(x− 1)(x− 2)(x− 2)(x− 1)(x− 1) (color a, c, d, f, b, h);

χG′′(x) = x(x − 1)(x− 2)(x− 2)(x− 2) (color z, a, c, f, b).

Therefore,

χG(x) = x(x − 1)(x− 2)2((x− 1)2 − (x− 2)) = x6 − 8x5 + 26x4 − 43x3 + 36x2 − 12x.

3.102. Chromatic Polynomials for Cycles. For each n ≥ 3, let Cn denote a graphconsisting of n vertices joined in a cycle. Let C1 denote a one-vertex graph, and let C2

denote a graph with two vertices joined by an edge. Finally, let χn(x) = χCn(x) be thechromatic polynomials for these graphs. We see directly that

χ1(x) = x, χ2(x) = x(x − 1) = x2 − x, χ3(x) = x(x− 1)(x− 2) = x3 − 3x2 + 2x.

Fix n > 3 and fix any edge e in Cn. Deleting this edge leaves a graph in which n vertices

Page 114: Combinatorics - Routledge

138 Combinatorics, Second Edition

are joined in a line; the chromatic polynomial of such a graph is x(x− 1)n−1. On the otherhand, collapsing the edge e in Cn produces a graph isomorphic to Cn−1. The chromaticrecursion therefore gives

χn(x) = x(x − 1)n−1 − χn−1(x).

Using this recursion to compute χn(x) for small n suggests the closed formula

χn(x) = (x− 1)n + (−1)n(x − 1) for all n ≥ 2.

One may now prove this formula for χn(x) by induction, using the chromatic recursion.

3.17 Spanning Trees

This section introduces the notion of a spanning tree for a graph. A recursion resemblingthe Chromatic Recursion 3.98 will allow us to count the spanning trees for a given graph.This will lead to a remarkable formula, called the Matrix-Tree Theorem, that expresses thenumber of spanning trees as a certain determinant.

3.103. Definition: Subgraphs. Let G = (V,E, ǫ) and H = (W,F, η) be graphs or di-graphs. H is a subgraph of G iff W ⊆ V , F ⊆ E, and η(f) = ǫ(f) for all f ∈ F . H is aninduced subgraph of G iff H is a subgraph such that F consists of all edges in E with bothendpoints in W .

3.104. Definition: Spanning Trees. Given a graph G = (V,E, ǫ), a spanning tree forG is a subgraph H with vertex set V such that H is a tree. Let τ(G) be the number ofspanning trees of G.

3.105. Example. Consider the graph G shown in Figure 3.21. This graph has 31 spanning

4d

a b

c

egf

h

G

30 2

1

FIGURE 3.21Graph used to illustrate spanning trees.

trees, which are specified by the following sets of edges:

{a, c, d, f}, {b, c, d, f}, {a, c, d, g}, {b, c, d, g}, {a, c, d, h}, {b, c, d, h},{c, d, e, f}, {c, d, e, g}, {c, d, e, h}, {a, c, e, f}, {a, d, e, f}, {b, c, e, f},{b, d, e, f}, {a, c, e, g}, {a, d, e, g}, {b, c, e, g}, {b, d, e, g}, {a, c, e, h},{a, d, e, h}, {b, c, e, h}, {b, d, e, h}, {a, c, f, h}, {a, d, f, h}, {b, c, f, h},{b, d, f, h}, {a, c, g, h}, {a, d, g, h}, {b, c, g, h}, {b, d, g, h}, {c, d, f, h},{c, d, g, h}.

We see that even a small graph can have many spanning trees. Thus we seek a systematicmethod for enumerating these trees.

Page 115: Combinatorics - Routledge

Counting Problems in Graph Theory 139

We are going to derive a recursion involving the quantities τ(G). For this purpose, weneed to adapt the ideas of deleting an edge and collapsing an edge (see Definition 3.97) fromsimple graphs to general graphs. Since loop edges are never involved in spanning trees, weonly consider graphs without loops. Suppose we are given a graph G = (V,E, ǫ) and a fixededge z ∈ E with endpoints u, v ∈ V . To delete z from G, we replace E by E′ = E−{z} andreplace ǫ by the restriction of ǫ to E′. To collapse the edge z, we act as follows: (i) delete zand any other edges linking u to v; (ii) replace V by (V−{u, v}) ∪ {w}, where w is a newvertex; (iii) for each edge y ∈ E that has exactly one endpoint in the set {u, v}, modify ǫ(y)by replacing this endpoint with the new vertex w.

3.106. Example. Let G be the graph shown in Figure 3.21. Figure 3.22 displays the graphsobtained from G by deleting edge f and collapsing edge f .

5

delete edge f: collapse edge f:

G0 G1

d

a b

c

eg

h

30 2

1 4d

a b

c3

1 4

e h

FIGURE 3.22Effect of deleting or collapsing an edge.

3.107. Theorem: Spanning Tree Recursion. Let G = (V,E, ǫ) be a graph, and letz ∈ E be a fixed edge. Let G0 be the graph obtained from G by deleting z. Let G1 be thegraph obtained from G by collapsing z. Then

τ(G) = τ(G0) + τ(G1).

The initial conditions are: τ(G) = 0 if G is not connected, and τ(G) = 1 if G is a tree withvertex set V .

Proof. For every graph K, let Sp(K) be the set of all spanning trees of K, so τ(K) =|Sp(K)|. Fix the graph G and the edge z. Let X be the set of trees in Sp(G) that do notuse the edge z, and let Y be the set of trees in Sp(G) that do use the edge z. Sp(G) isthe disjoint union of X and Y , so τ(G) = |X |+ |Y | by the Sum Rule. Now, it follows fromthe definition of edge deletion that the set X is precisely the set Sp(G0), so |X | = τ(G0).To complete the proof, we need to show that |Y | = τ(G1). It suffices to define a bijectionF : Y → Sp(G1).

Suppose T ∈ Y is a spanning tree of G that uses the edge z with endpoints u, v. DefineF (T ) to be the graph obtained from T by collapsing the edge z; this graph is a subgraphof G1. Let n be the number of vertices of G; then T is a connected graph with n− 1 edges,one of which is z. It is routine to check that F (T ) is still connected. Furthermore, since T isa tree, z is the only edge in T between u and v. It follows from the definition of collapsingthat F (T ) has exactly n − 2 edges. Since G1 has n − 1 vertices, it follows that F (T ) is aspanning tree of G1. We see also that the edge set of F (T ) is precisely the edge set of Twith z removed. So far, we have shown that F is a well-defined function mapping Y intoSp(G1).

Page 116: Combinatorics - Routledge

140 Combinatorics, Second Edition

d

2 G4G3

d

a b

c

eh

30 2

1 4 d

a b

c3

1 4

5

e a b

c3

1

6

G

FIGURE 3.23Auxiliary graphs used in the computation of τ(G).

Next we define a map H : Sp(G1) → Y that is the two-sided inverse of F . GivenU ∈ Sp(G1) with edge set E(U), let H(U) be the unique subgraph of G with vertex set Vand edge set E(U) ∪ {z}. We must check that H(U) does lie in the claimed codomain Y .First, H(U) is a subgraph of G with n− 1 edges, one of which is the edge z. Furthermore,it can be checked that H(U) is connected, since walks in U can be expanded using the edgez if needed to give walks in H(U). Therefore, H(U) is a spanning tree of G using z, andso H(U) ∈ Y . Since F removes z from the edge set while H adds it back, F and H aretwo-sided inverses of each other. Hence both are bijections, and the proof is complete.

3.108. Example. We use the graphs in Figures 3.21 and 3.22 to illustrate the proof ofthe spanning tree recursion, taking z = f . The graph G0 on the left of Figure 3.22 has 19spanning trees; they are precisely the trees listed in Example 3.105 that do not use the edgef . Applying F to each of the remaining 12 spanning trees on the list produces the followingsubgraphs of G1 (specified by their edge sets):

{a, c, d}, {b, c, d}, {c, d, e}, {a, c, e}, {a, d, e}, {b, c, e},{b, d, e}, {a, c, h}, {a, d, h}, {b, c, h}, {b, d, h}, {c, d, h}.

These are precisely the spanning trees of G1.Next, we illustrate the calculation of τ(G) using the recursion. We first delete and

collapse edge f , producing the graphs G0 and G1 shown in Figure 3.22. We know thatτ(G) = τ(G0)+ τ(G1). Deletion of edge g from G0 produces a new graph G2 (Figure 3.23),while collapsing g in G0 leads to another copy of G1. So far, we have τ(G) = 2τ(G1)+τ(G2).Continuing to work on G1, we see that deleting edge h leads to the graph G3 in Figure 3.23,whereas collapsing edge h leads to the graph G4 in that figure. On the other hand, deletingh from G2 leaves a disconnected graph (which can be discarded), while collapsing h fromG2 produces another copy of G3. Now we have τ(G) = 3τ(G3) + 2τ(G4). Deleting edge efrom G3 gives a graph that has two spanning trees (by inspection), while collapsing e in G3

leads to G4 again. So τ(G) = 3(2 + τ(G4)) + 2τ(G4) = 6 + 5τ(G4). Finally, deletion of dfrom G4 leaves a graph with two spanning trees, while collapsing d produces a graph withthree spanning trees. We conclude that τ(G4) = 5, so τ(G) = 6 + 25 = 31, in agreementwith the enumeration in Example 3.105.

Next we extend the preceding discussion to rooted spanning trees in digraphs.

3.109. Definition: Rooted Spanning Trees. Let G = (V,E, ǫ) be a digraph, and letv0 ∈ V . A spanning tree of G rooted at v0 is a rooted tree T with root v0 and vertex setV such that T (without the loop at v0) is a subgraph of G. Let τ(G, v0) be the number ofspanning trees of G rooted at v0.

Page 117: Combinatorics - Routledge

Counting Problems in Graph Theory 141

The notions of edge deletion and contraction extend to digraphs. This leads to thefollowing recursion for counting rooted spanning trees.

3.110. Theorem: Rooted Spanning Tree Recursion. Let v0 be a fixed vertex in adigraph G, and let z be a fixed edge leading into v0. Let G1 be the digraph obtained fromG by deleting z. Let G2 be the digraph obtained from G by collapsing z, and let the newcollapsed vertex in G2 be v′0. Then

τ(G, v0) = τ(G1, v0) + τ(G2, v′0).

Proof. We modify the proof of Theorem 3.107. As before, the two terms on the right sidecount rooted spanning trees of G that do not contain z or do contain z. One may checkthat if T is a rooted spanning tree using the edge z, then the graph obtained from T bycollapsing z is a rooted spanning tree of G2 rooted at v′0. Similarly, adding z to the edge setof a rooted spanning tree of G2 rooted at v′0 produces a rooted spanning tree of G rootedat v0.

3.111. Remark. Our results for counting undirected spanning trees are special cases ofthe corresponding results for rooted spanning trees. Starting with any graph G = (V,E, ǫ),we consider the associated digraph obtained by replacing each e ∈ E by two directed edgesgoing in opposite directions. As in the proof of Theorem 3.73, there is a bijection betweenthe set of rooted spanning trees of this digraph rooted at any given vertex v0 ∈ V and theset of spanning trees of G. In what follows, we shall only treat the case of digraphs.

3.18 The Matrix-Tree Theorem

There is a remarkable determinant formula for the number of rooted spanning trees of adigraph. The formula uses the following modified version of the adjacency matrix of thedigraph.

3.112. Definition: Laplacian Matrix of a Digraph. Let G be a loopless digraph onthe vertex set V = {v0, v1, . . . , vn}. The Laplacian matrix of G is the matrix L = (Lij : 0 ≤i, j ≤ n) such that Lii = outdeg(vi) and Lij is the negative of the number of edges from vito vj in G. We let L0 be the n × n matrix obtained by erasing the row and column of Lcorresponding to v0. The matrix L0 = L0(G) is called the truncated Laplacian matrix of G(relative to v0).

3.113. The Matrix-Tree Theorem. With the notation of the preceding definition, wehave

τ(G, v0) = det(L0(G)).

We prove the theorem after considering two examples.

3.114. Example. Let G be the digraph associated to the undirected graph in Figure 3.21.In this case, Lii is the degree of vertex i in the undirected graph, and Lij is the negative ofthe number of undirected edges between i and j. So

L =

4 0 −2 −1 −10 3 0 −2 −1−2 0 3 0 −1−1 −2 0 3 0−1 −1 −1 0 3

.

Page 118: Combinatorics - Routledge

142 Combinatorics, Second Edition

n

23

1

4

a

c

d

fg jh

k

m

0 5b

p

q

e

FIGURE 3.24Digraph used to illustrate the Matrix-Tree Theorem.

Erasing the row and column corresponding to vertex 0 leaves

L0 =

3 0 −2 −10 3 0 −1−2 0 3 0−1 −1 0 3

.

We compute det(L0) = 31, which agrees with our earlier calculation of τ(G).

3.115. Example. Consider the digraph G shown in Figure 3.24. We compute

L =

4 0 −1 0 −2 −1−1 2 0 −1 0 0−1 0 2 0 −1 0−1 0 0 1 0 0−1 0 0 −3 4 00 0 −1 0 0 1

, L0 =

2 0 −1 0 00 2 0 −1 00 0 1 0 00 0 −3 4 00 −1 0 0 1

,

and det(L0) = 16. So G has 16 spanning trees rooted at 0, as can be confirmed by directenumeration. We use the matrix L0 as a running example in the proof below.

3.116. Proof of the Matrix-Tree Theorem. Write L0 = L0(G). First we prove thatτ(G, v0) = det(L0) in the case where indeg(v0) = 0. If v0 is the only vertex of G, thenτ(G, v0) = 1 and det(L0) = 1 by the convention that the determinant of a 0× 0 matrix is 1.Otherwise, τ(G, v0) is zero, and L0 is a nonempty matrix. Using the condition indeg(v0) = 0and the definition of L0, we see that every row of L0 sums to zero. Therefore, letting u bea column vector of n ones, we have L0u = 0, so that L0 is singular and det(L0) = 0.

For the general case, we use induction on the number of edges in G. The case where Ghas no edges is covered by the previous paragraph. The only case left to consider occurswhen indeg(v0) > 0. Let e be a fixed edge in G that leads from some vi to v0. Let G1 bethe graph obtained from G by deleting e, and let G2 be the graph obtained from G bycollapsing e. Both graphs have fewer edges than G, so the induction hypothesis tells us that

τ(G1, v0) = det(L0(G1)) and τ(G2, v′0) = det(L0(G2)), (3.4)

where v′0 is the new vertex created after collapsing e. Using Theorem 3.110, we concludethat

τ(G, v0) = det(L0(G1)) + det(L0(G2)). (3.5)

Page 119: Combinatorics - Routledge

Counting Problems in Graph Theory 143

Next, we evaluate the determinant det(L0(G)). We use the fact that the determinant ofa matrix is a linear function of each row of the matrix. More precisely, for a fixed matrix Aand row index i, let A[y] denote the matrix A with the ith row replaced by the row vector y;then det(A[y+ z]) = det(A[y])+det(A[z]) for all y, z. This linearity property can be proveddirectly from the definition of the determinant (see Definition 12.40 and Theorem 12.48 fordetails). To apply this result, write the ith row of L0 = L0(G) in the form y + z, wherez = (0, 0, . . . , 1, 0, . . . , 0) has a 1 in position i. Then

det(L0(G)) = det(L0[y]) + det(L0[z]). (3.6)

For example, if G is the digraph in Figure 3.24 and e is the edge from 2 to 0 (so i = 2),then y = (0, 1, 0,−1, 0), z = (0, 1, 0, 0, 0),

L0[y] =

2 0 −1 0 00 1 0 −1 00 0 1 0 00 0 −3 4 00 −1 0 0 1

, L0[z] =

2 0 −1 0 00 1 0 0 00 0 1 0 00 0 −3 4 00 −1 0 0 1

.

Comparing equations (3.5) and (3.6), we see that it suffices to prove det(L0(G1)) =det(L0[y]) and det(L0(G2)) = det(L0[z]).

How does the removal of e from G affect L(G)? Answer: The i, i-entry drops by 1, whilethe i, 0-entry increases by 1. Since the zeroth column is ignored in the truncated Laplacian,we see that we can obtain L0(G1) from L0(G) by decrementing the i, i-entry by 1. In otherwords, L0(G1) = L0[y], and hence det(L0(G1)) = det(L0[y]).

Next, let us calculate det(L0[z]) by expanding the determinant along row i. The onlynonzero entry in this row is the 1 in the diagonal position, so det(L0[z]) = (−1)i+i det(M) =det(M), where M is the matrix obtained from L0[z] (or equivalently, from L0) by erasingrow i and column i. In our running example,

M =

2 −1 0 00 1 0 00 −3 4 00 0 0 1

.

We claim that M = L0(G2), which will complete the proof. Consider the k, j-entry ofM , where k, j ∈ {0, 1, . . . , n}−{0, i}. If k = j, this entry is outdegG(vj), which equalsoutdegG2

(vj) because vj is not v0, vi, or v′0. For the same reason, if k 6= j, the k, j-entry of

M is the negative of the number of edges from vk to vj , which is the same in G and G2.

3.19 Eulerian Tours

3.117. Definition: Eulerian Tours. Let G = (V,E, ǫ) be a digraph. An Eulerian tour inG is a walk W = (v0, e1, v1, e2, v2, . . . , en, vn) such that W visits every vertex in V , and Wuses every edge in E exactly once. Such a tour is called closed iff vn = v0.

3.118. Example. For the digraph G shown in Figure 3.25, one closed Eulerian tour of Gis

W1 = (0,m, 2, l, 5, e, 1, a, 3, c, 4, b, 3, d, 5, f, 4, g, 5, k, 0, i, 4, h, 5, j, 0).

Page 120: Combinatorics - Routledge

144 Combinatorics, Second Edition

To specify the tour, it suffices to list only the edges in the tour. For instance, here is theedge sequence of another closed Eulerian tour of G:

W2 = (i, g, e, a, d, f, b, c, h, j,m, l, k).

3.119. Example. The digraph G shown in Figure 3.2 does not have any closed Euleriantours, since there is no way to reach vertex 6 from the other vertices. Even if we deletevertex 6 from the graph, there are still no closed Eulerian tours. The reason is that no tourcan use both edges leaving vertex 2, since only one edge enters vertex 2.

The previous example indicates two necessary conditions for a digraph to have a closedEulerian tour: the digraph must be connected, and also balanced in the sense that indeg(v) =outdeg(v) for every vertex v. We now show that these necessary conditions are also sufficientto guarantee the existence of a closed Eulerian tour.

3.120. Theorem: Existence of Closed Eulerian Tours. A digraph G = (V,E, ǫ) hasa closed Eulerian tour iff G is connected and balanced.

Proof. First suppose G has a closed Eulerian tour W starting at v0. Since W visits everyvertex, we can obtain a walk from any vertex to any other vertex by following certain edgesof W . So G is connected. Next, let v be any vertex of G. The walk W arrives at v via anincoming edge exactly as often as the walk leaves v via an outgoing edge; this is true evenif v = v0. Since the walk uses every edge exactly once, it follows that indeg(v) = outdeg(v).

Conversely, assume that G is connected and balanced. Let W = (v0, e1, v1, . . . , en, vn)be a walk of maximum length in G that never repeats an edge. We claim that vn = v0.Otherwise, the walk W would enter vertex vn one more time than it leaves vn. Sinceindeg(vn) = outdeg(vn), there must be an outgoing edge from vn that has not beenused by W . So we could use this edge to extend W , contradicting maximality of W .Next, we claim that W uses every edge of G. If not, let e be an edge not used by W .Since G is connected, we can find such an edge that is incident to one of the verticesvi visited by W . Since vn = v0, we can cyclically shift the walk W to get a new walkW ′ = (vi, ei+1, vi+1, . . . , en, vn = v0, e1, . . . , ei, vi) that starts and ends at vi. By adding theedge e to the beginning or end of this walk (depending on its direction), we could againproduce a longer walk than W with no repeated edges, violating maximality. Finally, Wmust visit every vertex of G, since W uses every edge of G and (unless G has one vertexand no edges) every vertex has an edge leaving it.

Our goal in the rest of this section is to count the number of closed Eulerian tours in G

2

3

1

4

a

0b

c

dfg

i

j

h

le

km

5

FIGURE 3.25Digraph used to illustrate Eulerian tours.

Page 121: Combinatorics - Routledge

Counting Problems in Graph Theory 145

2

1 T2

3

1

4 0

ad

h

l 25

j

3

1

4

a

0

h

c

k

l5

T

FIGURE 3.26Rooted spanning trees associated to Eulerian tours.

starting at a given vertex v0. Recall that τ(G, v0) is the number of rooted spanning trees ofG rooted at v0.

3.121. The Eulerian Tour Rule. Let G = (V,E, ǫ) be a connected, balanced digraph.For each v0 ∈ V , the number of closed Eulerian tours of G starting at v0 is

τ(G, v0) · outdeg(v0)! ·∏

v 6=v0

(outdeg(v) − 1)!. (3.7)

Let {v0, v1, . . . , vn} be the vertex set of G. Let X be the set of all closed Eulerian toursof G starting at v0. Let SpTr(G, v0) be the set of spanning trees of G rooted at v0. Let Ybe the set of all tuples (T,w0, w1, w2, . . . , wn) satisfying these conditions: T ∈ SpTr(G, v0);w0 is a permutation of all the edges leaving v0; and, for 1 ≤ i ≤ n, wi is a permutationof those edges leaving vi other than the unique outgoing edge from vi that belongs to T(see Definition 3.42). By the Product Rule, the cardinality of Y is given by the right sideof (3.7). So it suffices to define a bijection f : X → Y .

Given an Eulerian tour W ∈ X , define f(W ) = (T,w0, . . . , wn) as follows. For each ibetween 0 and n, let w′i be the permutation of all edges leading out of vi, taken in theorder in which they occur in the walk W . Call w′i the departure word of vertex vi. Next, setw0 = w′0 and for i > 0, let wi be the word w′i with the last symbol erased. Finally, let T bethe subgraph of G whose edges are given by the last symbols of w′1, . . . , w

′n, augmented by

a loop edge at v0. It is not immediately evident that T ∈ SpTr(G, v0); we prove this shortly.Next we define a map g : Y → X that is the two-sided inverse of f . Fix (T,w0, . . . , wn) ∈

Y . For every i > 0, form w′i by appending the unique edge of T leaving vi to the end of theword wi; let w

′0 = w0. Starting at v0, we use the words w′i to build a walk through G, one

edge at a time, as follows. If we are currently at some vertex vi, use the next unread symbolin w′i to determine which edge to follow out of vi. Repeat this process until the walk reachesa vertex in which all the outgoing edges have already been used. The resulting walk W isg(T,w0, . . . , wn). The edges occurring in W are pairwise distinct, but it is not immediatelyevident that W must use all edges of G; we prove this shortly.

Once we check that f and g map into their stated codomains, the definitions just givenshow that f ◦ g and g ◦ f are both identity maps. Before proving that f maps into Y and gmaps into X , we consider an example.

3.122. Example. We continue the analysis of Eulerian tours in the digraph G from Ex-ample 3.118. The walk W1 in that example has departure words w′0 = mi, w′1 = a, w′2 = l,

Page 122: Combinatorics - Routledge

146 Combinatorics, Second Edition

w′3 = cd, w′4 = bgh, and w′5 = efkj. Therefore,

f(W1) = (T1,mi, ·, ·, c, bg, efk),

where · denotes an empty word and T1 is the graph shown on the left in Figure 3.26.Similarly, for W2 we compute w′0 = im, w′1 = a, w′2 = l, w′3 = dc, w′4 = gbh, w′5 = efjk,and

f(W2) = (T2, im, ·, ·, d, gb, efj).We now calculate g(T1, im, ·, ·, c, bg, fke). First, we use the edges of T1 to recreate thedeparture words w′0 = im, w′1 = a, w′2 = l, w′3 = cd, w′4 = bgh, and w′5 = fkej. We thenuse these words to guide our tour through the graph. We begin with 0, i, 4, since i is thefirst letter of w′0. Consulting w

′4 next, we follow edge b to vertex 3, then edge c to vertex 4,

then edge g to vertex 5, and so on. We obtain the tour

W3 = (0, i, 4, b, 3, c, 4, g, 5, f, 4, h, 5, k, 0,m, 2, l, 5, e, 1, a, 3, d, 5, j, 0).

Similarly, we compute

g(T2,mi, ·, ·, d, bg, jfe) = (m, l, j, i, b, d, f, g, e, a, c, h, k).

To complete the proof of Rule 3.121, we must prove two things. First, to show thatf(W ) ∈ Y for all W ∈ X , we must show that the digraph T obtained from the last lettersof the departure words w′i (for i > 0) is a rooted spanning tree of G rooted at v0. Since Wvisits every vertex of G, the definition of T shows that outdegT (vi) = 1 for all i ≥ 0. Weneed only show that T has no cycles other than the loop at v0 (see Definition 3.42). We canview the tour W as a certain permutation of all the edges in G. Let us show that if e, h aretwo non-loop edges in T with ǫ(e) = (x, y) and ǫ(h) = (y, z), then e must precede h in thepermutation W . Note that y cannot be v0, since the only outgoing edge from v0 in T is aloop edge. Thus, when the tour W uses the edge e to enter y, the following edge in the tourexists and is an outgoing edge from y. Since h is, by definition, the last such edge used bythe tour, e must precede h in the tour. Now suppose (z0, e1, z1, . . . , en, zn) is a cycle in Tthat is not the 1-cycle at v0. Using the previous remark repeatedly, we see that ei precedesei+1 in W for all i, and also en precedes e1 in W . These statements imply that e1 precedesitself in W , which is impossible. We conclude that f(W ) ∈ Y .

Second, we must show that g maps Y into X . Fix (T,w0, . . . , wn) ∈ Y and W =g(T,w0, . . . , wn), and let w′i be the departure word constructed from T and wi. We knowfrom the definition of g that W is a walk in G starting at v0 that never repeats an edge.We must show that W ends at v0 and uses every edge in G. Suppose, at some stage in theconstruction of W , that W has just reached vi for some i > 0. Then W has entered vi onemore time than it has left vi. Since G is balanced, there must exist an unused outgoing edgefrom vi. This edge corresponds to an unused letter in w′i. So W does not end at vi. Theonly possibility is that W ends at the starting vertex v0.

To prove that W uses every edge of G, we claim that it is enough to prove that W usesevery non-loop edge of T . To establish the claim, consider a vertex v 6= v0 of G. If W usesthe unique outgoing edge from v that is part of T , then W must have previously used allother outgoing edges from v, by definition of W . Since W ends at v0, W certainly uses alloutgoing edges from v0. All edges are accounted for in this way, proving the claim.

Finally, to get a contradiction, assume that some edge e in T from x to y is not usedby W . Since T is a rooted tree rooted at v0, we can choose such an e so that the distancefrom y to v0 through edges in T is minimal. If y 6= v0, minimality implies that the uniqueedge leading out of y in T does belong to W . Then, as noted in the last paragraph, everyoutgoing edge from y in G is used in W . Since G is balanced, every incoming edge into y in

Page 123: Combinatorics - Routledge

Counting Problems in Graph Theory 147

G must also appear in W , contradicting the assumption that e is not used by W . On theother hand, if y = v0, we see similarly that W uses every outgoing edge from y in G andhence every incoming edge to y in G. Again, this contradicts the assumption that e is notin W . This completes the proof of the Eulerian Tour Rule.

Summary

Table 3.2 contains brief definitions of the terminology from graph theory used in this chapter.

• Facts about Matrix Multiplication. If A1, . . . , As are matrices such that At is nt−1 × nt,then the i, j-entry of the product A1A2 · · ·As is

n1∑

k1=1

n2∑

k2=1

· · ·ns−1∑

ks−1=1

A1(i, k1)A2(k1, k2)A3(k2, k3) · · ·As(ks−1, j).

If As = 0 (i.e., A is nilpotent), then I −A is invertible, and

(I −A)−1 = I +A+A2 +A3 + · · ·+As−1.

This formula applies (with s = n) when A is a strictly upper or lower triangular n× nmatrix.

• Adjacency Matrices and the Walk Rule. Given a graph or digraph G with vertex set{v1, . . . , vn}, the adjacency matrix of G is the matrix A such that A(i, j) is the numberof edges from vi to vj in G. For all s ≥ 0, As(i, j) is the number of walks in G of lengths from vi to vj . G is a DAG iff An = 0, in which case A will be strictly lower-triangularunder an appropriate ordering of the vertices. When G is a DAG, (I −A)−1(i, j) is thetotal number of paths (or walks) from vi to vj .

• Degree Sum Formulas. For a graph G = (V,E, ǫ),∑

v∈V degG(v) = 2|E|. For a digraphG = (V,E, ǫ),

∑v∈V indegG(v) = |E| =

∑v∈V outdegG(v).

• Functional Digraphs. For a finite set X , every function f : X → X has an associatedfunctional digraph with vertex set X and edge set {(x, f(x)) : x ∈ X}. Every functionaldigraph decomposes uniquely into one or more disjoint cycles together with disjointrooted trees rooted at the vertices on these cycles. For each vertex x0 in a functionaldigraph, there exist unique walks of each length k starting at x0, which are foundby repeatedly following the unique outgoing edge from the current vertex. Such walkseventually reach a cycle in the functional digraph.

• Cycle Structure of Permutations. For a finite set X , a map f : X → X is a bijection iffthe functional digraph of f is a disjoint union of directed cycles. The signless Stirlingnumber of the first kind, s′(n, k), counts the number of bijections f on an n-element setsuch that the functional digraph of f has k cycles. We have

s′(n, k) = s′(n− 1, k − 1) + (n− 1)s′(n− 1, k) for 0 < k < n.

• Connectedness and Components. The vertex set of any graph or digraph G is the dis-joint union of connected components. Two vertices belong to the same component iffeach vertex is reachable from the other by a walk. G is connected iff there is only one

Page 124: Combinatorics - Routledge

148 Combinatorics, Second Edition

TABLE 3.2Terminology used in graph theory.

Term Brief Definitiongraph (V,E, ǫ) where ǫ(e) = {v, w} means edge e has endpoints v, wdigraph (V,E, ǫ) where ǫ(e) = (v, w) means edge e goes from v to wsimple graph graph with no loops or multiple edgessimple digraph digraph with no multiple edgesG ∼= H G becomes H under some renaming of vertices and edgeswalk (v0, e1, v1, . . . , es, vs) where each ei is an edge from vi−1 to viclosed walk walk starts and ends at same vertexpath walk visiting distinct verticescycle closed walk visiting distinct vertices and edges, except at endDAG digraph with no cyclesindegG(v) number of edges leading to v in digraph GoutdegG(v) number of edges leading from v in digraph GdegG(v) number of edges incident to v in graph G (loops count as 2)isolated vertex vertex of degree zeroleaf vertex of degree onefunctional digraph simple digraph with outdeg(v) = 1 for all vertices vcyclic vertex vertex in functional digraph that belongs to a cyclerooted tree functional digraph with a unique cyclic vertex (the root)G is connected for all u, v ∈ V (G), there is a walk in G from u to vcut-edge of G edge belonging to no cycle of the graph Gforest graph with no cyclesacyclic graph graph with no cyclestree connected graph with no cyclesbipartite graph all edges in graph go from A ⊆ V (G) to B ⊆ V (G) with

A ∩B = ∅matching of G set M of edges in G where no two edges in M share an endpointm(G) size of a maximum matching of Gvertex cover of G set C of vertices where every edge of G has an endpoint in Cvc(G) size of a minimum vertex cover of GN(S) set of vertices reachable from vertices in S by following one edgeproper coloring map f : V (G)→ C assigning unequal colors to adjacent verticesχG(x) number of proper colorings of G using x available colorschromatic number least x with χG(x) > 0subgraph of G graph G′ with V (G′) ⊆ V (G), E(G′) ⊆ E(G) (same endpoints)induced subgraph subgraph G′ where all edges in G with ends in V (G′) are keptspanning tree of G subgraph of G that is a tree using all verticesτ(G) number of spanning trees of Grooted spanning tree rooted tree using all vertices of a digraphτ(G, v0) number of rooted spanning trees of G with root v0Eulerian tour walk visiting each vertex that uses every edge once

Page 125: Combinatorics - Routledge

Counting Problems in Graph Theory 149

component iff for all u, v ∈ V (G) there exists at least one path from u to v in G. Deletinga cut-edge splits a component of G in two, whereas deleting a non-cut-edge has no effecton components.

• Forests. A graph G is a forest (acyclic) iff G has no loops and for each u, v ∈ V (G),there is at most one path from u to v. A forest with n vertices and k edges has n − kcomponents.

• Trees. The following conditions on an n-vertex simple graph G are equivalent and char-acterize trees: (a) G is connected with no cycles; (b) G is connected with at most n− 1edges; (c) G is acyclic with at least n − 1 edges; (d) for all u, v ∈ V (G), there exists aunique path in G from u to v. An n-vertex tree has n− 1 edges and (for n > 1) at leasttwo leaves. Pruning any leaf from a tree produces another tree with one less vertex andone less edge.

• Tree Counting Rules. There are nn−2 trees with vertex set {1, 2, . . . , n}. There are nn−2

rooted trees on this vertex set rooted at 1. For d1 + · · · + dn = 2(n − 1), there are(n−2

d1−1,...,dn−1)trees on this vertex set with deg(j) = dj for all j. Bijective proofs of these

facts use the following ideas:

– Functions on {1, 2, . . . , n} fixing 1 and n correspond to rooted trees by arrangingthe cycles of the functional digraph in a certain order, breaking back edges, andlinking the cycles to get a tree (see Figures 3.7 and 3.8).

– Trees correspond to rooted trees by directing each edge of the tree toward the rootvertex.

– Trees with deg(j) = dj correspond to words in R(1d1−1 · · ·ndn−1) by repeatedlypruning the largest leaf and appending the leaf’s neighbor to the end of the word.

• Matchings and Vertex Covers. For any matching M and vertex cover C of a graph G,|M | ≤ |C|. If equality holds, then M must be a maximum matching of G and C mustbe a minimum vertex cover of G. We have m(G) ≤ vc(G) for all graphs G, but equalitydoes not always hold.

• Bipartite Graphs. A graph G is bipartite iff G has no cycles of odd length. For bipartitegraphs G, m(G) = vc(G). If G has partite sets A and B, there exists a matching of Gsaturating A iff for all S ⊆ A, |S| ≤ |N(S)|.

• Chromatic Polynomials. For any edge e in a simple graph G, the chromatic functionof G satisfies the recursion χG = χG−{e} − χGe , where G−{e} is G with e deleted,and Ge is G with e collapsed. It follows that χG(x) is a polynomial function of x. Thesigned Stirling numbers of the first kind, s(n, k), are the coefficients in the chromaticpolynomial for an n-vertex graph with an edge between each pair of vertices.

• Recursion for Spanning Trees. For any edge e in a graphG, the number τ(G) of spanningtrees of G satisfies the recursion τ(G) = τ(G−{e}) + τ(Ge), where G−{e} is G withe deleted, and Ge is G with e collapsed. A similar recursion holds for rooted spanningtrees of a digraph.

• The Matrix-Tree Theorem. Given a digraph G and v0 ∈ V (G), let Lii = outdegG(vi),let −Lij be the number of edges from i to j in G, and let L0 be the matrix obtainedfrom [Lij ] by erasing the row and column indexed by v0. Then det(L0) is τ(G, v0), thenumber of rooted spanning trees of G with root v0.

Page 126: Combinatorics - Routledge

150 Combinatorics, Second Edition

• Eulerian Tours. A digraph G has a closed Eulerian tour iff G is connected and balanced(indegree equals outdegree at every vertex). In this case, the number of such toursstarting at v0 is

τ(G, v0) · outdegG(v0)! ·∏

v 6=v0

(outdegG(v)− 1)!.

The proof associates to each tour a rooted spanning tree built from the last departureedge from each vertex, together with (truncated) departure words for each vertex givingthe order in which the tour used the other outgoing edges.

Exercises

3-1. Draw pictures of the following simple graphs.(a) C = ({1, 2, 3, 4}, {{1, 2}, {1, 3}, {1, 4}}) (the claw graph)(b) P = ({1, 2, 3, 4}, {{1, 2}, {1, 3}, {1, 4}, {2, 3}}) (the paw graph)(c) K = ({1, 2, 3, 4}, {{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}}) (the kite graph)(d) B = ({1, 2, 3, 4, 5}, {{1, 2}, {2, 3}, {1, 3}, {1, 4}, {2, 5}}) (the bull graph)(e) Kn = ({1, 2, . . . , n}, {{i, j} : 1 ≤ i < j ≤ n}) (the complete graph on n vertices)

3-2. Let V be an n-element set. (a) How many simple graphs have vertex set V ? (b) Howmany simple digraphs have vertex set V ?

3-3. Let V and E be sets with |V | = n and |E| = m. (a) How many digraphs have vertexset V and edge set E? (b) How many graphs have vertex set V and edge set E?

3-4. Let V be an n-element set. Define a bijection between the set of simple graphs withvertex set V and the set of symmetric, irreflexive binary relations on V . Conclude thatsimple graphs can be viewed as certain kinds of simple digraphs.

3-5. Let G, H , and K be graphs. (a) Prove G ∼= G. (b) Prove G ∼= H implies H ∼= G.(c) Prove G ∼= H and H ∼= K imply G ∼= K. Thus, graph isomorphism is an equivalencerelation on any given set of graphs.

3-6. Find all isomorphism classes of simple graphs with at most four vertices.

3-7. Find the adjacency matrices for the graphs in Exercise 3-1.

3-8. Let G be the simple graph in Figure 3.10. For 1 ≤ k ≤ 8, find the number of walks oflength k in G from vertex 1 to vertex 10.

3-9. Let G be the graph in Figure 3.21. Find the number of walks in G of length 5 betweeneach pair of vertices.

3-10. Let G be the digraph in Figure 3.24. Find the number of closed walks in G of length10 that begin at vertex 0.

3-11. Let G be a graph with adjacency matrix A. (a) Find a formula for the number ofpaths in G of length 2 from vi to vj . (b) Find a formula for the number of paths in G oflength 3 from vi to vj .

3-12. Consider the DAG G shown here.

Page 127: Combinatorics - Routledge

Counting Problems in Graph Theory 151

3

1

4

6

5

2

(a) Find all total orderings of the vertices for which the adjacency matrix of G is strictlylower-triangular. (b) How many paths in G go from vertex 5 to vertex 1?

3-13. A strict partial order on a set X is an irreflexive, transitive binary relation on X .Given a strict partial order R on a finite set X , show that the simple digraph (X,R) is aDAG.

3-14. For each of the following sets X and strict partial orders R, draw the associated DAGand calculate the number of paths from the smallest element to the largest element of thepartially ordered set.

(a) X = {1, 2, 3, 4, 5} under the ordering 1 < 2 < 3 < 4 < 5.(b) X is the set of subsets of {1, 2, 3}, and (S, T ) ∈ R iff S ( T .(c) X is the set of positive divisors of 60, and (a, b) ∈ R iff a < b and a divides b.

3-15. Let X = {1, 2, . . . , n} ordered by 1 < 2 < · · · < n. In the associated DAG, how manypaths go from 1 to n? Can you find a combinatorial (not algebraic) proof of your answer?

3-16. Let X be the set of subsets of {1, 2, . . . , n} ordered by strict set inclusion. In theassociated DAG, how many paths go from ∅ to {1, 2, . . . , n}?3-17. Given a digraph G, construct a simple digraph H as follows. The vertices of H arethe strong components of G. Given C,D ∈ V (H) with C 6= D, there is an edge from C to Din H iff there exists c ∈ C and d ∈ D such that there is an edge from c to d in G. (a) Provethat H is a DAG. (b) Conclude that some strong component C of G has no incoming edgesfrom outside C, and some strong component D has no outgoing edges. (c) Draw the DAGsassociated to the digraph G3 in Figure 3.1 and the functional digraph in Figure 3.5.

3-18. (a) Find the degree multiset for the graph in Figure 3.10, and verify Theorem 3.35in this case. (b) Compute the indegrees and outdegrees at each vertex of the digraph inFigure 3.24, and verify Theorem 3.32 in this case.

3-19. Find necessary and sufficient conditions for a multiset [d1, d2, . . . , dn] to be the degreemultiset of a graph G.

3-20. Consider the cycle graph Cn defined in Example 3.84. (a) What is deg(Cn)? (b) Showthat any connected graph with the degree multiset in (a) must be isomorphic to Cn. (c) Howmany graphs with vertex set {1, 2, . . . , n} are isomorphic to Cn? (d) How many isomorphismclasses of graphs have the same degree multiset as Cn? (e) How many isomorphism classesof simple graphs have the same degree multiset as Cn?

3-21. Consider the path graph Pn defined in Example 3.84. (a) What is deg(Pn)? (b) Showthat any connected graph with the degree multiset in (a) must be isomorphic to Pn. (c) Howmany graphs with vertex set {1, 2, . . . , n} are isomorphic to Pn? (d) How many isomorphismclasses of graphs have the same degree multiset as Pn?

3-22. Find two simple graphs G and H with the smallest possible number of vertices, suchthat deg(G) = deg(H) but G 6∼= H .

3-23. Prove or disprove: there exists a simple graph G with more than one vertex such thatthe degree multiset deg(G) contains no repetitions.

Page 128: Combinatorics - Routledge

152 Combinatorics, Second Edition

3-24. Prove or disprove: there exists a graph G with no loops and more than one vertexsuch that the degree multiset deg(G) contains no repetitions.

3-25. Given a graph G = (V,E, ǫ), we can encode the endpoint function ǫ by a |V | × |E|matrix M , with rows indexed by V and columns indexed by E, such that M(v, e) is 2 if eis a loop edge at v, 1 if e is a non-loop edge incident to v, and 0 otherwise. M is called theincidence matrix of G. Prove the Degree Sum Formula 3.35 by computing the sum of allentries of M in two ways.

3-26. Draw the functional digraphs associated to each of the following functions f : X → X .For each digraph, find the set C of cyclic vertices and the set partition {Sv : v ∈ C}described in Theorem 3.43. (a) X = {1, 2, 3, 4}, f is the identity map on X ; (b) X ={0, 1, . . . , 6}, f(x) = (x2+1) mod 7; (c) X = {0, 1, . . . , 12}, f(x) = (x2+1) mod 13; (d) X ={0, 1, . . . , 10}, f(x) = 3x mod 11; (e) X = {0, 1, . . . , 11}, f(x) = 4x mod 12.

3-27. Let X = {0, 1, 2, . . . , 9}. (a) Define f : X → X by setting f(x) = (3x + 7) mod 10.Draw the functional digraphs for f , f−1 and f ◦ f . What is the smallest integer k > 0 suchthat f ◦ f ◦ · · · ◦ f (k factors) is the identity map on X? (b) Define g : X → X by settingg(x) = (2x+ 3) mod 10. Draw the functional digraphs for g and g ◦ g.3-28. Let X be a finite set, let x0 ∈ X , and let f : X → X be any function. Recursivelydefine xm+1 = f(xm) for all m ≥ 0. Show that there exists i > 0 with xi = x2i.

3-29. Pollard-rho Factoring Algorithm. Suppose N > 1 is an integer. Let X ={0, 1, . . . , N − 1}, and define f : X → X by f(x) = (x2 + 1) mod N . (a) Show that thefollowing algorithm always terminates and returns a divisor of N greater than 1. (Use theprevious exercise.)

Step 1. Set u = f(0), v = f(f(0)), and d = gcd(v − u,N).Step 2. While d = 1: set u = f(u), v = f(f(v)), and d = gcd(v − u,N).Step 3. Return d.

(b) Trace the steps taken by this algorithm to factor N = 77 and N = 527.

3-30. Suppose X is a finite set of size k and f : X → X is a random function (which meansthat for all x, y ∈ X , P (f(x) = y) = 1/k, and these events are independent for differentchoices of x). Let x0 ∈ X , define xm+1 = f(xm) for all m ≥ 0, and let S be the leastindex such that xS = xt for some t < S. (a) For each s ≥ 0, find the exact probability thatS > s. (b) Argue informally that the expected value of S is at most 2

√k. (c) Use (b) to

argue informally that the expected number of gcd computations needed by the Pollard-rhofactoring algorithm to find a divisor of a composite number N is bounded above by 2N1/4.

3-31. Let V be an n-element set, and let v0 6∈ V . A function f : V → V is called acyclic iffall cycles in the functional digraph of f have length 1. Count these functions by setting upa bijection between the set of acyclic functions on V and the set of rooted trees on V ∪{v0}with root v0.

3-32. How many bijections f on an 8-element set are such that the functional digraph of fhas: (a) five cycles; (b) three cycles; (c) one cycle?

3-33. Let X be an n-element set. Let Y be the set of all functional digraphs for bijectionsf : X → X . How many equivalence classes does Y have under the equivalence relation ofgraph isomorphism?

3-34. How many functional digraphs with vertex set {1, 2, . . . , n} have a1 cycles of length1, a2 cycles of length 2, etc., where

∑i iai = n?

3-35. Referring to the proof of the Rooted Tree Rule, draw pictures of the set A of functions,the set B of trees, and the bijection φ : A→ B when n = 4.

Page 129: Combinatorics - Routledge

Counting Problems in Graph Theory 153

3-36. Compute the rooted tree associated to the function below by the map φ in the proofof the Rooted Tree Rule.

f(1) = 1; f(2) = 19; f(3) = 8; f(4) = 30; f(5) = 5;f(6) = 15; f(7) = 8; f(8) = 9; f(9) = 26; f(10) = 23;f(11) = 21; f(12) = 30; f(13) = 27; f(14) = 13; f(15) = 28;f(16) = 16; f(17) = 13; f(18) = 23; f(19) = 25; f(20) = 11;f(21) = 5; f(22) = 19; f(23) = 25; f(24) = 30; f(25) = 18;f(26) = 9; f(27) = 16; f(28) = 15; f(29) = 7; f(30) = 30.

3-37. Compute the function associated to the rooted tree with edge set

{(1, 1), (2, 12), (3, 1), (4, 3), (5, 10), (6, 17), (7, 15), (8, 7), (9, 3),(10, 3), (11, 12), (12, 1), (13, 4), (14, 10), (15, 1), (16, 4), (17, 4)}

by the map φ−1 in the proof of the Rooted Tree Rule.

3-38. Formulate a theorem for rooted trees similar to Theorem 3.74, and prove it by ana-lyzing the bijection in the Rooted Tree Rule.

3-39. Let G be the digraph in Figure 3.2. Use the algorithm in Theorem 3.52 to convertthe walk

W = (1, b, 1, b, 1, a, 3, f, 5,m, 2, n, 5, h, 4, c, 3, f, 5, j, 4, g, 5,m, 2, k, 4)

to a path in G from 1 to 4.

3-40. What are the strong components of a functional digraph?

3-41. Show that a connected graph G with n vertices has n edges iff G has exactly onecycle.

3-42. Prove that a graph G is not connected iff there exists an ordering of the vertices ofG for which the adjacency matrix of G is block-diagonal with at least two diagonal blocks.

3-43. Prove Theorem 3.60.

3-44. How many connected simple graphs have vertex set {1, 2, 3, 4}?3-45. Prove that every forest is bipartite.

3-46. How many connected simple graphs on the vertex set {1, 2, 3, 4, 5} have exactly fiveedges?

3-47. Prove that a graph G with no odd-length cycles is bipartite by induction on thenumber of edges in G.

3-48. How many bipartite simple graphs have partite sets A = {1, 2, . . . ,m} and B ={m+ 1, . . . ,m+ n}?3-49. Suppose G is a bipartite graph with c components. Count the number of decomposi-tions of V (G) into an ordered pair of partite sets (A,B).

3-50. Suppose G is a k-regular graph with n vertices. (a) How many edges are in G? (b) Ifk > 0 and G is bipartite with partite sets A and B, prove that |A| = |B|.3-51. Fix k ≥ 2. Prove or disprove: there exists a k-regular bipartite graph G such that Ghas a cut-edge.

3-52. Suppose G is a graph, and G′ is obtained from G by deleting some edges of G. Whatis the relation between m(G) and m(G′)? What is the relation between vc(G) and vc(G′)?

3-53. For each k ≥ 0, give a specific example of a graph G such that vc(G)−m(G) = k.

3-54. Find a maximum matching and a minimum vertex cover for the graph shown here.

Page 130: Combinatorics - Routledge

154 Combinatorics, Second Edition

31 2 54 6

7 8 10 11 129

3-55. For m,n ≥ 1, the grid graph Gm,n has vertex set {1, 2, . . . ,m} × {1, 2, . . . , n} withedges from (i, j) to (i+1, j) for 1 ≤ i < m, 1 ≤ j ≤ n, and edges from (i, j) to (i, j +1) for1 ≤ i ≤ m, 1 ≤ j < n. For example, Figure 1.2 displays several copies of the graph G3,4.Find a maximum matching and a minimum vertex cover for each graph Gm,n, and hencedetermine m(Gm,n) and vc(Gm,n).

3-56. Suppose X is a finite set, and P = {S1, . . . , Sk} is a collection of subsets of X .A system of distinct representatives for P is a list a1, . . . , ak of k distinct elements of Xsuch that ai ∈ Si for all i. Prove that P has a system of distinct representatives iff for allI ⊆ {1, 2, . . . , k}, |I| ≤ |⋃i∈I Si|.3-57. An independent set of a graph G is a subset I of the vertex set of G such that notwo vertices in I are adjacent. Let i(G) be the size of a maximum independent set of G.An edge cover of G is a subset C of the edge set of G such that every vertex of G is theendpoint of some edge in C. Let ec(G) be the size of a minimum edge cover of G. Prove ananalogue of the Lemma on Matchings and Vertex Covers for the numbers i(G) and ec(G).

3-58. Show that I is an independent set of a graph G iff V (G)−I is a vertex cover of G.Conclude that i(G) + vc(G) = |V (G)|.3-59. Let G be a graph with no isolated vertex. (a) Given any maximum matching M ofG, use M to construct an edge cover of G of size |V (G)| − |M |. (b) Given any minimumedge cover C of G, use C to construct a matching of G of size |V (G)| − |C|. (c) Concludethat m(G) + ec(G) = |V (G)|.3-60. Use the preceding exercises to prove that for a bipartite graph G with no vertex ofdegree zero, i(G) = ec(G).

3-61. Use Hall’s Matching Theorem to prove the Konig-Egervary Theorem.

3-62. Prove that an n-vertex graph G in which every vertex has degree at least (n − 1)/2must be connected.

3-63. Let G be a forest with n vertices and k connected components. Compute∑v∈V (G) degG(v) in terms of n and k.

3-64. The arboricity of a simple graph G, denoted arb(G), is the least n such that thereexist n forests Fi with V (G) =

⋃ni=1 V (Fi) and E(G) =

⋃ni=1 E(Fi). Prove that

arb(G) ≥ maxH

⌈ |E(H)||V (H)| − 1

⌉,

where H ranges over all induced subgraphs of G with more than one vertex. (It can beshown that equality holds [94].)

3-65. Show that any tree not isomorphic to a path graph Pn must have at least three leaves.

3-66. Let T be a tree. Show that degT (v) is odd for all v ∈ V (T ) iff for all e ∈ E(T ), bothconnected components of (V (T ), E(T )−{e}) have an odd number of vertices.

3-67. Helly Property of Trees. Suppose T , T1, . . ., Tk are trees, each Ti is a subgraphof T , and V (Ti) ∩ V (Tj) 6= ∅ for all i, j ≤ k. Show that

⋂ki=1 V (Ti) 6= ∅.

3-68. Let G be a tree with leaves {v1, . . . , vm}. Let H be a tree with leaves {w1, . . . , wm}.

Page 131: Combinatorics - Routledge

Counting Problems in Graph Theory 155

Suppose that, for each i and j, the length of the unique path in G from vi to vj equals thelength of the unique path in H from wi to wj . Prove G ∼= H .

3-69. For 1 ≤ n ≤ 7, count the number of isomorphism classes of trees with n vertices.

3-70. (a) How many isomorphism classes of n-vertex trees have exactly three leaves?(b) How many trees with vertex set {1, 2, . . . , n} have exactly three leaves?

3-71. How many trees with vertex set {1, 2, . . . , n} have exactly k leaves?

3-72. Let Kn be the complete graph on n vertices (see Exercise 3-1). (a) Give a bijective orprobabilistic proof that every edge of Kn appears in the same number of spanning trees ofKn. (b) Use Cayley’s Theorem to count the spanning trees of Kn that do not use the edge{1, 2}.3-73. Use Theorem 3.74 to find the number of trees T with V (T ) = {1, 2, . . . , 8} anddeg(T ) = [3, 3, 3, 1, 1, 1, 1, 1].

3-74. Let tn be the number of trees on a given n-element vertex set. Without using Cayley’sTheorem, prove the recursion

tn =

n−1∑

k=1

k

(n− 2

k − 1

)tktn−k.

3-75. (a) Use the pruning bijection to find the word associated to the tree

T = ({0, 1, . . . , 8}, {{1, 5}, {2, 8}, {3, 7}, {7, 0}, {6, 2}, {4, 7}, {5, 4}, {2, 4}}).(b) Use the inverse of the pruning bijection to find the tree with vertex set {0, 1, . . . , 8}associated to the word 1355173.

3-76. Use the inverse of the pruning bijection to find all trees with vertex set {1, 2, . . . , 7}associated to the words in R(11334).3-77. Let G be the graph with vertex set {±1,±2, . . . ,±n} and with an edge between iand −j for all i, j ∈ {1, 2, . . . , n}. (a) Show that any spanning tree in G has at least onepositive leaf and at least one negative leaf. (b) Develop an analogue of the pruning mapthat sets up a bijection between the set of spanning trees of G and pairs of words (u, v),where u ∈ {1, . . . , n}n−1 and v ∈ {−1, . . . ,−n}n−1. Conclude that G has n2n−2 spanningtrees.

3-78. Let χn(x) be the chromatic polynomial for the graph Cn consisting of n verticesjoined in a cycle. Prove that

χn(x) = (x − 1)n + (−1)n(x− 1) for all n ≥ 2.

3-79. Find the chromatic polynomials for the graphs in Exercise 3-1.

3-80. Find the chromatic polynomial and chromatic number for the graph G2 in Figure 3.1.

3-81. Find two non-isomorphic simple graphs with the same chromatic polynomial.

3-82. A certain department needs to schedule meetings for a number of committees, whosemembers are listed in the following table.

Committee MembersAdvisory Driscoll, Loomis, LaskerAlumni Sheffield, LoomisColloquium Johnston, Tchaikovsky, ZornComputer Loomis, Clark, SpadeGraduate Kennedy, Loomis, TrotterMerit Lee, Rotman, Fowler, SheffieldPersonnel Lasker, Schreier, Tchaikovsky, TrotterUndergraduate Jensen, Lasker, Schreier, Trotter, Perkins

Page 132: Combinatorics - Routledge

156 Combinatorics, Second Edition

(a) What is the minimum number of time slots needed so that all committees can meetwith no time conflicts? (b) How many non-conflicting schedules are possible if there are six(distinguishable) time slots available? (c) Repeat (a) and (b), assuming that Zorn becomesa member of the Merit Committee (and remains a member of the Colloquium Committee).

3-83. Let Kn be the complete graph on n vertices (see Exercise 3-1). (a) How many sub-graphs does Kn have? (b) How many induced subgraphs does Kn have?

3-84. Prove that a graph G has at least one spanning tree iff G is connected.

3-85. Fill in the details of the proof of Theorem 3.110.

3-86. Use the Spanning Tree Recursion 3.107 to find τ(G1) for the graph G1 in Figure 3.1.

3-87. Let T1 and T2 be spanning trees of a graph G. (a) If e1 ∈ E(T1)−E(T2), prove thereexists e2 ∈ E(T2)−E(T1) such that

T3 = (V (G), (E(T1)−{e1}) ∪ {e2})

is a spanning tree of G. (b) If e1 ∈ E(T1)−E(T2), prove there exists e2 ∈ E(T2)−E(T1)such that

T4 = (V (G), (E(T2) ∪ {e1})−{e2})is a spanning tree of G.

3-88. Fix k ≥ 3. For each n ≥ 1, let Gn be a graph obtained by gluing together n regulark-sided polygons in a row along shared edges. The figure below illustrates the case k = 6,n = 5.

Let G0 consist of a single edge. Prove the recursion

τ(Gn) = kτ(Gn−1)− τ(Gn−2) for all n ≥ 2.

What are the initial conditions?

3-89. Find m(G) and vc(G) for the graph G displayed in the previous exercise.

3-90. Given a simple graph G, let G−v be the induced subgraph with vertex set V (G)−{v}.Assume |V (G)| = n ≥ 3. (a) Prove that |E(G)| = (n− 2)−1

∑v∈V (G) |E(G−v)|. (b) Prove

that, for v0 ∈ V (G), degG(v0) = (n− 2)−1∑

v∈V (G) |E(G−v)| − |E(G−v0)|.3-91. For each graph in Exercise 3-1, count the number of spanning trees by direct enu-meration, and again by the matrix-tree theorem.

3-92. Confirm by direct enumeration that the digraph in Figure 3.24 has 16 spanning treesrooted at 0.

3-93. Let G be the graph with vertex set {0, 1}3 such that there is an edge between v, w ∈V (G) iff the words v and w differ in exactly one position. Find the number of spanningtrees of G.

3-94. Let I be the m×m identity matrix, let J be the m×m matrix all of whose entriesare 1, and let t, u be scalars. Show that det(tI − uJ) = tm −mtm−1u.3-95. Deduce Cayley’s Theorem 3.71 from the Matrix-Tree Theorem 3.113.

Page 133: Combinatorics - Routledge

Counting Problems in Graph Theory 157

3-96. Let A and B be disjoint sets of size m and n, respectively. Let G be the simple graphwith vertex set A ∪B and edge set {{a, b} : a ∈ A, b ∈ B}. Show that τ(G) = mn−1nm−1.

3-97. How many closed Eulerian tours starting at vertex 5 does the digraph in Figure 3.25have?

3-98. Find necessary and sufficient conditions for a graph to have a (not necessarily closed)Eulerian tour.

3-99. Consider a digraph with indistinguishable edges consisting of a vertex set V and amultiset of directed edges (u, v) ∈ V × V . Formulate the notion of a closed Eulerian tourfor such a digraph, and prove an analogue of Theorem 3.121.

3-100. de Bruijn Sequences. Let A = {x1, . . . , xn} be an n-letter alphabet. For eachk ≥ 2, show that there exists a word w = w0w1 · · ·wnk−1 such that the nk words

wiwi+1 · · ·wi+k−1 (where 0 ≤ i < nk and subscripts are reduced mod nk)

consist of all possible k-letter words over A.

3-101. The Petersen graph is the graph G with vertex set consisting of all two-elementsubsets of {1, 2, 3, 4, 5}, and with edge set {{A,B} : A ∩B = ∅}. (a) Compute the numberof vertices and edges in G. (b) Show that G is isomorphic to each of the graphs shown here.

J

1

2

3 4

5

6

7

89

10

A B

C

DE

F

G

H I

(c) Show that G is 3-regular. (d) Is G bipartite? (e) Show that any two non-adjacent verticesin G have exactly one common neighbor.

3-102. Find (with proof) all k such that the Petersen graph has a cycle of length k.

3-103. Given any edge e in the Petersen graph G, count the number of cycles of length 5in G that contain e. Use this to count the total number of cycles of length 5 in G.

3-104. (a) Prove that the Petersen graph G has exactly ten cycles of length 6. (b) Howmany claws (see Exercise 3-1) appear as induced subgraphs of G?

3-105. How many spanning trees does the Petersen graph have?

Notes

Our coverage of graph theory in this chapter has been limited to a few enumerative topics.Systematic expositions of graph theory may be found in [13, 16, 17, 25, 52, 60, 130, 136]; thetext by West is especially recommended. Roberts [109] gives a treatment of graph theorythat emphasizes applications.

Page 134: Combinatorics - Routledge

158 Combinatorics, Second Edition

The bijection used to enumerate rooted trees in the Rooted Tree Rule 3.47 is due toEgecioglu and Remmel [28]. The original proof of Cayley’s Theorem appears in [21]. Thepruning bijection described in §3.12 is due to Prufer [100]; the image of a tree under thismap is often called the Prufer code of the tree. For more on the enumeration of trees,see [91].

Our discussion of the Konig-Egervary Theorem is based on Rizzi’s proof [108]. Thematrix-tree theorem for undirected graphs is often attributed to Kirchhoff [71]; Tutte ex-tended the theorem to digraphs [126]. The enumeration of Eulerian tours in the EulerianTour Rule 3.121 was proved by van Aardenne-Ehrenfest and de Bruijn [127].

Page 136: Combinatorics - Routledge

Chapter 2

Combinatorics

Explaining what combinatorics is about may be simple since it deals with objects andtechniques that are quite familiar to most people. Yet, combinatorics is not easy to defineprecisely. At the fundamental level, combinatorics deals with the questions related to count-ing the number of elements in a given set; a bit more precisely, combinatorics deals withdiscrete structures: sets—with, perhaps, some specific characteristics—whose elements canbe listed and enumerated, as opposed to sets whose elements vary continuously and cannotbe put in a list.

Moreover, beyond its object of study, combinatorics can be characterized by its methods.Typically, by the combinatorial method we mean a relatively basic—but, perhaps, surpris-ingly deep and far-reaching—argument using some relatively elementary tools, rather thanthe application of sophisticated and elaborately developed machinery. That is what makescombinatorics so highly applicable and why it serves as a very elegant and accessible branchof study in the mathematics curriculum.

In this section we introduce some of the concepts and methods of combinatorics that wewill need later.

2.1 Basic enumeration principles

Enumeration—or, simply, counting—is probably one of our earliest intellectual pursuits,and it is a ubiquitous task in everyday life. The principles of enumeration are also whatseveral branches of mathematics are based on, especially probability theory and statistics.In this section we briefly discuss elementary enumeration techniques.

A typical enumeration problem asks us to determine the size of a set: the size of a set A,denoted by |A|, is the number of elements in A. Clearly, each set has either finite or infinitesize. Here we focus on finite sets only.

Most enumeration questions can be reduced to one of two fundamental principles: theAddition Rule and the Multiplication Rule. According to the Addition Rule, if A and B aredisjoint finite sets, then we have

|A ∪B| = |A|+ |B|.More generally, if A1, A2, . . . , An are pairwise disjoint finite sets (n ∈ N), then we have

|A1 ∪ · · · ∪ An| = |A1|+ · · ·+ |An|.The Multiplication Rule says that for arbitrary finite sets A and B, we have

|A×B| = |A| · |B|,

15

Page 137: Combinatorics - Routledge

16 CHAPTER 2. COMBINATORICS

and more generally, for arbitrary finite sets A1, A2, . . . , An (n ∈ N), we have

|A1 × · · · ×An| = |A1| · · · · · |An|.Observe that the Addition Rule—unlike the Multiplication Rule—requires that the sets

be pairwise disjoint. A more general formula treats the case when our sets are not (or notknown to be) pairwise disjoint: for finite sets A and B we can verify that

|A ∪B| = |A|+ |B| − |A ∩B|;indeed, to count the elements in the union of A and B, adding the sizes of A and Btogether would double-count the elements that are in both A and B, so we need to subtractthe number of elements in the intersection of A and B. Similarly, for finite sets A, B, andC, we have

|A ∪B ∪ C| = |A|+ |B|+ |C| − |A ∩B| − |A ∩ C| − |B ∩ C|+ |A ∩B ∩ C|.The situation gets more complicated as the number of sets increases; while a precise state-ment (called the Inclusion–Exclusion Rule) is readily available, we will not state it here.Instead, we just point out that, in general, for arbitrary sets A1, A2, . . . , An we have

|A1 ∪ · · · ∪ An| ≤ |A1|+ · · ·+ |An|.An often-used consequence of this inequality is the Pigeonhole Principle, which says

that, if we have|A1 ∪ · · · ∪ An| > kn

for some nonnegative integer k, then there must be at least one index i ∈ {1, . . . , n} forwhich |Ai| ≥ k + 1. To paraphrase: if more than kn pigeons happen to sit in n holes, thenat least one hole must have at least k + 1 pigeons in it. Consequently, for example, we seethat in a set of 101 positive integers, one can always find 11 (or more) that share their lastdigits; similarly, among a group of 3000 people there is always a group of at least nine thatshare the same birthday.

While the counting principles we reviewed here may seem rather elementary, they havefar-reaching consequences. We present some in the exercises below.

Exercises

1. Exhibit the Inclusion–Exclusion formula for four sets; that is, find an expression forthe size of the union of four sets in terms of the sizes of their various intersections.

2. Prove that however we place seven points inside an 8-by-9 rectangle, we can alwaysfind

(a) a pair whose distance is at most 5, and

(b) three that form a triangle of area at most 12.

3. Let S be a set of 100 distinct positive integers. Which of the following statements aretrue?

(a) If each element of S is at most 198, then S must contain two elements that arerelatively prime.

(b) If each element of S is at most 199, then S must contain two elements that arerelatively prime.

(c) If each element of S is at most 198, then S must contain two elements so thatone is divisible by the other.

(d) If each element of S is at most 199, then S must contain two elements so thatone is divisible by the other.

Page 138: Combinatorics - Routledge

2.2. COUNTING LISTS, SEQUENCES, SETS, AND MULTISETS 17

2.2 Counting lists, sequences, sets, and multisets

Before we discuss the four main counting questions in mathematics, we review some familiarterminology and notations, and introduce some new ones. Recall that, for a given set A andpositive integer m, an element (a1, a2, . . . , am) of Am is called a sequence of length m. Theorder of the terms in the sequence matters; for example, the sequence (2, 3, 4, 5) of integersis different from (3, 2, 4, 5). On the other hand, a subset of A of size m is simply a collectionof m of its elements, where two subsets are considered equal without regard to the orderin which the terms are listed; for example, {2, 3, 4, 5} and {3, 2, 4, 5} are equal subsets ofthe set of integers. Recall also that a set remains unchanged if we choose to list some of itselements more than once; for example, the sets {2, 3, 3, 5}, {2, 3, 5, 5}, and {2, 3, 5} are allequal, while the sequences (2, 3, 3, 5), (2, 3, 5, 5), and (2, 3, 5) are all different. Thus, we canconsider sets as two-fold relaxations of sequences: we don’t care about the order in whichthe elements are listed, nor do we care how many times the elements are listed.

It will be useful for us to introduce two other objects. First, we say that a sequence(a1, a2, . . . , am) of elements of a set A is a list, if the m terms are pairwise distinct. Thus,in a list, the order of the elements still matters, but each element is only allowed to appearonce. For example, the sequence (2, 3, 4, 5) is a list, but (2, 3, 3, 5) is not. Conversely, ina so-called multiset [a1, a2, . . . , am] of size m, the order of the elements a1, a2, . . . , am ofA does not matter (as it is the case with sets), but elements may appear repeatedly (asthey may in sequences). For example, the multisets [2, 3, 3, 5], [2, 3, 5, 5], and [2, 3, 5] are alldifferent, but [2, 3, 3, 5] is still the same as [2, 5, 3, 3].

Given a set A and a positive integer m, we are interested in counting the number of m-sequences (sequences of length m), m-lists (lists of length m), m-multisubsets (multisubsetsof size m), and m-subsets (subsets of size m) of A. The schematic summary of these fourterms is given in the following table.

order matters order does not matter

elements distinct m-lists m-sets

elements may repeat m-sequences m-multisets

Obviously, if |A| < m, then A has neither m-lists nor m-subsets. If |A| = m, then the(only) m-subset of A is A itself, while, as we will soon see, if |A| = m, then A has m! m-lists.For other situations, we introduce the following notations.

Suppose that n is a nonnegative integer and m is a positive integer. We define the risingfactorial m-th power and the falling factorial m-th power of n to be

nm = n(n+ 1) · · · (n+m− 1)

and

nm = n(n− 1) · · · (n−m+ 1),

respectively. For example, we have

103 = 10 · 11 · 12 = 1320

and

103 = 10 · 9 · 8 = 720.

Page 139: Combinatorics - Routledge

18 CHAPTER 2. COMBINATORICS

Analogous to n0 = 1 and 0! = 1, we extend these notations with

n0 = 1 and n0 = 1

for arbitrary nonnegative integers n.Furthermore, we introduce the notations

(nm

)(pronounced “n choose m”) and

[nm

]

(pronounced “n multichoose m”): For nonnegative integers m and n,(n

m

)=

nm

m!=

n(n− 1) · · · (n−m+ 1)

m!

and [ nm

]=

nm

m!=

n(n+ 1) · · · (n+m− 1)

m!.

It is well known that these quantities always denote integers. The values of(nm

), also

known as binomial coefficients, are exhibited in Pascal’s Triangle; here we tabulate some ofthese values in a table format. (Note that, when m > n, the formula above yields

(nm

)= 0;

keeping the traditional shape of Pascal’s Triangle, we omitted these entries from the tablebelow.)

(nm

)m=0 m=1 m=2 m=3 m=4 m=5 m=6 m=7

n=0 1n=1 1 1n=2 1 2 1n=3 1 3 3 1n=4 1 4 6 4 1n=5 1 5 10 10 5 1n=6 1 6 15 20 15 6 1n=7 1 7 21 35 35 21 7 1

Observe that, since

n(n− 1) · · · (n−m+ 1)

m!=

n(n− 1) · · · (m+ 1)

(n−m)!

(which we can check by cross-multiplying), we have the identity(n

m

)=

(n

n−m

),

expressing the fact that the rows in Pascal’s Triangle are “palindromic.” The explanationfor the term “binomial coefficient” will be clear once we discuss the Binomial Theorembelow.

The first few values of[nm

]are as follows.

[nm

]m=0 m=1 m=2 m=3 m=4 m=5 m=6 m=7

n=1 1 1 1 1 1 1 1 1n=2 1 2 3 4 5 6 7 8n=3 1 3 6 10 15 21 28 36n=4 1 4 10 20 35 56 84 120n=5 1 5 15 35 70 126 210 330n=6 1 6 21 56 126 252 462 792n=7 1 7 28 84 210 462 924 1716

Page 140: Combinatorics - Routledge

2.2. COUNTING LISTS, SEQUENCES, SETS, AND MULTISETS 19

As we can see, the two tables contain the same data—values are just shifted: the entriesin column m in the first table are moved up by m − 1 rows in the second table. Indeed,since for integers n and m we clearly have

nm = n(n+ 1) · · · (n+m− 1) = (n+m− 1)(n+m− 2) · · ·n = (n+m− 1)m,

we see that values of[nm

]can be expressed via the more-often-used binomial coefficients as

[ nm

]=

(n+m− 1

m

).

We are now ready to “size up” our four main configurations. The Enumeration Theoremsays that, if A is a set of size n and m is a positive integer, then

• the number of m-sequences of A is nm,

• the number of m-lists of A is nm,

• the number of m-multisubsets of A is[nm

], and

• the number of m-subsets of A is(nm

).

Note that, when n < m, then nm = 0 and(nm

)= 0, in accordance with the fact that A

has no m-lists and no m-subsets in this case. If n = m, then nm = m! and(nm

)= 1; indeed,

in this case A has m! m-lists while its only m-subset is itself.The enumeration techniques discussed above are often employed to determine the num-

ber of choices one has for selecting or arranging a given number of elements from a givenset or collection of sets. For example, the Addition Rule and the Multiplication Rule can beinterpreted to say that, given boxes labeled A1, A2, . . . , An, if box Ai contains mi distinctobjects (i = 1, 2, . . . , n), then there are

m1 +m2 + · · ·+mn

ways to choose an object from one of the boxes, and there are

m1 ·m2 · · · · ·mn

ways to choose an object from each of the boxes. In a similar manner, the four basic enu-meration functions of the Enumeration Theorem are sometimes called “choice functions”;the following table summarizes our results for the number of ways to choose m elementsfrom a given set of n elements.

order matters order does not matter

elements distinct nm(nm

)

elements may repeat nm[nm

]

An important example for enumeration problems, one that we will refer to often, is tocount the number of positive integer solutions to an equation of the form

x1 + x2 + · · ·+ xm = h;

Page 141: Combinatorics - Routledge

20 CHAPTER 2. COMBINATORICS

that is, to find, for a given h ∈ N, the number of m-sequences of N with the property thatthe entries in the sequence add up to h. (Note that we are counting sequences: the orderof the terms does matter.) We can visualize this question by imagining a segment of lengthh inches with markings at all integer inches (that is, at 1, 2, and so on, all the way toh − 1); our task is then to find the number of ways this segment can be broken into mpieces at m − 1 distinct markings: the lengths of the m parts created will correspond, inorder, to x1, x2, . . . , xm. By the Enumeration Theorem, the number of ways that this canbe done, and therefore the number of positive integer solutions to our equation, is

(h−1m−1

).

As a variation, one can easily prove (see one of the exercises below) that the number of

nonnegative integer solutions to the same equation equals[

h+1m−1

]=(m+h−1

h

).

Exercises

1. Find the number of

(a) 4-sequences,

(b) 4-lists,

(c) 4-multisubsets, and

(d) 4-subsets

of a set of size 7. Exhibit one example for each question.

2. Above we have shown that the number of positive integer solutions to an equation

x1 + x2 + · · ·+ xm = h

equals(h−1m−1

). Here we use three different approaches to find the number of nonnegative

solutions to the equation.

(a) Modify the argument used for the number of positive integer solutions to prove

that the number of nonnegative integer solutions equals[

h+1m−1

].

(b) Explain why the number of nonnegative integer solutions to

x1 + x2 + · · ·+ xm = h

is the same as the number of positive integer solutions to

x1 + x2 + · · ·+ xm = h+m,

and use this fact to get that the result is(h+m−1m−1

).

(c) Explain why the number of nonnegative integer solutions to

x1 + x2 + · · ·+ xm = h

is the same as the number of ways one can place h identical objects into mdistinct boxes, and use this fact to get that the result is

[mh

].

(d) Verify algebraically that the results of the three previous parts are the same.

Page 142: Combinatorics - Routledge

2.3. BINOMIAL COEFFICIENTS AND PASCAL’S TRIANGLE 21

2.3 Binomial coefficients and Pascal’s Triangle

In this section we discuss some of the many famous and interesting properties of the so-called binomial coefficients, that is, the quantities

(nm

). First, let us explain the reason for

the name.A closer look at the rows of the table of entries for

(nm

), exhibited earlier, reveals, in

order, the coefficients of the various terms in the expansion of the power (a + b)n (here aand b are arbitrary real numbers and n is a nonnegative integer). For example, the entriesin row 4 of the table are 1, 4, 6, 4, and 1; indeed, the power (a+ b)4 expands as

(a+ b)4 = a4 + 4a3b+ 6a2b2 + 4ab3 + b4.

We can easily explain this coincidence as follows. When using the distributive law toexpand the expression

(a+ b)n = (a+ b) · · · (a+ b),

we arrive at a sum of products of n factors, where each factor is either a or b. Using thecommutative property of multiplication, each term can be arranged so that the a’s (if any)all come before the b’s (if any). We can then collect “like” terms; that is, terms of the forman−mbm for the same m = 0, 1, . . . , n. The number of such terms clearly equals the numberof those n-sequences of the set {a, b} that contain exactly n −m a’s and m b’s, which, bythe Enumeration Theorem, is exactly

(nm

).

This result is known as (Newton’s) Binomial Theorem, and can be stated in general asthe identity

(a+ b)n =

n∑

m=0

(n

m

)an−mbm.

As the name implies,(nm

)is indeed a “binomial coefficient.”

The first few entries for(nm

)(and, therefore, for

[nm

]as well) are tabulated in Pascal’s

Triangle below.

11 1

1 2 11 3 3 1

1 4 6 4 11 5 10 10 5 1

1 6 15 20 15 6 11 7 21 35 35 21 7 1

We can read off values of(nm

)as follows. If we label the rows, the “left” diagonals, and the

“right” diagonals 0, 1, 2, etc. (we start with 0), then(nm

)appears as the entry where row n

and right diagonal m intersect. For example, we see that(63

)= 20.

The binomial coefficients possess many interesting properties. We have already men-tioned the fact that the rows are “palindromic”:

(n

m

)=

(n

n−m

).

Another important property is known as Pascal’s Identity:

(n

m

)=

(n− 1

m

)+

(n− 1

m− 1

).

Page 143: Combinatorics - Routledge

22 CHAPTER 2. COMBINATORICS

This identity provides us, actually, with the easiest way to enumerate binomial coefficients:each entry in Pascal’s Triangle is simply the sum of the two entries above it. We can, thus,quite quickly find the next row:

1 8 28 56 70 56 28 8 1

Another interesting property of Pascal’s Triangle is that the sum of the entries in eachrow add up to a power of 2:

(n

0

)+

(n

1

)+ · · ·+

(n

n

)= 2n.

Note that this identity follows directly from the Binomial Theorem (take a = b = 1).Similarly, (by taking a = 1 and b = 2) we have

(n

0

)· 20 +

(n

1

)· 21 + · · ·+

(n

n

)· 2n = 3n.

Of the numerous other interesting properties of Pascal’s Triangle, we list only two more:

(n− 1

m

)+

(n− 2

m− 1

)+ · · ·+

(n−m− 1

0

)=

(n

m

),

expressing the fact that the entries in each NW-SE diagonal, above a certain row, add toan entry in the next row. Adding up numbers on NE-SW diagonals yields

(n− 1

m− 1

)+

(n− 2

m− 1

)+ · · ·+

(m− 1

m− 1

)=

(n

m

).

(See the exercises below for proofs.)We will use each of these identities later.

Exercises

1. What identity of binomial coefficients arises from using the Binomial Theorem forevaluating (1− 1)n? Verify your identity for n = 6 and n = 7.

2. Suppose that n and m are positive integers, and suppose that m ≤ n.

(a) We set A = {1, 2, . . . , n}; furthermore, we let A0 be the set of m-subsets of Athat do not contain 1, let A1 be the set of m-subsets of A that contain 1 but donot contain 2, let A2 be the set of m-subsets of A that contain 1 and 2 but donot contain 3, and so on. Prove the identity

(n− 1

m

)+

(n− 2

m− 1

)+ · · ·+

(n−m− 1

0

)=

(n

m

)

by considering A0 ∪ A1 ∪ A2 ∪ · · · ∪ Am.

(b) Prove the identity

(n− 1

m− 1

)+

(n− 2

m− 1

)+ · · ·+

(m− 1

m− 1

)=

(n

m

)

using similar techniques as in part (a).

Page 144: Combinatorics - Routledge

2.4. SOME RECURRENCE RELATIONS 23

2.4 Some recurrence relations

Let us return to the binomial coefficients discussed in the previous section. Rather thanlooking at Pascal’s Triangle, let’s arrange their values in a more convenient table format:

p(j,k) k=0 k=1 k=2 k=3 k=4 k=5 k=6 k=7

j=0 1 1 1 1 1 1 1 1j=1 1 2 3 4 5 6 7 8j=2 1 3 6 10 15 21 28 36j=3 1 4 10 20 35 56 84 120j=4 1 5 15 35 70 126 210 330j=5 1 6 21 56 126 252 462 792j=6 1 7 28 84 210 462 924 1716j=7 1 8 36 120 330 792 1716 3432

Here p(j, k) denotes the entry in row j and column k; we have

p(j, k) =

[j + 1

k

]=

(j + k

k

).

As we noted before, Pascal’s Identity, together with the values in the top row and theleft-most column in the table, determine all entries recursively: we simply need to add the(previously determined) values directly above and directly to the left of the desired entry.In fact, we can define the function p(j, k) recursively by the recurrence relation

p(j, k) = p(j − 1, k) + p(j, k − 1)

and the initial conditions that p(j, 0) = 1 for all j ∈ N0 and p(0, k) = 1 for all k ∈ N0.Let us consider a variation where the function a(j, k) is defined by the initial conditions

a(j, 0) = 1 for all j ∈ N0 and a(0, k) = 1 for all k ∈ N0 and by the recursive relation

a(j, k) = a(j − 1, k) + a(j − 1, k − 1) + a(j, k − 1).

The first few values of the function are as follows.

a(j, k) k = 0 k = 1 k = 2 k = 3 k = 4 k = 5 k = 6

j = 0 1 1 1 1 1 1 1j = 1 1 3 5 7 9 11 13j = 2 1 5 13 25 41 61 85j = 3 1 7 25 63 129 231 377j = 4 1 9 41 129 321 681 1289j = 5 1 11 61 231 681 1683 3653j = 6 1 13 85 377 1289 3653 8989

The numbers in this table are called Delannoy numbers, named after the French amateurmathematician who introduced them in the nineteenth century in [62]. According to itsrecurrence relation, the Delannoy number a(j, k) is the sum of not only the entries directlyabove and to the left, but the entry in the “above-left” position as well. Delannoy numbers—like any two-dimensional array—can be turned into a sequence by listing entries by its anti-diagonals; this sequence is given as A008288 in [188]. (The sequence of entries in variouscolumns can be found in [188] as well.) In the next section we shall see an interestinginterpretation of Delannoy numbers.

Page 145: Combinatorics - Routledge

24 CHAPTER 2. COMBINATORICS

Changing the initial conditions, we next define the function c(j, k) by the initial condi-tions c(j, 0) = 0 for all j ∈ N and c(0, k) = 1 for all k ∈ N0 and by the (same) recursiverelation

c(j, k) = c(j − 1, k) + c(j − 1, k − 1) + c(j, k − 1).

The first few values of this function are as follows.

c(j, k) k = 0 k = 1 k = 2 k = 3 k = 4 k = 5 k = 6

j = 0 1 1 1 1 1 1 1j = 1 0 2 4 6 8 10 12j = 2 0 2 8 18 32 50 72j = 3 0 2 12 38 88 170 292j = 4 0 2 16 66 192 450 912j = 5 0 2 20 102 360 1002 2364j = 6 0 2 24 146 608 1970 5336

The numbers given by this table can be found in sequence form at A266213 in [188].The functions a(j, k) and c(j, k) are strongly related; it is not difficult to reduce each

one to the other, as we now show.Consider first the function c(j, k). A quick glance at the tables above suggests that for

j ≥ 1 and k ≥ 1, the entry c(j, k) is the sum of entries a(j, k − 1) and a(j − 1, k − 1):

c(j, k) = a(j, k − 1) + a(j − 1, k − 1).

We will prove this by induction. We see that the equation holds for j = 1 and for k = 1; wethen use the defining recursions for both c and a, as well as our inductive hypothesis, forj ≥ 1 and k ≥ 1 to write

c(j, k) = c(j − 1, k) + c(j − 1, k − 1) + c(j, k − 1)

= a(j − 1, k − 1) + a(j − 2, k − 1) +

+a(j − 1, k − 2) + a(j − 2, k − 2) +

+a(j, k − 2) + a(j − 1, k − 2)

= a(j, k − 1) + a(j − 1, k − 1),

as claimed.Using the recursion for a(j, k) once more, we may rewrite this identity as

c(j, k) = a(j, k)− a(j − 1, k),

from which we geta(j, k) = c(j, k) + a(j − 1, k).

We can then use this identity to express a in terms of c:

a(j, k) = c(j, k) + a(j − 1, k)

= c(j, k) + c(j − 1, k) + a(j − 2, k)

= c(j, k) + c(j − 1, k) + c(j − 2, k) + a(j − 3, k)

= . . .

= c(j, k) + c(j − 1, k) + · · ·+ c(1, k) + a(0, k)

= c(j, k) + c(j − 1, k) + · · ·+ c(1, k) + c(0, k).

In summary, we have:

Page 146: Combinatorics - Routledge

2.4. SOME RECURRENCE RELATIONS 25

Proposition 2.1 For the functions a(j, k) and c(j, k), defined recursively above for all non-negative integers j and k, we have

c(j, k) = a(j, k − 1) + a(j − 1, k − 1) = a(j, k)− a(j − 1, k)

for all j, k ∈ N and

a(j, k) = c(j, k) + c(j − 1, k) + · · ·+ c(1, k) + c(0, k)

for all j, k ∈ N0.

While recursive expressions are quite helpful, direct formulae, if they exist, would be evenmore useful, particularly when the variables are large. For example, the binomial coefficientscan be easily computed via the function p(j, k) defined above, but it is good to know that

p(j, k) =

(j + k

k

)=

(j + k)!

j! · k! .

Although formulae for a(j, k) and c(j, k) are not so direct, we have the following expressions.

Proposition 2.2 For all nonnegative integers j and k we have

a(j, k) =∑

i≥0

(j

i

)(k

i

)2i

and

c(j, k) =∑

i≥0

(j − 1

i− 1

)(k

i

)2i.

For a proof of Proposition 2.2, see page 308. Note that, while the summations seem toinclude infinitely many terms, all but finitely many are zero. Note also that including i = 0in the last sum is only relevant if j = 0. (Here we use the convention that

(j−1−1

)equals 1

for j = 0 and 0 if j > 0.)It may seem a bit strange that, while p(j, k) and a(j, k) are similarly defined—with the

only difference being that p relies on a double recursion while a uses a triple recursion—theyyield very different formulae. We gain some insight by the following consideration. Supposethat we are given j+k distinct (for example, numbered) balls, and that j of them are greenand k are yellow. Recall that p(j, k) =

(j+kk

), a quantity expressing the number of ways one

can select k balls from the collection of these j+ k balls. Now if i of the k balls selected aregreen and the other k− i are yellow, then the number of such choices, by the MultiplicationRule, equals

(ji

)·(ki

); summing over all possible values of i, we get

p(j, k) =

(j + k

j

)=∑

i≥0

(j

i

)(k

i

),

a form more closely reminiscent to the one for a(j, k) in Proposition 2.2.We will make frequent use of the quantities a(j, k) and c(j, k). Without going into detail

here, we mention, for example, that

• for an s-spanning set of size m in a group of order n (see Chapter B), we haven ≤ a(m, s);

• for aBh set over Z of sizem in a group of order n (see Chapter C), we have n ≥ c(h,m);and

Page 147: Combinatorics - Routledge

26 CHAPTER 2. COMBINATORICS

• for a t-independent set of size m in a group of order n (see Chapter F), we have

– n ≥ c(m, t+12 ) if t is odd and t > 1, and

– n ≥ a(m, t2 ) if t is even.

We will discuss each of these bounds in the relevant chapters of the book.

Exercises

1. Find a(7, 7) and c(7, 7) using

(a) their recursive definitions and

(b) Proposition 2.2.

2. Suppose that m ∈ N. Express a(m, 3) and c(m, 3) as polynomial functions in m.

2.5 The integer lattice and its layers

One of the most often discussed combinatorial objects—and one that we will frequently relyon—is the m-dimensional integer lattice

Zm = Z× Z× · · · × Z︸ ︷︷ ︸m

,

consisting of all points (or vectors) (λ1, λ2, . . . , λm) with integer coordinates. (Here m ∈ N

is called the dimension of the lattice.) Of course, the 1-dimensional integer lattice is simplythe set of integers Z, while the points in Z2 are arranged in an infinite (2-dimensional) gridin the plane, and Z3 can be visualized as an infinite grid in 3-space. (For m ≥ 4, geometricvisualization of Zm is not convenient.)

A layer of the integer lattice is defined as the collection of points with a given fixednorm; that is, for a given nonnegative integer h, the hth layer of Zm is defined as

Zm(h) = {(λ1, λ2, . . . , λm) ∈ Zm | |λ1|+ |λ2|+ · · ·+ |λm| = h}.

Obviously, Zm(0) consists of a single point, the origin. We can also easily see that Zm(1)consists of the points of the m-dimensional lattice with all but one coordinate equal to 0and the remaining coordinate equal to 1 or −1; there are exactly 2m such points.

Describing Zm(h) explicitly gets more complicated as h increases, however. For instance,we find that

Z2(3) = {(0,±3), (±1,±2), (±2,±1), (±3, 0)},and

Z3(2) = {(0, 0,±2), (0,±2, 0), (±2, 0, 0), (0,±1,±1), (±1, 0,±1), (±1,±1, 0)}.

The twelve points of Z2(3) lie on the boundary of a square in the plane (occupying the fourvertices and two points on each edge), and the eighteen points of Z3(2) are on the surfaceof an octahedron (the six vertices and the midpoints of the twelve edges).

We can derive a formula for the size of Zm(h), as follows. For i = 0, 1, 2, . . . ,m, let Iibe the set of those elements of Zm(h) where exactly i of the m coordinates are nonzero.How many elements are in Ii? We can choose which i of the m coordinates are nonzero in(mi

)ways. Next, we choose the absolute values of these nonzero coordinates: since the sum

Page 148: Combinatorics - Routledge

2.5. THE INTEGER LATTICE AND ITS LAYERS 27

of these i positive integers equals h, we have(h−1i−1

)choices (see page 20). Finally, each of

these i coordinates can be positive or negative, and therefore

|Ii| =(m

i

)(h− 1

i − 1

)2i.

Summing now for i yields

|Zm(h)| =h∑

i=0

(m

i

)(h− 1

i− 1

)2i;

since for i > h the terms vanish, we may write this as

|Zm(h)| =∑

i≥0

(m

i

)(h− 1

i− 1

)2i.

Here we recognize the expression for the size of Zm(h) as the quantity c(h,m), discussed indetail in Section 2.4.

In our investigations later, we will also consider certain restrictions of Zm(h). In somecases, we will look at the part of Zm(h) that is in the “first quadrant;” that is, the subsetNm

0 (h) of Zm(h) that contains only those points that contain no negative coordinates:

Nm0 (h) = {(λ1, λ2, . . . , λm) ∈ Nm

0 | λ1 + λ2 + · · ·+ λm = h}.

So, for example,N2

0(3) = {(0, 3), (1, 2), (2, 1), (3, 0)}and

N30(2) = {(0, 0, 2), (0, 2, 0), (2, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 0)}.

We can enumerate Nm0 (h) by observing that it is nothing but the set of m-sequences of

N0 with the property that the entries in the sequence add up to h; as we have seen on page20, this set has size

|Nm0 (h)| =

(m+ h− 1

h

).

Two other, frequently appearing, cases occur when we restrict Zm(h) or Nm0 (h) to those

points where the absolute value of the coordinates are not more than 1. (These points lie

within a cube of side length 2 centered at the origin.) We denote these sets by Zm(h) and

Nm0 (h), respectively; namely, we have

Zm(h) = {(λ1, λ2, . . . , λm) ∈ {−1, 0, 1}m | |λ1|+ |λ2|+ · · ·+ |λm| = h}

andNm

0 (h) = {(λ1, λ2, . . . , λm) ∈ {0, 1}m | λ1 + λ2 + · · ·+ λm = h}.So, for example,

Z3(2) = {(0,±1,±1), (±1, 0,±1), (±1,±1, 0)}and

N30(2) = {(0, 1, 1), (1, 0, 1), (1, 1, 0)},

but we have Z2(3) = ∅ and N20(3) = ∅. It is easy to see that the sizes of these sets are given

by

|Zm(h)| =(m

h

)2h

Page 149: Combinatorics - Routledge

28 CHAPTER 2. COMBINATORICS

and

|Nm0 (h)| =

(m

h

).

Often, rather than considering a single layer Zm(h) of the integer lattice, we will studythe union of several of them. Since the layers are pairwise disjoint, for a given range H ⊆ N0

of norms we have ∣∣∣∣∣⋃

h∈H

Zm(h)

∣∣∣∣∣ =∑

h∈H

|Zm(h)|;

we can similarly just add the sizes of Nm0 (h), Zm(h), and Nm

0 (h) for all h ∈ H . Most often,we will consider H consisting of

• a single norm h (with h ∈ N0),

• a range [0, s] = {0, 1, 2, . . . , s} (with s ∈ N0), or

• allow all possible norms (i.e., have H = N0).

The following table summarizes what we can say, using some of the identities we have seenearlier, about the size of

Λm(H) = {(λ1, λ2, . . . , λm) ∈ Λm | |λ1|+ |λ2|+ · · ·+ |λm| ∈ H}

for these choices of H ⊆ N0 and our four exemplary sets Λ ⊆ Z.

|Λm(H)| H = {h} H = [0, s] H = N0

Λ = N0

(m+h−1

h

) (m+ss

)∞

Λ = Z c(h,m) =∑

i≥0

(mi

)(h−1i−1

)2i a(m, s) =

∑i≥0

(mi

)(si

)2i ∞

Λ = {0, 1}(mh

) ∑h∈H

(mh

)2m

Λ = {−1, 0, 1}(mh

)2h

∑h∈H

(mh

)2h 3m

We need to compute the size of an additional set that we use later. Namely, we wantto find the number of lattice points that are strictly on one side of one of the coordinateplanes of the m-dimensional space; that is, the size of the set

Zm(h)k+ = {(λ1, λ2, . . . , λm) ∈ Zm | |λ1|+ |λ2|+ · · ·+ |λm| = h, λk > 0}.

For example, the lattice points of the layer Z2(3) that are to the right of the y-axis are

Z2(3)1+ = {(1,±2), (2,±1), (3, 0)}.

Note that |Zm(h)k+| is the same for any k = 1, 2, . . . ,m; here we calculate |Zm(h)1+|.As before, we let, for each j = 1, . . . ,m, Ij denote the set of those elements of Zm(h)1+

where exactly j of the m coordinates are nonzero. (Note that I0 = ∅.) How many elementsare in Ij? Here we can choose which j of the m coordinates are nonzero in

(m−1j−1

)ways (since

Page 150: Combinatorics - Routledge

2.5. THE INTEGER LATTICE AND ITS LAYERS 29

we must have λ1 > 0). Next, we choose the absolute values of these nonzero coordinates:since the sum of these j positive integers equals h, we have

(h−1j−1

)choices. Finally, j − 1 of

these coordinates can be positive or negative, and therefore

|Ij | =(m− 1

j − 1

)(h− 1

j − 1

)2j−1.

Summing now for j yields

|Zm(h)1+| =∑

j≥1

(m− 1

j − 1

)(h− 1

j − 1

)2j−1.

We can replace j − 1 by i; this yields

|Zm(h)1+| =∑

i≥0

(m− 1

i

)(h− 1

i

)2i,

and therefore

|Zm(h)k+| =∑

i≥0

(m− 1

i

)(h− 1

i

)2i = a(m− 1, h− 1)

for every k = 1, 2, . . . ,m. Indeed, the set Z2(3)1+ featured above consists of a(1, 2) = 5points.

Exercises

1. We have already evaluated the entries in the column of H = {h} in the table on page28; here we verify the rest. Prove each of the following.

(a) |Zm([0, s])| = a(m, s)

(b) |Nm0 ([0, s])| =

(m+ss

)

(c) |Zm(N0)| = 3m

(d) |Nm0 (N0)| = 2m

2. For each set below, first find the size of the set, then list all its elements.

(a) Z2([0, 3])

(b) N20([0, 3])

(c) Z2([0, 3])

(d) N20([0, 3])

(e) Z2(3)1+

Page 152: Combinatorics - Routledge

Chapter 2

Fundamentals of Enumeration

In this chapter we explore some applications of the two principles that wereintroduced in Section 1.3.

2.1 Permutations and Combinations

In practice, two particular applications of the Multiplication Principle arisemany times. Because of this, they have their own notations.

Example 2.1: An antiques dealer has twelve different pieces of iridescentglass and wishes to display five pieces in a window display. In how many wayscan she arrange five of the twelve pieces in some order in the window?

Since there are twelve pieces to choose from, she has 12 ways to put a piecein the first spot. There are 11 ways to put a piece in the second spot (becauseafter the first piece has been placed, only 11 remain); 10 for the third; and soforth. The Multiplication Principle tells us that the total number of ways is12× 11× 10× 9× 8 = 95, 040. �

This argument may be generalized nicely. We assume that the reader isaware that a permutation is an ordered subset, and a combination is an un-ordered subset, of a set.

THEOREM 2.1 (Counting Permutations)The number of ways to arrange k objects in order from a set of n objects isn!/(n− k)!, commonly denoted P (n, k) or [n]k.

Proof. There are n possible choices for the first object, (n−1) for the second,and so forth, until we find that there are n−k+1 possible choices for the kthobject. The Multiplication Principle tells us that there are n(n−1) . . . (n−k+1) arrangements altogether. When we divide n! by (n − k)!, this is preciselythe result. �

Example 2.2: How many ways are there for an awards committee toaward three distinct scholarships among 12 students entered?

27

Page 153: Combinatorics - Routledge

28 Introduction to Combinatorics

The formula gives us at once 12!/9! = 1, 320. �

We wish to ask what happens if we do not wish to order the k chosenobjects. Thus, if we have three (identical) scholarships and 12 students, howmany ways can we award the scholarships? The answer will be much smallerthan the 1, 320 that we got for the previous example, because we do notdistinguish among scholarship winners. Thus, if students A, B, and C areselected to win a scholarship, that one case corresponds to six cases in thelast example; for we might have A first, then B and C last, or A, then C, thenB, and so on. Because there are three winners, there are 3! ways to orderthem. We can employ the Multiplication Principle by asking how many waysthere are to order the three students. Let the number of ways to choose 3 of 12students be denoted

(123

)or C(12, 3). Both notations are commonly used; we

say “12 choose 3.” Then there are C(12, 3) ways to choose the students, and3! ways to order the chosen students; this says that C(12, 3)× 3! = P (12, 3).It follows that C(12, 3) is just P (12, 3)/3! = 220. This example also may begeneralized.

THEOREM 2.2 (Counting Combinations)The number of ways to choose k objects from a set of n distinct objects is(nk

)= n!/(k!(n− k)!), also commonly denoted C(n, k).

Proof. By Theorem 2.1, there are P (n, k) ways to choose k elements in aparticular order, and there are k! ways of ordering the given k elements. Itfollows that

(nk

)× k! = P (n, k), and dividing by k! completes the proof. �

Example 2.3: An automobile manufacturer produces eight models ofsports car. In how many ways can we choose three models to be blown upduring the exciting climax of our next action movie?

The solution is(83

)= 8!/(3!·5!) = 56. �

Example 2.4: A school decides to offer a new bioinformatics program,and decides to appoint a committee consisting of two mathematicians, threebiologists, and three computer scientists to plan the implementation. If thereare six mathematicians, ten biologists, and five computer scientists availableto serve on this committee, in how many ways can the committee be formed?

There are six mathematicians who could serve and we must choose twoof them; this may be done in C(6, 2) = 15 ways. We select the biologistsin one of C(10, 3) = 120 ways. The computer scientists are chosen in oneof C(5, 3) = 10 ways. By the Multiplication Principle, we have a total of15× 120× 10 = 18, 000 possible committees. �

Example 2.5: For the new bioinformatics program of the previous exam-ple, we find that Dr. John Walters of computer science and Dr. Walter Johns

Page 154: Combinatorics - Routledge

Fundamentals of Enumeration 29

of mathematics cannot serve together due to their tendency to become dis-tracted and make dreadful puns during committee deliberations. How manycommittees are there that contain at most one of these two individuals?

We could calculate the answer by doing cases, but it is easier to subtract thepossible committees that contain both these professors. The committees thatcontain both involve a choice of one of the five mathematicians in additionto Dr. Walter Johns, two of the four computer scientists in addition to Dr.John Walters, and three biologists. There are C(5, 1)·C(10, 3)·C(4, 2) = 3, 600such committees. We subtract these from the 18, 000, so we have 18, 000 −3, 600 = 14, 400 possible committees. You should observe that we get the sameresult from calculating that there are C(5, 2)·C(10, 3)·C(4, 3) committees thatcontain neither professor, C(5, 2) ·C(10, 3) ·C(4, 2) committees that containJohn Walters but not Walter Johns, and C(5, 1)·C(10, 3)·C(4, 3) that containWalter Johns but not John Walters, and then adding the results. �

2.2 Applications of P (n, k) and

(n

k

)

Here we discuss some problems whose solutions involve counting permu-tations and combinations, as well as a generalization of the concepts. Inparticular, the student is probably aware that the symbol C(n, k) is calleda binomial coefficient . A “subscripting technique” proves the theorem thatexplains this name.

THEOREM 2.3 (The Binomial Theorem)

(x+ y)n =

n∑

k=0

(n

k

)xkyn−k

Proof. We write the product as (x1 + y1)(x2 + y2) . . . (xn + yn). Then eachterm of the product will be of the form a1a2 . . . an−1an, where each a is eitheran x or a y. To find a term that will contribute to the coefficient of xkyn−k,we need for k of the as to be x and the other n−k of them to be y. There areclearly

(nk

)ways to pick k of the as to be x. Removing the subscripts means

that we can collect all such terms together to get(nk

)xkyn−k. This works for

each value of k from 0 to n. �

COROLLARY 2.3.1 (n

k

)=

(n

n− k

)

Page 155: Combinatorics - Routledge

30 Introduction to Combinatorics

Proof. Clearly (x+ y)n = (y + x)n. �

COROLLARY 2.3.2

n∑

k=0

(n

k

)= 2n

Proof. Set x = y = 1 in Theorem 2.3. �

COROLLARY 2.3.3

n∑

k=0

(−1)k(n

k

)= 0

Proof. Set x = 1 and y = −1 in Theorem 2.3. �

There are many other identities and formulas related to binomial coeffi-cients. Some of these are explored in the exercises and problems. We mentionone last identity as it is important.

THEOREM 2.4 (Pascal’s Identity)

(n− 1

k − 1

)+

(n− 1

k

)=

(n

k

)

Combinatorial identities often have two or more kinds of proofs. One kindof proof for a theorem such as this is the algebraic proof, where we simplywrite both sides of the equation, expand in factorials, and transform one sideinto the other by means of elementary (and reversible) algebraic operations.Another approach is to use a combinatorial proof, which involves showingthat each side of the equation counts the same set, or counts sets betweenwhich a bijection exists. The combinatorial proof is often preferred becauseit provides greater insight into the meaning of the identity.

Proof. Consider a set of n distinct objects, one of which we distinguish witha label of some kind from the others. We count the number of ways to selectk of these objects. Clearly, there are

(nk

)ways to do this. Now, if we wish to

separate these subsets of size k according to whether or not they contain thedistinguished object, how many of each kind are there? The sets containingthe distinguished object may be formed by taking the object and choosingk − 1 of the remaining objects of the n− 1; so there are

(n−1k−1

)subsets of size

k that contain our distinguished element. Similarly, if we do not include the

Page 156: Combinatorics - Routledge

Fundamentals of Enumeration 31

distinguished object, there are(n−1k

)ways of choosing k objects from the n−1

not-distinguished objects. Since every subset either does or does not containthe distinguished object, the identity follows. �

This method of proving an identity is sometimes called the distinguishedelement method. We will see many other identities proved in this way.

Binomial coefficients are usually presented in a triangular array, called Pas-cal’s Triangle (although it certainly predates Pascal; see [16] or [24], whichspecify earlier Chinese, Indian, and European sources). In the figure below,the entry in row n and column k is

(nk

).

n\k 0 1 2 3 4 5 60 11 1 12 1 2 13 1 3 3 14 1 4 6 4 15 1 5 10 10 5 16 1 6 15 20 15 6 1

Example 2.6: Suppose we live at the lower-left corner of the diagram ofFigure 2.1, and we need to walk to the upper-right corner along the streetsrepresented by the vertical and horizontal lines. In how many ways can wemake this walk? We assume that we never take shortcuts through parkinglots or other open areas, and each block is walked either north or east (so wenever retrace our steps or detour south or west).

FIGURE 2.1: How many ways to walk?

We may describe our path by a string of 12 characters, each of which iseither N or E to represent the direction we take. So if we start our stringwith “NNEE,” this would indicate that we first walk two blocks north andthen walk two blocks east. The string “EEEEEEENNNNN” indicates thatwe walk 7 blocks east along the southernmost street, then turn left and walk5 blocks north to reach our goal. Thus, our path is a string of 12 characters,

All

All

All

Page 157: Combinatorics - Routledge

32 Introduction to Combinatorics

of which 7 must be “E” and 5 must be “N.” How many such strings are there?Clearly C(12, 5) = 792. �

Example 2.7: In how many ways can we make this walk if we determineto walk along the block marked b1 in Figure 2.1? How many ways if the blockmarked b1 is blocked off and we must avoid it?

The first question is simple enough; to guarantee we walk along block b1,we must walk from our starting point (denoted (0, 0)) to the westmost pointof the block (at (2, 2)); then walk from the end of that block (at (3, 2)) toour destination at (7, 5). The Multiplication Principle gives us the number ofways to do this; it is C(4, 2)·C(7, 3) = 210.

The second question requires us to take the 792 total ways to walk fromone corner to the other and subtract the 120 ways that entail walking downblock b1; this gives us 582 ways to walk without going down block b1. �

We will see other problems involving counting lattice paths like this else-where in the book. You should also see the exercises and problems at the endof the chapter that make use of the blocks labeled b2 and b3.

2.3 Permutations and Combinations of Multisets

Theorem 2.2 tells us how to select some k items from a set of n items. Itis also possible that we wish to select more than one “copy” of some items.

Example 2.8: Consider the two questions: How many ways can we rear-range the letters of the word KEPT? How many distinct rearrangements arethere of the word KEEP?

The first question is simple. Because there are four distinct letters, we mayarrange them in 4! different ways, using Theorem 2.1. The second question,however, requires some effort. We begin by using subscripts, as we did inthe proof of Theorem 2.3. The word KE1E2P now consists of four distinctsymbols, and there are accordingly 4! distinct rearrangements. However, whenwe remove the subscripts, there are 2! ways of permuting the two Es. Thus, wehave 4!/2! = 12 rearrangements. This is a small enough number we can checkby listing them explicitly. We find EEKP, EEPK, EKEP, EKPE, EPEK,EPKE, KEEP, KEPE, KPEE, PEEK, PEKE, and PKEE. Each of these turnsinto two permutations if we leave the subscripts on the Es. �

Example 2.9: In how many distinct ways can we rearrange the letters ofMADAM IM ADAM ?

Page 158: Combinatorics - Routledge

Fundamentals of Enumeration 33

There are 11 letters, of which four are M, 4 are A, two are D, and one is I.Thus, we have 11!/(4!·4!·2!·1!) = 34, 650. We divide by 4! for the Ms, 4! forthe As, and 2! for the D. �

Example 2.10: In almost every combinatorics textbook, the reader isshown the number of distinct ways to rearrange the letters of the word MIS-SISSIPPI. How many ways are there?

Since there is one M, four each of I and S, and two Ps, we get 11!/(1!4!4!2!)or 34, 650. �

THEOREM 2.5 (Permutations of Multisets)The number of distinct permutations of n objects of r types, with k1 objectsof the first type, k2 of the second, and so on, where two objects of the same

type are considered identical, isn!

k1!k2! . . . kr!.

Proof. As in the preceding example, we apply subscripts to all objects of agiven type, so that we have n distinct objects. This gives us n! ways to arrangethe distinct objects. Now, we divide by k1! to enumerate the ways in whichthe objects of the first type might be rearranged, and by k2! to rearrangeobjects of the second type, and so on. The result follows. �

This theorem may be described as a theorem about permutations of mul-tisets; the reader will recall that in Chapter 1, we described a multiset asbeing able to contain more than one “copy” of a given element. Thus, PEEKcontains one P, one K, and two copies of E. Theorem 2.5 counts the numberof permutations of a multiset.

The binomial theorem may be generalized to powers of more involved sums.We define n!/(k1!k2! . . . kr!) where k1 + k1 + . . . kr = n to be the multinomialcoefficient

(n

k1k2...kr

).

THEOREM 2.6 (The Multinomial Theorem)

(x1 + x2 + · · ·+ xr)n =

k1+k1+···+kr=n

(n

k1 k2 . . . kr

)xk1

1 xk2

2 . . . xkr

r

where the sum is over all ways to write n as a sum of non-negative integersk1 + k2 + · · ·+ kr.

The proof is similar to that of Theorem 2.3 and is omitted. �

Here we look at a problem whose solution involves(nk

). Ordinarily,

(nk

)

counts the number of ways of selecting k of n distinct elements. We wish todivide up n identical objects into k distinct classes.

Page 159: Combinatorics - Routledge

34 Introduction to Combinatorics

Example 2.11: If we are given a dozen identical chocolate eggs and wishto arrange them into four distinct Easter baskets, in how many ways can wedo this? In how many ways can we do this if each basket is to receive at leastone egg?

We are not concerned with fairness; we might give all twelve eggs to onebasket, for instance, and do not need to put three eggs in each. Because thebaskets are distinct, a solution in which all 12 eggs go into the first basket isdifferent from one in which all 12 go into the second, third, or fourth baskets.We set this problem up by lining up the twelve eggs, and inserting threedividers between eggs to indicate which eggs go into which basket. Thus adiagram like this indicates three eggs in each basket:

OOO|OOO|OOO|OOO

If all twelve eggs were to go into the first basket, the diagram would be this:

OOOOOOOOOOOO|||

Each vertical divider separates the eggs that go into one basket from theeggs that go into the next. A little thought will reveal that each diagramcorresponds to a distinct way to arrange the eggs, and each arrangementof eggs is represented by exactly one diagram. Thus we have a one-to-onecorrespondence between diagrams and ways to arrange the eggs, and we maycount the diagrams to solve the problem.

How many diagrams are there? With 12Os and three |s, we have 15 symbolsaltogether; and three of these symbols must be |. There are

(153

)= 455 ways

to arrange the eggs. Now, if each basket must contain at least one egg, wemerely place one of our twelve eggs into each basket. This leaves us 8 eggsand four distinct baskets (each with an egg in it), and we repeat the problemby taking 8 eggs and three dividers, to get

(113

)= 165 ways. �

We use the reasoning of the foregoing examples to establish the next theo-rem.

THEOREM 2.7 (Sorting Identical Objects into Distinct Classes)We can sort n identical objects into k distinct classes in

(n+k−1k−1

)ways.

Proof. We create a string of length n+k−1 that will consist of n objects andk − 1 dividers. The ith divider will separate the objects that go into class ifrom the objects that go into class i+1. Because there are C(n+k− 1, k− 1)such strings, there are C(n+ k − 1, k − 1) ways to separate the objects. �

Example 2.12: We are organizing a party for small children and need tobuy 18 party hats; the store has 5 different designs. In how many ways canwe select 18 hats, assuming any hats with the same design are identical andthe store has an unlimited number of hats of each design?

Page 160: Combinatorics - Routledge

Fundamentals of Enumeration 35

At first glance, this problem does not appear to be solvable using the the-orem. However, with a little thought we can see that it may be stretched toapply. Imagine that we have 18 identical hat boxes, and we wish to place thehat boxes into one of five categories depending on the design of hat that it willhold. Then by Theorem 2.7 there are C(18+ 5− 1, 5− 1) = C(22, 4) = 7, 315possibilities. �

This example illustrates an idea that arises often enough in different con-texts that it deserves its own theorem. Just as Theorem 2.5 dealt with thepermutations of a multiset, this deals with combinations of a multiset.

THEOREM 2.8 (Combinations of Multisets)The number of ways of selecting n (not necessarily distinct) items from aset of k distinct items where there is no limit on the number of repetitions isC(n+ k − 1, k − 1).

Proof. We imagine n boxes. Each box is to hold one item, and each is to beclassified into one of k classes, depending on which kind of item the box is tohold. Again, we use Theorem 2.7 to show that there are C(n+k−1, k−1) waysin which to classify the boxes. We fill each box with a copy of the object ofthat type, and after discarding the boxes, we have our desired combination.There is clearly a bijection between the ways to classify the boxes and theways to select the items from the multiset. �

Another common counting problem is that of cyclic permutations. Supposewe wish to seat n people at a round table with identical seats. At first glance,this laudably Arthurian arrangement might be accomplished by lining upour people in one of the n! possible ways, and simply seating them in order.However, this actually overcounts the number of ways to seat people. Supposewe moved each person one or more places to the left. This would be the sameseating arrangement, because the same people would be seated next to eachother. Since there are n ways to choose the seat where a selected person sits,and any of the n seating arrangements we obtain by rotating people left orright are equivalent, we see that there are actually n!/n = (n − 1)! distinctcyclic seating arrangements.

Example 2.13: Suppose that we are to seat 10 children at a circular table.First of all, in how many distinct ways can this be done? In how many if twoof the children are siblings and always sit next to one another? In how many,if two of the children are mischievous siblings who on no account may sit nextto one another if sanity is to be preserved?

The first question is a simple matter of applying the formula; there are10!/10 = 9! = 362, 880 distinct seatings. The second question takes somemore thought. Suppose we “glue” the siblings c0 and c1 together into a singleunit. We may do this in two distinct ways; we may glue them so that c0

Page 161: Combinatorics - Routledge

36 Introduction to Combinatorics

is on c1’s left, or on c1’s right. Having done this, we have the two siblingsas one unit, so there are 9 “units” to be seated in a circle. We arrive atthe figure 2 ·8! = 80, 640 by the Multiplication Principle. Finally, to countthe arrangements in which the children are kept separate, we subtract fromthe total number of arrangements the arrangements in which the children areadjacent; this leaves 282, 240 arrangements. �

There are very many works that discuss the uses of binomial coefficients,identities involving them, and interesting uses. Among others, the reader maybenefit from [41] and [63].

2.4 Applications and Subtle Errors

We introduce a number of counting problems by use of a standard deckof playing cards. There are four suits (clubs, diamonds, hearts, and spades);each suit consists of thirteen ranks, the ace (or one), the deuce (or two), thetrey (three), the four through ten, the jack, the queen, and the king. Manycard games involve sets (hands) of varying numbers of cards; for instance,bridge consists of four hands of thirteen cards each and draw poker consists ofa variable number of hands of five cards each. We will consider some subtletiesof counting using cards and similar devices.

Example 2.14: For instance, one poker hand is known as two pair ; thismeans that of the five cards, we have two cards of one rank (say, the eightof clubs and the eight of diamonds); two cards of a different rank (such asdeuces of clubs and spades); and a fifth card of a different rank (say, jack ofclubs). How many such hands are there?

An unsuspecting student might reason as follows: We have thirteen waysto select the rank of the first pair; that is

(131

)or 13. Once we have chosen

that rank, we choose the suit of the first card of that rank; there are foursuits. Then we choose the suit of the second card of that rank, with threesuits left. Then there are twelve ways to select the rank of the second pair,four choices for the suit of the first card, and three for the suit of the secondcard. Finally, there are 11 ranks left for the fifth card, and four possiblesuits for that card. Applying the Multiplication Principle, we appear to have13× 4× 3× 12× 4× 3× 11× 4 or 988, 416. This is tragically wrong!

To see why this does not work, let us see how the sample hand given abovemight be selected. We might choose an 8 of the thirteen ranks, then choosea club for the first suit, then a diamond for the second. Then we mightchoose a deuce from the 12 remaining ranks, and choose club for our first suit(from four possibilities) and spade for our second (from the three remaining).

Page 162: Combinatorics - Routledge

Fundamentals of Enumeration 37

Finally, of the 11 remaining ranks, we would choose the jack and choose clubsfrom the four possible suits.

Suppose instead we chose a deuce first, and chose a spade for the first suitand a club for the second. Then we chose an 8, and chose a diamond for thefirst suit and a club for the second. Then we again chose the jack and clubs forthe fifth card. Notice that, even though we made distinctly different choices,we still obtain the same hand! This means that each possible hand is beingcounted more than once.

How might we choose this hand correctly? The problem arose because thepoker hand does not care whether the eight or the deuce was dealt first; andit makes no difference for the eight whether we choose diamonds or clubs first.Thus, we must choose both pairs at once. Now consider that we want tworanks for our two pairs, and we wish to choose them from the thirteen ranksavailable; that is

(132

)or 78. Now we choose two suits for one of the pairs; we

can do this in(42

)or 6 ways. Another

(42

)selects the two suits for the second

pair. Now, as before, we have 11 ranks remaining and four suits for each rank.Now our total is 78× 6× 6× 11× 4 or 123, 552. This is exactly one-eighth ofthe total we had before (and is correct). �

Example 2.15: A flush is a poker hand in which each of the five cards isof the same suit; a straight flush is a flush in which the cards are consecutive,as the 4, 5, 6, 7, and 8 of clubs. A royal flush is a straight flush consisting ofthe 10 through ace. How many of each of these hands are there?

Clearly, there are only four royal flushes; one for each suit. (The royal flushis the strongest hand in poker because it is the rarest.) How many straightflushes are possible if we do not count royal flushes? We count according tothe lowest card. The ace may be the lowest or the highest card, so a straightflush may have as its lowest card ace, deuce, trey, and on through 9. Since astraight flush is entirely determined by its lowest card, and since there are 9possible lowest cards in each of 4 suits, we have 4 × 9 = 36 straight flushesthat are not royal flushes. Finally, to count flushes, we choose a suit in 4ways; we choose five cards from that suit in

(135

)ways; and we subtract the

straight and royal flushes from this total. This gives us 5, 108 possible flushesthat are not straight flushes or royal flushes. �

Example 2.16: A hand of bridge consists of 13 cards; each player hasa partner. How many possible ways are there for a player and that player’spartner to have two hands? Assume it makes no difference if the playersexchange hands.

There are(5213

)possible bridge hands for the player, and the player’s partner

can then have(3913

)possible hands from the remaining cards. We count the

configuration as the same if the two players switch hands, so the correct answeris half the product of these two numbers, 1

2

(5213

)(3913

), or about 2.6× 1021. �

Page 163: Combinatorics - Routledge

38 Introduction to Combinatorics

Closely tied to the concept of set enumeration is the concept of probability.We shall discuss probability in the next Chapter.

2.5 Algorithms

Because permutations have such a broad range of applications, we presenttwo algorithms that may be used to generate permutations. Easy modifica-tions of these algorithms may be used to produce particular kinds of permu-tations, or to produce combinations. The first algorithm will produce a listof all n! permutations on n letters.

Permutation-Generating algorithm: If n = 1, then return the listconsisting only of the letter a1. If n > 1, then use the algorithm to generatethe list of all permutations on n − 1 letters, using the symbols a1, . . . an−1.Make n copies of each permutation on this list. For each permutation, thereare n places where the new symbol an may be placed (before the first symbol,between the first and the second, and so on until it is placed at the end). Forthe ith copy of this permutation, place an in the ith position, and repeat untilall permutations have been treated this way.

This will become clearer with an example. Consider the case n = 2; weuse the algorithm to generate all permutations consisting of one letter, and wemake n copies of this permutation. This gives us two copies of the permutationa1.

The first copy gets an a2 in front; the second copy gets an a2 behind it. Thisgives us the two permutations a2a1 and a1a2, which are all the permutationson two letters. Now we will work through the case of n = 3 in more detail.

The algorithm has given us both permutations on two letters, and we makethree copies of each, which we display in the diagram below.

a1 a2a1 a2a1 a2

a2 a1a2 a1a2 a1

We now interleave the a3 (boldfaced for clarity) within each to generate allsix permutations on three letters.

a3 a1 a2a1 a3 a2a1 a2 a3

a3 a2 a1a2 a3 a1a2 a1 a3

The result is the set of six permutations on three letters. This algorithm isfairly well known, and is discussed in, among other sources, [43] and [13]; ourapproach follows that of Brualdi[13].

Often, what is desired is not the set of all permutations on n letters, butjust one, perhaps chosen at random. While this could easily be accomplishedwith the foregoing algorithm (merely generate all n! permutations on n letters

Page 164: Combinatorics - Routledge

Fundamentals of Enumeration 39

and select one at random), the time and space required for even moderate-sized values of n is prohibitive. Accordingly, we present an algorithm to selecta permutation on n letters at random.

Random permutation algorithm: Create a list of all n letters inany order. Each letter is unmarked. Now, for each i between 1 and n, choosean unmarked letter at random. Now, place that letter in position i of thepermutation and mark the letter in the list. Continue until all letters havebeen chosen. No letter may be used twice because at each step the selectedletter is marked so that it cannot be chosen at a later step.

Exercises 2A

1. A program for generating random computer passwords gives one lower-case letter, one upper-case letter, two digits (0 through 9), and threeletters that may be upper-case or lower-case. How many possible pass-words can this program produce?

2. At one time, area codes were three-digit numbers with the second digit0 or 1 and the first digit greater than 1. How many area codes werepossible under this system? How many are possible if we don’t allow 1sin both the second and third digit (so as not to conflict with 911, 411,etc.)?

3. A bookstore has a large box of very old books from an estate sale, andthe owner wishes to display one book from the box in each of five windowdisplays. If there are 24 books in the box, how many ways can this bedone?

4. A number is called a palindrome if its digits read the same forwards asbackwards.

(i) Find the number of palindromes on seven digits.

(ii) Find the number of seven-digit palindromes that have no digit ap-pearing more than twice.

5. How many of the first million positive integers contain exactly one 3,one 5, and one 7?

6. A student decides that time is available to join no more than one socialnetworking site. Of four sites recommended, the student has three ac-quaintances on the first, five on the second, six on the third, and four onthe fourth. Once joined to any site, the student has for each acquain-tance the option to befriend or not to befriend that acquaintance. How

Page 165: Combinatorics - Routledge

40 Introduction to Combinatorics

many possible outcomes are there of the process of choosing a site andbefriending or not befriending each acquaintance on the site?

7. A student decides that time is available to join exactly two social net-working sites. Of four sites recommended, each has four of the student’sacquaintances. Once joined to a site, the student has for each acquain-tance the option to befriend or not to befriend that acquaintance. Howmany possible outcomes are there of the process of choosing two sitesand befriending or not befriending each acquaintance on the site? As-sume that the acquaintances on each site are different.

8. A student decides that time is available to join exactly two social net-working sites. Of four sites recommended, two have four of the student’sacquaintances, and two have five. Once joined to a site, the student hasfor each acquaintance the option to befriend or not to befriend thatacquaintance. How many possible outcomes are there of the process ofchoosing two sites and befriending or not befriending each acquaintanceon the site? Assume that the acquaintances on each site are different.

9. A student wishes to celebrate with a good friend. She has four friendsfrom which to choose, and one of these friends is under the age of 21.The restaurants that she may choose from include three that do notserve anyone under 21 due to state liquor laws, and four with no suchrestriction. How many possible ways can the student celebrate assumingshe takes only one friend out? How many ways if she can afford to taketwo of her friends out?

10. There are six tutors who are available to handle the 2:00 PM shift atthe Tutoring Center. In how many ways can we select three to assignto that shift?

11. Compute P (6, 2), P (7, 2), and P (8, 2).

12. Find the row of Pascal’s triangle corresponding to n = 7.

13. Use Pascal’s triangle to expand the expression (x2 + x−1)5.

14. Show that∑n

k=1(−1)k−1(nk

)= 1 when n is a positive integer.

15. Refer to Figure 2.1. Compute the number of ways to walk from thesouthwest corner to the northeast corner if we require that we passalong block b2. Use this result to count the number of ways if block b2is closed off and cannot be entered.

16. In how many distinct ways can we arrange the letters in the phraseSLEEPING STEEPLES?

17. Use the multinomial theorem to expand (3x+ 5y + 7z)3.

Page 166: Combinatorics - Routledge

Fundamentals of Enumeration 41

18. We wish to distribute 10 identical memory cards among three teen-agersfor use in their tablet computers. In how many ways can we do this? Inhow many ways if each of the teenagers is to get at least one memorycard?

19. A popular brand of mobile phone cover comes in eight different colors.We wish to buy three covers. In how many ways can we do this if anytwo covers of the same color are considered identical?

20. Using the permutation-generating algorithm to generate all permuta-tions of {1, 2, 3, 4, 5, 6}, which permutation precedes 356142? Whichone follows it? Which follows 415326?

Exercises 2B

1. A program for generating computer passwords produces two lower-caseletters, one upper-case letter, three digits, and two letters that maybe either upper-case or lower-case, in that order. How many possiblepasswords can this program generate?

2. A game store has 10 new games; the manager wants to devote each ofthree distinct displays, one to each of three of the new games. How manyways can the manager select three games, one for each of the displays,in order?

3. At one time, seven-digit telephone numbers never had a zero or a onein the first three digits. How many telephone numbers (without areacode) are possible in this system? How many are possible given that wecannot have any beginning with 555 or with the second and third digitsbeing 11 (so as not to conflict, for instance, with 911 or 411)?

4. Find the number of 5-digit numbers with no repeated digits.

5. Palindromes were defined in Exercise 2A.4. Find the number of palin-dromes on 10 digits.

6. A binary sequence is a sequence of 0s and 1s. Find the number of binarysequences of length n that have an even number of elements 0.

7. There are eight tutors available to handle the 4:00 PM shift at theTutoring Center. In how many ways can we choose three of them toassign to that shift?

8. Compute P (5, 3), P (6, 3), and P (7, 3).

Page 167: Combinatorics - Routledge

42 Introduction to Combinatorics

9. Find the row of Pascal’s triangle corresponding to n = 8.

10. Use Pascal’s triangle to expand the expression (2x2 + 1)4.

11. Refer to Figure 2.1. Compute the number of ways to walk from thesouthwest corner to the northeast corner if we require that we passalong block b3. Use this result to count the number of ways if block b3is closed off and cannot be entered.

12. How many distinct rearrangements of the letters SNIP TIN NIT PINSare there?

13. Use the multinomial theorem to expand (x+ 2y + 3z)3.

14. There are seven identical memory cards that we wish to distributeamong four teenagers for use in their MP3 music players. In how manyways can we do this? In how many ways if each of the teenagers is toget at least one memory card?

15. A popular brand of pocket calculator comes in five different colors. Wewish to buy four calculators. In how many ways can we do this if anytwo of the same color are considered identical?

16. Using the permutation-generating algorithm to generate all permuta-tions of {1, 2, 3, 4, 5, 6}, which permutation follows 2436135? Which oneprecedes it? Which precedes 641253?

Problems

Problem 1: Find the total number of integers with distinct digits.

Problem 2: Palindromes were defined in Exercise 2A.4. Prove that anypalindrome of even length is divisible by 11.

Problem 3: Prove the Vandermonde Convolution:

(n+m

k

)=

k∑

i=0

(n

i

)(m

k − i

)

Problem 4: Find a combinatorial proof of the identity:

k

(n

k

)= n

(n− 1

k − 1

)

Page 168: Combinatorics - Routledge

Fundamentals of Enumeration 43

Problem 5: Find an algebraic proof of the identity:

k

(n

k

)= n

(n− 1

k − 1

)

Problem 6: Find a four-letter and a five-letter word where the five-letterword has fewer distinct rearrangements than the four-letter word. (It is evenpossible to find two such words with similar meanings!)

Problem 7: Prove the identity:

k odd

(n

k

)=

k even

(n

k

)

Problem 8: Show that the number of odd-order subsets of a set of n elementsis 2n−1. Use this result to find the number of even-order subsets.

Problem 9: Using Figure 2.1, find the number of ways to walk from thesouthwest to the northeast corner if we must pass through block b1 but cannotpass through b2.

Problem 10: How many distinct ways are there to rearrange the letters ofthe phrase:

(i) BANDS BAN BANDIT BRAND BANDANAS?

(ii) THE SIXTH SHEIK’S SHEEP’S SICK ?

Problem 11: We have four Republicans and four Democrats who wish tosit at a round conference table to discuss a bill. In how many ways can theybe seated? In how many ways can they be seated if we require that no twocompatriots (Republicans or Democrats) sit next to each other? How manyways can we seat four Republicans, four Democrats, and an Independent ifno members of the same party sit next to each other?

Problem 12: We have n pairs of twins. In how many ways can we choose acommittee of n− 1 people from this set of 2n people so that no pair of twinsboth serve on the committee?

Problem 13: This problem is for those of you who have been wondering atthe improbably small numbers in problems and exercises up to now. “Whatkind of person,” you ask, “would only have five tunes on a digital music playerthat can hold 3000 tunes? Who on Earth only knows four people with whomthey would go to a restaurant?” Very well, then, try this.A student wishes to take two of her 10 friends to a restaurant to celebrate;three of these friends are vegetarian, and two insist on eating meat. Of the 10restaurants available, three are vegetarian only and two do not offer enoughvegetarian entrees to interest her vegetarian friends. How many ways can

Page 169: Combinatorics - Routledge

44 Introduction to Combinatorics

she take two of her friends out to celebrate without violating any of theserestrictions?

Problem 14: Modify the algorithm that produces a random permutation onn letters to obtain an algorithm to produce a random permutation of k of then letters, for any given k ≤ n.

Problem 15: Produce an algorithm to choose a random subset of order k ofa set of n letters.

Page 171: Combinatorics - Routledge

1

1C H A P T E R

What’s It All About?

1.1 WHAT IS COMBINATORICS?Mathematics is a problem-solving activity, and the ultimate source of most mathemat-ics is the external, nonmathematical world. Mathematical concepts are developed to help us tackle problems arising in this way. The abstract mathematical ideas that we use soon assume a life of their own and generate further problems, but these are more technical problems whose connection with the external world is more remote.

Since the time of Isaac Newton and until quite recently, almost the entire emphasis of applied mathematics has been on continuously varying processes, modeled by the mathe-matical continuum and using methods derived from the differential and integral calculus. In contrast, combinatorics concerns itself mainly with finite collections of discrete objects. With the growth of digital devices, especially computers, discrete mathematics has become more and more important.

The way mathematics has developed creates a difficulty when it comes to teaching and learning the subject. It is generally thought best to begin with the most basic ideas and then gradually work your way up to more and more complicated mathematics. This seems more sensible than being thrown in at the deep end and hoping you will learn to swim before you drown. However, this logical approach often obscures the historical reasons why a particu-lar mathematical idea was developed. This means that it can be difficult for the student to understand the real point of the subject.

Fortunately, combinatorics is different. The starting point usually consists of problems that are easy to understand even if finding their solutions is not straightforward. They tend to be concrete problems that can be understood by those who do not know any technical mathematics. In this chapter we list a number of these problems that gave rise to much of the mathematics explained in the remainder of this book.

So what sorts of problems does combinatorics address? As combinatorics finds its ori-gins in statistical, gambling, and recreational problems, a rough answer is: anywhere where knowing “How many?” (the answer to which may be “zero”) is of interest. So, for example, the techniques we describe (or generalized versions of them) have been used in design of experi-ments, for example, the testing of crops (statistics), design of traffic routes (graph theory),

Page 172: Combinatorics - Routledge

2    ◾    How to Count: An Introduction to Combinatorics, Second Edition

construction of codes, arrangements of meetings (permutations and combinations), placing of people in jobs (rook polynomials), determination of certain chemical compounds (graph theory), production and school teaching schedules, as well as increasingly in mathematical biology in relation to the DNA code. There are also applications within mathematics, espe-cially in the theory of numbers, and within computing, where questions of speed and com-plexity of working are important. Among recreational puzzles with a combinatorial flavor are the well-known Rubik’s Cube, “magic” squares, Lucas’s Tower of Hanoi, and the famous problem that was the origin of graph theory, that of crossing the bridges of Königsberg.

In many problems, not only a solution but an “optimal” solution is sought. For example, it would seem desirable to seek to maximize factory output or traffic flow or to minimize factory or computing costs or travel cost (by choosing the shortest route when visiting a succession of towns; this is the well-known traveling salesman problem). These aspects indicate the three basic problems of combinatorics: counting the number of solutions, checking existence (is there even one solution?), and searching for an optimal solution.

In this general introductory book we are not able to go into any of these topics in any great depth. Our aim is to give the reader the flavor of a broad range of interesting combi-natorial ideas. At the end of the book we make suggestions for further reading where many of these ideas can be followed up.

1.2 CLASSIC PROBLEMSIn this section we list a number of classic and other interesting combinatorial problems that, later in the book, we show you how to solve. Many of these problems have been around for a long time. Accordingly, in most cases we have not tried to attribute the problems to their authors. Nevertheless, the present authors would be grateful for any enlightenment readers wish to provide in this regard.

We have selected at least one problem for all but one of the subsequent chapters, and our numbering of them matches the chapter numbers. So our first problem is called “Problem 2A” to indicate that it relates to Chapter 2 and is the first problem listed here from that chapter.

Many combinatorial problems arise from questions about probabilities. For, if a cer-tain event can produce a finite set of equally likely different outcomes, of which some are deemed favorable, then we say that the probability of a favorable outcome is the fraction

the number of favorable outcomesthe total nnumber of all outcomes

.

So we can work out probabilities by counting the number of outcomes in the two sets occurring in this fraction. This sort of counting is mostly what this book is about. For exam-ple, consider the probability problem: “When throwing two standard dice, what is the proba-bility that the total shown on the dice is 6?” The total number of outcomes when two dice are thrown is 36 as each face 1,2,3,4,5,6 on one die* can appear partnered by each one of the faces

* Being mathematicians, naturally we are pedantic. Although dice is often used as the singular term, strictly speak-ing, it is one die and two or more dice. Remember Julius Caesar’s remark as he crossed the Rubicon, “The die is cast” (“Iacta alea est”).

Page 173: Combinatorics - Routledge

What’s It All About?    ◾    3

1,2,3,4,5,6 on the other die. The outcome 6 can be achieved in five different ways, namely, 1 + 5, 2 + 4, 3 + 3, 4 + 2, and 5 + 1. So the answer to the probability problem is 5/36.

The first problem we list is rather more complicated but one of direct interest to anyone who “invests” their money in a lottery.

PROBLEM 2AWhat Is the Chance of a Jackpot?The operators of “Lotto,” the British National Lottery, advertize that each ticket has a 1 in 13,983,816 chance of winning a share of the jackpot. How is this probability calculated?

Next we have an old classic, whose answer usually comes as a surprise.

PROBLEM 2B�e Birthdays ProblemHow many people do you need to have in a room before there is a better than 50% chance that at least two people share a birthday?

While solving Problems 2A and 2B is fairly straightforward, some counting prob-lems are a bit more perplexing. Let us have a look at two involving food and money, the second being of rather more general interest than the first!

PROBLEM 3AHot ChocolatesA manufacturer of high-quality (and therefore high-priced) chocolates makes just six different flavors of chocolate and sells them in boxes of 10. He claims he can offer over 3000 different “selection boxes.” If he is wrong, he will fall foul of the advertizing laws. Should he fear prosecution?

PROBLEM 3BA Common OpinionThere is a widely held view that, in a truly random selection of six distinct numbers from among the numbers 1 to 49 (as in the British lottery), the chance that two con-secutive numbers will be chosen is extremely small. Has this opinion any credibility?

The solution to both of these problems relies on the same general principles used to solve the following purely arithmetic problem. Notice how much less “cluttered” and more transparent the arithmetic problem is without the “real-life” trimmings!

PROBLEM 3CCounting SolutionsHow many solutions does the equation x + y + z + t = 60 have where x, y, z, and t are positive integers?

If, in this problem, there were only, say, three unknowns x, y, and z and the 60 were replaced by a 6, there would be little difficulty, as we could easily list all the solutions

Page 174: Combinatorics - Routledge

4    ◾    How to Count: An Introduction to Combinatorics, Second Edition

systematically, that is, (1,1,4), (1,2,3), (1,3,2), (1,4,1), (2,1,3), (2,2,2), (2,3,1), (3,1,2), (3,2,1), and (4,1,1). So, there are exactly 10 of them.

That was easy. But what if we return to four unknowns and reintroduce the 60 or change it to 600? How many solutions then? It is clear that the same technique of listing all possible answers could be tried; the difficulty would seem to be in making sure you count all the solutions once and once only. To be sure, in the case where there are only three unknowns, it is not too difficult, even by the above method, to determine the number of solutions of each equation x + y + z + = n without actually listing any of them. But with more variables we surely need some new ideas. And after these new ideas are introduced in Chapter 3 you will be able to write down the answer to every problem of this sort (that is, with any number of variables and any n on the right-hand side) immediately.

In Chapter 3 we shall also see how Problem 3A can be reinterpreted as a problem of placing identical marbles in distinguishable boxes. This new point of view then gener-ates a host of fascinating problems known as occupancy problems, one slight variant of which is the intriguing but very difficult problem involving the partitions of an integer (see Problem 6 and Chapters 6 and 8).

Here is a probability problem whose answer would confound most people’s intuition.

PROBLEM 4Snap!Two fully shuffled standard packs of 52 cards are placed face down and side by side. One after another, pairs of cards, one from each pack, are turned over. What is the probability that, as all 52 pairs are turned over, at least one pair of cards will be identical?

If you have not seen this problem before, you will surely be intrigued by the answer. And for those who are happy to engage in a little gambling (neither of the authors does) there is a chance for readers with no conscience to use the counterintuitive result to make a little money on the side from their more susceptible friends! In Chapter 4 we introduce the inclusion-exclusion principle and show how it may be used to solve this problem.

Certain numbers arise in combinatorics so frequently that they often bear the names of their originators. The numbers that arise on putting distinct balls into identical cells, with no cell left empty, are named after James Stirling, who defined the Stirling numbers in a completely different context. Here is a problem from calculus (don’t worry if you haven’t yet met the ideas involved) to which the Stirling numbers provide an answer. We let θ be the operator x(d/dx). Thus θy = x(dy/dx), and

θ22

22y x d

dxx dy

dxx x d y

dxdydx

x d=

= +

=22

2

ydx

x dydx

+ ,

and you can check that, similarly,

θ3 33

32

2

23y x d y

dxx d y

dxx dy

dx= + + .

Page 175: Combinatorics - Routledge

What’s It All About?    ◾    5

PROBLEM 5ADi�erential OperatorsFind a formula for the coefficient of the term xk(dky/dxk) in θ ny, for 1 ≤ k ≤ n.

In Chapter 5 we also introduce the Catalan numbers, which arise in very many seemingly unrelated problems.

PROBLEM 5BWalking East and North!Suppose we have an n × n grid. How many paths are there, following edges of the grid, from the bottom left corner to the top right corner that may touch, but not go above, the diagonal shown in Figure 1.1?

Here is a problem that engaged the Swiss mathematician Leonhard Euler.* By a tri-angulation of a polygon, we mean a way of dividing the polygon in triangles by non-intersecting diagonals, that is, lines joining two vertices. For example, Figure 1.2 is an example of a triangulation of a regular hexagon.

* See Chapter 8, Section 8.2, for a brief biography of Euler.

FIGURE 1.1

FIGURE 1.2

Page 176: Combinatorics - Routledge

6    ◾    How to Count: An Introduction to Combinatorics, Second Edition

PROBLEM 5CChopping Up a HexagonHow many different triangulations are there of a regular hexagon?

A classic combinatorial problem is that of counting partitions. Here is a problem of this type.

PROBLEM 6PartitionsIn how many different ways can the number 100 be expressed as the sum of positive integers?

To make this question precise we explain that we are here interested only in which numbers make up the sum and not the order in which they are written. So, for example, we regard the sum 50 + 24 + 13 + 13 as representing the same way of expressing 100 as a sum of positive integers as does 13 + 24 + 50 + 13. We call 50 + 24 + 13 + 13 a parti-tion of 100, and we let p(n) be the number of different partitions of n. When n is small, the value of p(n) can be calculated by listing all the possibilities. For example, we can see that p(6) = 11, from the list

6,5 + 1, 4 + 2, 4 + 1 + 1, 3 + 3, 3 + 2 + 1, 3 + 1 + 1 + 1, 2 + 2 + 2, 2 + 2 + 1 + 1,

2 + 1 + 1 + 1 + 1, 1 + 1 + 1 + 1 + 1 + 1

of all the different ways of writing 6 as the sum of positive integers. Of course, to evalu-ate p(6) in this way, we need to be satisfied that we have included all the possibilities. And while it is feasible to evaluate p(6) in this way, it is hardly practicable for p(100).

All this raises the question of finding a formula for p(n). This problem was solved by two giants of mathematics, the Indian Srinivasa Ramanujan and the Englishman G. H. Hardy. Their proof is far too involved to reproduce in this book, but, in Chapters 6 and 8, we can experience a more modest sense of achievement by using some elementary cal-culus, believe it or not, to obtain fairly reasonable upper and lower bounds for p(n) and related functions. We shall also prove a lovely theorem that will enable you to calculate quite a large number of the smaller p(n) fairly quickly by hand and avoiding brute force!

Almost every mathematically inclined student will have heard of Fibonacci and his rabbits. At the heart of the story is the Fibonacci sequence 1, 1, 2, 3, 5, 8, 13, 21, 34, … in which each integer after the first two is the sum of the previous two. If we let fn be the nth term of this sequence, we can describe the sequence by saying that

f1 = f2 = 1 and, generally, for n ≥ 3, fn = fn–2 + fn–1.

The Fibonacci sequence has so many wonderful properties that a quarterly journal is produced to publicize them. One famous application is the test devised by Lucas* to

* Francois-Edouard-Anatole Lucas was born in Amiens on April 4, 1842, and died in Paris on October 3, 1891. He introduced the recreational game The Tower of Hanoi, which we discuss in Chapter 7. He died of an infection after being hit by a flying shard of a broken dinner plate.

Page 177: Combinatorics - Routledge

What’s It All About?    ◾    7

check whether or not a number of the form 2n – 1 is a prime. In 1876 he proved, with only pencil and paper but lots of patience, that the 39-digit number

2127–1  = 170,141,183,460,469,231,731,687,303,715,884,105,727

is prime. This number stood as the largest prime known to anyone until the 1950s when electronic calculators were applied to the task!

PROBLEM 7�e Fibonacci Numbers Is there a formula explicitly giving the values of the Fibonacci numbers?

The Fibonacci numbers are defined by the recurrence relation fn = fn–2 + fn–1, which relates later numbers in the sequence to earlier numbers in the sequence. We study recur-rence relations systematically in Chapter 7. One technique that is useful here is that of generating functions, which we describe in Chapter 8. This technique is particularly use-ful with some intriguing problems that arise if we place restrictions on the numbers that are allowed in a partition. Here is one suggested by experiments with small numbers.

PROBLEM 8Special PartitionsIs it true that for each integer n the number of ways of writing n as the sum of odd positive integers is the same as the number of ways of writing n as the sum of positive integers that are all different?

In the following table we have listed the partitions of 12 into odd numbers and into different numbers.

11 1

9 3

9 1 1 1

7 5

7 3 1 1

7 1 1 1 1 1

5 5 1 1

5

+

+

+ + +

+

+ + +

+ + + + +

+ + +

++ + +

+ + + + +

+ + + + + + +

+ + +

+

3 3 1

5 3 1 1 1 1

5 1 1 1 1 1 1 1

3 3 3 3

3 3++ + + +

+ + + + + + +

+ + + + + + + + +

3 1 1 1

3 3 1 1 1 1 1 1

3 1 1 1 1 1 1 1 1 1

11 1 1 1 1 1 1 1 1 1 1 1+ + + + + + + + + + +

12

11 1

10 2

9 3

9 2 1

8 4

8 3 1

7 5

7 4 1

7 3 2

6 5

+

+

+

+ +

+

+ +

+

+ +

+ +

+ +11

6 4 2

6 3 2 1

5 4 3

5 4 2 1

+ +

+ + +

+ +

+ + +

Page 178: Combinatorics - Routledge

8    ◾    How to Count: An Introduction to Combinatorics, Second Edition

Not many partitions occur in both lists, but both lists contain the same number of partitions. Is this a coincidence? It comes as a surprise that the answer is “no” and that the proof uses only rather simple manipulations of power series.

We now come to one of the best known of all combinatorial problems. The river Pregel flows through Königsberg* and divides the town, flowing around an island called the Kneiphof (“Beer Garden”). The city was connected by seven bridges as shown in the sketch map in Figure 1.3. It is said that the residents considered the following problem during their Sunday stroll.

PROBLEM 9A�e Bridges of KönigsbergIs there a route that would have taken the burghers of Königsberg over each of the bridges exactly once?

This problem was solved by Leonhard Euler in 1735. Euler’s solution of this problem is regarded as the origin of the branch of mathematics known as graph theory. The “graphs” of graph theory are rather different from the “graphs” of functions you will be familiar with, but in both cases, graph abbreviates graphical representation. In the case of the Königsberg bridges problem, all that really matters is how the different parts of the city are connected by the bridges. So we can replace Figure 1.3 with the representa-tion of the same situation shown in Figure 1.4, where the dots represent the land areas and the lines represent the bridges.

* Originally a medieval city, Königsberg became the capital of East Prussia in the fifteenth century. In 1945 it was ceded by Germany to the Soviet Union and was renamed Kaliningrad. It remains part of modern-day Russia.

KneiphofRiver Pregel

FIGURE 1.3

FIGURE 1.4

Page 179: Combinatorics - Routledge

What’s It All About?    ◾    9

Another classic problem of graph theory is the utilities problem. We state it in a slightly modernized form.

PROBLEM 9B�e Utilities ProblemIs it possible to connect up a house, a cottage, and a bungalow to supplies of electric-ity, gas, and cable television so that the pipes, wires, and cables do not cross each other?

In Figure 1.5 we show a failed attempt to solve this problem. But one failure does not prove that the problem does not have a solution. The issue is whether the graph consist-ing of two sets of three dots, where each dot in the first set is joined to each dot in the second graph, can be drawn in the plane so that the lines meet only at dots.

An even more famous problem in this area is whether when drawing maps we always need only four colors to ensure that countries with a common boundary can be colored differently. The question was first asked in 1852, but it took 124 years for a solution to emerge—although a “proof” proposed in 1879 stood for 11 years before a flaw in it was found.

PROBLEM 9C�e Four-Color ProblemIs it possible to color every map drawn in the plane with at most four colors so that adjacent countries are colored differently?

We show in Chapter 9 how this problem may be reworded as a problem about color-ing the vertices of a graph. The four-color theorem says that the answer to this question is “yes.” It was proved to most people’s satisfaction by Kenneth Appel and Wolfgang Haken in 1977. Their proof involved a considerable use of computer time to check a large number of cases and so has not been accepted as a “mathematical proof” by every-one. We are not able to go into the technicalities in this book, but we are able to give a proof of the less ambitious claim that every map may be colored using at most five colors.

Graphs can also be used to represent chemical molecules, with the vertices repre-senting atoms and the edges representing valency bonds. Two examples are shown in Figure 1.6.

Electricity Gas Cable TV

House Cottage Bungalow

FIGURE 1.5

Page 180: Combinatorics - Routledge

10    ◾    How to Count: An Introduction to Combinatorics, Second Edition

The graphs used to represent these molecules are of a special kind called trees. These graphs have lots of applications, and we study these in Chapter 10. The classic problem in this area is the following.

PROBLEM 10Labeled TreesHow many different trees are there with n vertices labeled with the numbers 1,2,...,n?

In Chapter 10 we give the answer originally found by the English mathematician Arthur Cayley.

Much of mathematics is about finding patterns. In order to prepare for our study of patterns, we look at symmetries of geometric figures. Symmetries give rise to math-ematical structures called groups. You may already have met this concept, but in case not, we introduce groups from scratch in Chapter 11. Ideas from group theory can be used to solve a large range of problems. Here is one example.

PROBLEM 11Shu�ing CardsWhat is the most effective way to shuffle a pack of cards?

We next look at the relationship between the coloring of figures and the symme-tries of these figures. We prove an important theorem, the orbit-stabilizer theorem, in Chapter 12, but we find we have to develop the theory further in Chapter 13 in order to answer questions such as the next three.

PROBLEM 13AColoring a ChessboardHow many different ways are there to color the squares of a chessboard using two colors?

On a standard 8 × 8 chessboard, the squares are colored alternately black and white as shown in Figure 1.7i, but clearly they could be colored in many other ways. Alternative colorings are shown in Figure 1.7ii and iii. The problem is to decide exactly how many different colorings are possible.

H H H H H H

H C C C H H C C C O H

H O H H H H

H

FIGURE 1.6

Page 181: Combinatorics - Routledge

What’s It All About?    ◾    11

PROBLEM 13BVarieties of Colored CubesIn how many different ways can you color a cube using three colors?

Before we can answer this question we need to make clear what “different” means. The cube on the right in Figure 1.8 looks different from the one on the left. But perhaps they could be made to look the same by rotating the cube on the right about an appro-priate axis. This is where the symmetries of a geometric figure come in.

This eventually leads us to a very powerful technique due to George Pólya for answer-ing more complicated questions, such as the following.

PROBLEM 14Counting Patterns AgainIn how many different ways can you color a cube using one red, two white, and three blue faces?

We also show in Chapter 14 that Pólya’s Counting Theorem enables us to count fairly readily the number of different simple graphs with a given number of vertices. Our next combinatorial principle arises in the context of number theory where it was used by Dirichlet to solve the following problem.

(i) (ii) (iii)

FIGURE 1.7

FIGURE 1.8

Page 182: Combinatorics - Routledge

12    ◾    How to Count: An Introduction to Combinatorics, Second Edition

PROBLEM 15ARational Approximations to Irrational NumbersShow that for each irrational number a, there exists a rational number p/q such that

a pq q

− < 12

.

The principle used to solve this problem is called Dirichlet’s pigeonhole principle, which is of deceptive simplicity but has surprising consequences. Here is one of a more recreational kind.

It is obvious that, using 18 dominoes, each of size 1 by 2, we can “cover” a 6 by 6 (square) board completely and without any two dominoes overlapping. An example is given in Figure 1.9.

Note that, in the figure, the two leftmost columns of dominoes are separated from the other four columns by a “fault line.” That is, a knife could be dragged down the board cutting it in two without having to cut through any domino. At the same time, the board cannot be similarly split along any other row or column. So, the problem is:

PROBLEM 15BPlacing Dominoes “Faultlessly”Can 18 dominoes be placed on a 6 by 6 board “faultlessly”?

We next come to another existence problem that is the starting point for a large area of study called Ramsey theory and that can also be reinterpreted in terms of graphs:

PROBLEM 16AFriends at a PartyThere are six people at a party. Each pair are either friends or strangers. We claim that, among the six, there are (at least) three people who are either all friends or all strangers. Are we correct?

A nice way to picture this problem is by using graphs, this time with colored edges. If we ask each pair of friends to hold opposite ends of a red string and each pair of

FIGURE 1.9

Page 183: Combinatorics - Routledge

What’s It All About?    ◾    13

strangers (if they would be so kind) to hold opposite ends of a blue string, the problem becomes: Is it true that if the 15 edges of a graph with six vertices are colored either red or blue, then there is always either a red “triangle,” that is, three edges forming a triangle that are all red, or a blue “triangle”? In brief, must there always exist a mono-chromatic triangle?

There are many other fascinating problems that are concerned with coloring (even infinitely many) points. For example:

PROBLEM 16BPlane ColorsLet us be given a red/blue coloring of the points of the plane. That is, imagine that with each point of the plane there is associated one of those two colors. Suppose that some-one now draws a particular triangle T in the plane. Is it always possible to move T to a position in the plane so that its vertices lie over three points all of the same color? In other words, can we find, in the plane, a monochromatic triangle congruent to T? If not, can we find one similar to T? We attempt no picture here, for obvious reasons!

In the final chapter of this book we deal with questions of the following kind.

PROBLEM 17ANonattacking rooksGiven the 5 × 5 board in Figure 1.10, in how many ways can 0, 1, 2, 3, 4, 5, or more nonattacking rooks (that is, no two rooks in the same row or column) be placed on the board so that none of them lies on a black square?

At first sight this seems rather a frivolous problem, but actually it is one with many practical applications. As you can see from Figure 1.11, it is equivalent to asking in how

FIGURE 1.10

Employee EEmployee DEmployee CEmployee BEmployee A

Job 1 Job 2 Job 3 Job 4 Job 5

FIGURE 1.11

Page 184: Combinatorics - Routledge

14    ◾    How to Count: An Introduction to Combinatorics, Second Edition

many ways the five people A, B, C, D, and E can each be allocated one of the jobs 1 to 5, where a black square indicates that the person named in its row is unable to do the job named in its column. Finding the answer leads to the introduction of rook polynomials. In most cases the key question is whether there is any solution at all rather than the number of solutions. One particularly intriguing version of this problem is the following, whose answer is certainly not obvious one way or the other.

PROBLEM 17BSelecting CardsLet 40 cards—10 red, 10 blue, 10 green, and 10 yellow, each set being numbered 1 to 10—be well shuffled and then dealt out into 10 groups of four. Is it always possible to pick one card from each group so that the 10 cards chosen will include exactly one of each number 1,2,…,10? (Obviously we do not insist that all the chosen cards are also of the same color.)

This problem is solved using Hall’s marriage theorem with which we end Chapter 17.

1.3 WHAT YOU NEED TO KNOWOne of the advantages of following a course in combinatorics is that only a modest math-ematical background is necessary in order to get started. This modest amount includes some basic set theory, which we remind you of below, a bit of elementary algebra, and, perhaps surprisingly (to help with two or three estimation problems), some calculus. In Chapter 11 we use groups, but we assume no previous knowledge of group theory, which we introduce as we need it.

Suppose A and B are sets. The union of A and B, written as A ∪ B, is the set of elements that are in A or B or both. The intersection of A and B, written as A ∩ B, is the set of ele-ments that are both in A and in B. The difference, written A \ B, is the set of elements in A but not in B. That is, A \ B = {x:x ∈ A and x ∉ B}. This may be represented pictorially as in Figure 1.12, where the shading represents the set A \ B.

There is, unfortunately, no standard notation for the number of elements in a set, X. The notations X , | X |, and card(X) are all used. However, our preferred notation is #(X).

We use the symbols N, N+, Z, Q, R, and C for the following sets of numbers:N is the set of natural numbers, that is, N = {0,1,2,...}. N + is the set of positive integers,

that is, N = {1,2,3,...}. Z is the set of integers, that is, Z = {...–2,–1,0,1,2,...}. Q is the set of rational numbers, R is the set of real numbers, and C is the set of complex numbers. We use R2 for the points of the plane.

We use the “arrow” notation for functions. For example, the function that squares each number will be written as x x 2 . If the function f maps elements of the set D to the set C, we write f D C: → and call the set D the domain of f, and the set C the codomain of f.

We say that a function f D C: → is injective if f does not repeat values, that is, if for all x, y ∈ D, x ≠ y implies that f(x) ≠ f(y). We say that f is surjective if each element of C is a value of f, that is, if for each y ∈ C, there is some x ∈ D such that f (x) = y. We say that f is bijective

Page 185: Combinatorics - Routledge

What’s It All About?    ◾    15

if it is both injective and surjective. (The alternative nomenclature that you may have met is one-one for injective, onto for surjective, and one-one correspondence for bijective.)

We assume that you are already familiar with the “sigma” notation for sums. For exam-ple, i

nia=∑ 1 represents the sum a1 + a2 + … + an. On occasion we also, in a similar way, use

the “pi” notation for products. So in

ia=∏ 1 represents the product a1 × a2 × … × an, or, omit-ting the multiplication signs, a1a2…an.

Although we approach most of the topics discussed in this book through concrete problems, a strong aim of this book is to emphasize the importance of proof in mathematics. While this is a book that focuses on combinatorial methods, these are worthless if we are unable to prove that employing them will give the correct answer. Mathematics is in the very privileged position of being the only area of human knowledge where assertions made have the chance of being verified by unassailable proof – or shot down by counterex-ample! A course in combinatorics provides an ideal opportunity for paying special atten-tion to methods of proof since, often, the reader will not have to make a huge mental effort to understand the meaning of the statements themselves. Accordingly, we offer no apology for paying careful attention to the majority of proofs themselves, the odd exceptions being proofs that are beyond the scope of this book or where even the most fastidious mathemati-cian might say, “Clearly, this very same proof goes over to the general case.”

We therefore largely assume that the reader is already familiar with the standard meth-ods of proof. In particular, as we are frequently concerned with results that hold for all natural numbers, or for all positive integers, proof by mathematical induction is used a good deal. If you need an introduction to this topic, or a reminder about it, please consult one of the many books that cover this topic.*

1.4 ARE YOU SITTING COMFORTABLY?Once upon a time there was a program on the radio called Listen with Mother. (In those days it was assumed that it would be the mother who would be at home with young chil-dren.) In the first program in 1950 the storyteller, Julia Lang, introduced the story she was about to tell by saying, “Are you sitting comfortably? Then we’ll begin.” Apparently this introduction was not planned, but it caught on and was used regularly until the program came to an end in 1982.†

* We mention just two, R. B. J. T. Allenby, Numbers and Proofs, Arnold, London, 1997, and Kevin Houston, How to Think like a Mathematician, Cambridge University Press, Cambridge, 2009.

† See Nigel Rees, Sayings of the Century, Allen & Unwin, London, 1984.

BA

A/B

FIGURE 1.12

Page 186: Combinatorics - Routledge

16    ◾    How to Count: An Introduction to Combinatorics, Second Edition

When it comes to reading mathematics, however, this is not an appropriate beginning. A mathematics book cannot be read like a novel, sitting in a comfortable chair, with a glass at your side. Reading mathematics requires you to be active. You need to be sitting at a table or a desk, with pencil and paper, both to work through the theory and to tackle the problems. A good guide is the amount of time it takes you to read the book. A novel can be read at a rate of about 60 pages an hour, whereas with most mathematics books you are doing well if you can read 5 pages an hour. (It follows that, even at 12 times the price, a mathematics book is good value for the money!)

Since the approach the book takes is to begin with problems and usually to use them to lead into the theory, we have posed a good number of problems in the text. The bth prob-lem in Chapter a is labeled Problem a.b. These problems are immediately followed by their solutions, but you are strongly encouraged to try the problems for yourself before reading our solution.

At the end of most of the chapter sections, there are exercises. Some of these are routine problems to help consolidate your understanding, and some take the theory a bit further or are designed to challenge you. In most cases these problems occur in pairs, labeled A and B. Usually the B question is quite similar to the A question. The difference is that we have included solutions for the A questions at the back of the book but not for the B ques-tions. The solutions to the A questions are usually written out in detail. This is intended to be helpful, but it will not achieve their purpose of helping you to learn the subject, if you give in to the temptation to read the solutions before making your own attempt at the exercises. The B questions, with no solutions, are there for those who cannot resist this temptation!