Many combinatorial problems admit “exact” solutions, and in these cases, we will usu-
ally try hard to ﬁnd them. TheErdős/Szekeres Theoremfrom earlier in this chapter is
a good example of an “exact” result¹. By this statement, we mean that for each pair*m*

and*n*of positive integers, there is a sequence of*mn*distinct real numbers that has nei-
ther an increasing subsequence of size*m*+1nor a decreasing subsequence of size*n*+1.
To see this, consider the sequenceσdeﬁned as follows: For each *i* 1,2, . . . ,*m*, let

*Bi* {*j*+(*m*−1)*i* : 1≤ *j* ≤ *n*}. Note that each*Bi* is a block of*n*consecutive integers.
Then deﬁne a permutation σof the ﬁrst *mn* integers by setting α < β if there exist
distinct integers*i*1and*i*2so thatα∈ *Bi*1andβ∈ *Bi*2. Also, for each*i*1,2, . . . ,*m*, set

α < βinσwhen1+(*m*−1)*i*≤β < α ≤*n*+(*m*−1)*i*. Clearly, any increasing subsequence

ofσcontains at most one member from each block, soσhas no increasing sequence of
size*m*1. On the other hand, any decreasing sequence inσis contained in a single
block, soσhas no decreasing sequence of size*n*+1.

As another example of an exact solution, the number of integer solutions to *x*1 +

*x*2+. . .*xr* *n* with*xi* > 0for*i*−1,2, . . . ,*r*is exactly*C*(*n*−1,*r*−1). On the other

hand, nothing we have discussed thus far allows us to provide an exact solution for
the number of partitions of an integer*n*.

**4.4.1 Approximate and Asymptotic Solutions**

Here’s an example of a famous problem that we can only discuss in terms of approx-
imate solutions, at least when the input size is suitably large. For an integer*n*, let
π(*n*)denote the number of primes among the ﬁrst*n* positive integers. For example,
π(12) 5since2,3,5,7and11are primes. The exact value ofπ(*n*)is known when

*4.4 Exact Versus Approximate*

*n* ≤1023, and in fact:

π(1023)1,925,320,391,606,803,968,923

On the other hand, you might ask whetherπ(*n*)tends to inﬁnity as*n*grows larger
and larger. The answer is yes, and here’s a simple and quite classic argument. Suppose
to the contrary that there were only*k*primes, where*k*is a positive integer. Suppose
these*k*primes are listed in increasing order as*p*1 < *p*2 < . . . < *pk*, and consider the
number*n* 1+*p*1*p*2· · ·*pk. Then* *n*is not divisible by any of these primes, and it is

larger than*pk*, which implies that*n*is either a prime number larger than*pk*or divisible
by a prime number larger than*pk.*

So we know thatlimn→∞π(*n*)∞. In a situation like this, mathematicians typically
want to know more about how fastπ(*n*)goes to inﬁnity. Some functions go to inﬁnity
“slowly”, such aslog*n*orlog log*n*. Some go to inﬁnity quickly, like2*n*_{,}_{n}_{!}_{or}_{2}2*n*

. Since
π(*n*) ≤ *n*, it can’t go to inﬁnity as fast as these last three functions, but it might go
inﬁnity likelog*n*or maybe√*n*.

On the basis of computational results (done by hand, long before there were com-
puters), Legendre conjectured in 1796 thatπ(*n*)goes to inﬁnity like*n*/ln*n*. To be more
precise, he conjectured that

lim
*n*→∞

π(*n*)ln*n*

*n* 1.

In 1896, exactly one hundred years after Legendre’s conjecture, Hadamard and de
la Vallée-Poussin independently published proofs of the conjecture, using techniques
whose roots are in the Riemann’s pioneering work in complex analysis. This result,
now known simply as the*Prime Number Theorem*, continues to this day to be much
studied topic at the boundary of analysis and number theory.

**4.4.2 Polynomial Time Algorithms**

Throughout this text, we will place considerable emphasis on problems for which a
certiﬁcate can be found in polynomial time. This refers to problems for which there is
some constant*c*>0so that there is an algorithmAfor solving the problem which has
running time*O*(*nc*_{)}_{where}_{n}_{is the input size. The symbol}_{P} _{is suggestive of}_{polyno-}

*mial*.

**4.4.3**

### P

### NP**?**

Perhaps the most famous question at the boundary of combinatorial mathematics, the- oretical computer science and mathematical logic is the notoriously challenging ques- tion of deciding whetherPis the same asNP. This problem has the shorthand form: PNP? Here, we present a brief informal discussion of this problem.

First, we have already introduced the classPconsisting of all yes-no combinatorial
problems which admit polynomial time algorithms. The ﬁrst two problems discussed
in this chapter belong toPsince they can be solved with algorithms that have running
time*O*(*n*)and*O*(*n*3_{)}_{, respectively. Also, determining whether a graph is}_{2-colorable}

and whether it is connected both admit polynomial time algorithms.

We should emphasize that it may be very diﬃcult to determine whether a problem belongs to classP or not. For example, we don’t see how to give a fast algorithm for solving the third problem (subset sum), but that doesn’t mean that there isn’t one. Maybe we all need to study harder!

Setting that issue aside for the moment, the classNPconsists of yes–no problems for
which there is a certiﬁcate for a yes answer whose correctness can be veriﬁed in poly-
nomial time. More formally, this is called the class of**nondeterministic polynomial**
**time**problems. Our third problem deﬁnitely belongs to this class.

The famous question is to determine whether the two classes are the same. Evi- dently, any problem belonging toP also belongs toNP, i.e,P ⊆ NP, but are they equal? It seems diﬃcult to believe that there is a polynomial time algorithm for set- tling the third problem (the subset sum problem), and no one has come close to settling this issue. But if you get a good idea, be sure to discuss it with one or both authors of this text before you go public with your news. If it turns out that you are right, you are certain to treasure a photo opportunity with yours truly.

**4.5 Discussion**

Carlos, Dave and Yolanda were fascinated by the discussion on complexity. Zori was
less enthusiastic but even she sensed that the question of which problems could be
solved quickly had practical implications. She could even predict that people could
earn a nice income solving problems faster and more accurately than their competition.
Bob remarked, “I’m not sure I understand what’s being talked about here. I don’t see
why it can’t be the case that all problems can be solved. Maybe we just don’t know how
to do it.” Xing said, “Any ﬁnite problem*can*be solved. There is always a way to list all
the possibilities, compare them one by one and take the best one as the answer.” Alice
joined in, “Well, a problem might take a long time just because it is big. For example,
suppose you are given two dvd’s, each completely full with the data for a large integer.
How are you possibly going to multiply them together, even with a large computer
and fancy software.” Carlos then oﬀered, “But I think there are really hard problems
that any algorithm will take a long time to solve and not just because the input size is
large. At this point, I don’t know how to formulate such a problem but I suspect that
they exist.”

*4.6 Exercises*

**4.6 Exercises**

**1.** Suppose you are given a list of*n* integers, each of size at most100*n*. How many
operations would it take you to do the following tasks (in answering these questions,
we are interested primarily in whether it will takelog*n*,√*n*,*n*,*n*2,*n*3,2*n*, … steps. In
other words, ignore multiplicative constants.):

(a) Determine if the number2*n*+7is in the list.

(b) Determine if there are two numbers in the list whose sum is2*n*+7.

(c) Determine if there are two numbers in the list whose product is2*n*+7(This one is
more subtle than it might appear! It may be to your advantage to sort the integers
in the list).

(d) Determine if there is a number*i*for which all the numbers in the list are between

*i*and*i*+2*n*+7.

(e) Determine the longest sequence of consecutive integers belonging to the list. (f) Determine the number of primes in the list.

(g) Determine whether there are three integers*x*,*y*and*z*from the list so that*x*+*y*
*z*.

(h) Determine whether there are three integers*x*,*y*and*z*from the list so that*x*2+*y*2
*z*2.

(i) Determine whether there are three integers*x*,*y*and*z*from the list so that*x yz*.
(j) Determine whether there are three integers*x*,*y*and*z*from the list so that*xy* _{}_{z}_{.}
(k) Determine whether there are two integers *x* and *y* from the list so that*xy* is a

prime.

(l) Determine the longest arithmetic progression in the list (a sequence(*a*1,*a*2, . . . ,*at*)
is an arithmetic progression when there is a constant*d* ,0so that*ai*+1 *ai*+*d*,
for each*i*1,2, . . . ,*t*−1).

(m) Determine the number of distinct sums that can be formed from members of the list (arbitrarily many integers from the list are allowed to be terms in the sum). (n) Determine the number of distinct products that can be formed from members

of the list (arbitrarily many integers from the list are allowed to be factors in the product).

(o) Determine for which integers*m*, the list contains at least10%of the integers from

{1,2, . . . ,*m*}.

**2.** If you have to put*n*+1pigeons into*n*holes, you have to put two pigeons into the
same hole. What happens if you have to put*mn*+1pigeons into*n*holes?

**3.** Consider the set*X* {1,2,3,4,5}and suppose you have two holes. Also suppose
that you have10pigeons: the2-element subsets of*X*. Can you put these10pigeons
into the two holes in a way that there is no3-element subset*S* {*a*,*b*,*c*} ⊂ *X*for
which all pigeons from*S*go in the same hole? Then answer the same question if*X*
{1,2,3,4,5,6}with15*C*(6,2)pigeons.

**4.** Let*n* 10,000. Suppose a friend tells you that he has a secret family of subsets

of{1,2, . . . ,*n*}, and if you guess it correctly, he will give you one million dollars. You

think you know the family of subsets he has in mind and it contains exactly half the
subsets, i.e., the family has2*n*−1_{subsets. Discuss how you can share your hunch with}

your friend in an eﬀort to win the prize.

**5.** Let*N*denote the set of positive integers. When *f* : *N* → *N*is a function, let*E*(*f*)

### CHAPTER

## 5

*Graph Theory*

InExample 1.5, we discussed the problem of assigning frequencies to radio stations in
the situation where stations within200miles of each other must broadcast on distinct
frequencies. Clearly we would like to use the smallest number of frequencies possible
for a given layouts of transmitters, but how can we determine what that number is?
Suppose three new homes are being built and each of them must be provided with utility connections. The utilities in question are water, electricity, and natural gas. Each provider needs a direct line from their terminal to each house (the line can zig-zag all it wants, but it must go from the terminal to the house without passing through another provider’s terminal or another house en route), and the three providers all wish to bury their lines exactly four feet below ground. Can they do this successfully without the lines crossing?

These are just two of many, many examples where the discrete structure known as a

**graph**can serve as an enlightening mathematical model. Graphs are perhaps the most

basic and widely studied combinatorial structure, and they are prominently featured in this text. Many of the concepts we will study, while presented in a more abstract mathematical sense, have their origins in applications of graphs as models for real- world problems.

**5.1 Basic Notation and Terminology for Graphs**

A**graphG**is a pair(*V*,*E*)where*V* is a set (almost always ﬁnite) and*E*is a set of2-

element subsets of*V*. Elements of*V* are called**vertices**and elements of*E*are called

**edges. We call** *V* the **vertex set**of **G** and *E* is the**edge set. For convenience, it is**

customary to abbreviate the edge{*x*,*y*}as just *x y*. Remember though that*x y* ∈ *E*

means exactly the same as*yx* ∈*E*. If*x*and*y*are distinct vertices from*V*,*x*and *y*are

**adjacent**when*x y* ∈ *E*; otherwise, we say they are**non-adjacent. We say the edge***x y*

is**incident to**the vertices*x*and*y*.

For example, we could deﬁne a graph**G** (*V*,*E*)with vertex set*V* {*a*,*b*,*c*,*d*,*e*}

perfectly permissible based on our deﬁnition. It is quite common to identify a graph
with a visualization in which we draw a point for each vertex and a line connecting two
vertices if they are adjacent. The graph**G**we’ve just deﬁned is shown inFigure 5.1. It’s
important to remember that while a drawing of a graph is a helpful tool, it is not the
same as the graph. We could draw**G**in any of several diﬀerent ways without changing
what it is as a graph.
*a*
*b*
*c*
*d*
*e*

**Figure 5.1:**A graph on5vertices

As is often the case in science and mathematics, diﬀerent authors use slightly dif-
ferent notation and terminology for graphs. As an example, some use**nodes**and**arcs**
rather than vertices and edges. Others refer to vertices as**points**and in this case, they
often refer to**lines**rather than edges. We will try to stick to vertices and edges but con-
fess that we may occasionally lapse into referring to vertices as points. Also, following
the patterns of many others, we will also say that adjacent vertices are**neighbors. And**
we will use the more or less standard terminology that the**neighborhood**of a vertex

*x* is the set of vertices adjacent to*x*. Thus, using the graph **G**we have depicted in
Figure 5.1, vertices*d*and *a*are neighbors, and the neighborhood of*d* is{*a*,*c*}while
the neighborhood of*e* is the empty set. Also, the**degree**of a vertex *v*in a graph**G**,
denoteddeg** _{G}**(

*v*), is then the number of vertices in its neighborhood, or equivalently, the number of edges incident to it. For example, we havedeg

**(**

_{G}*d*) deg

**(**

_{G}*a*) 2, deg

**(**

_{G}*c*) deg

**(**

_{G}*b*) 1, anddeg

**(**

_{G}*e*) 0. If the graph being discussed is clear from context, it is not uncommon to omit the subscript and simply writedeg(

*v*)for the de- gree of

*v*.

When**G**(*V*,*E*)and**H**(*W*,*F*)are graphs, we say**H**is a**subgraph**of**G**when*W* ⊆
*V*and*F* ⊆*E*. We say**H**is an**induced subgraph**when*W* ⊆*V*and*F* {*x y*∈*E*:*x*,*y*∈
*W*}. In other words, an induced subgraph is deﬁned completely by its vertex set and
the original graph**G**. We say**H**is a**spanning subgraph**when*W* *V*. InFigure 5.2,
we show a graph, a subgraph and an induced subgraph. Neither of these subgraphs
is a spanning subgraph. A graph**G**(*V*,*E*)is called a**complete graph**when*x y*is an
edge in**G**for every distinct pair*x*,*y* ∈ *V*. Conversely,**G**is an**independent graph**if

*x y*<*E*, for every distinct pair*x*,*y* ∈*V*. It is customary to denote a complete graph on

*5.1 Basic Notation and Terminology for Graphs*
*a*
*b* *c*
*d*
*e*
*f*
*g*
*h*
*i*
*j*
*l*
*m*
*k* *a*
*b* *c*
*d*
*e*
*h*
*i*
*a*
*b* *c*
*d*
*e*
*h*
*i*

**Figure 5.2:**A Graph, a Subgraph and an Induced Subgraph

**K**1 **K**2 **K**3 **K**4 **K**5

**Figure 5.3:**Small complete graphs

the complete graphs with at most5vertices. A sequence(*x*1,*x*2, . . . ,*xn*)of vertices in
a graph**G**(*V*,*E*)is called a**walk**when*xixi*+1is an edge for each*i* 1,2, . . . ,*n*−1.

Note that the vertices in a walk need not be distinct. On the other hand, if the vertices
are distinct, then the sequence is called a**path, and often to emphasize where a path**
starts and ends, we will say that a sequence(*x*1,*x*2, . . . ,*xn*)of distinct vertices is a path
from*x*1 to*xn* in**G**. Similarly, when*n* ≥3, a path(*x*1,*x*2, . . . ,*xn*)of*n*distinct vertices
is called a**cycle**when*x*1*xn*is also an edge in**G**. It is customary to denote a path on*n*
vertices by**P***n* , while**C***n*denotes a cycle on*n*vertices. The**length**of a path or a cycle
is the number of edges it contains. Therefore, the length of**P***n*is*n*−1and the length
of**C***n*is*n*. InFigure 5.4, we show the paths of length at most4, and inFigure 5.5, we
show the cycles of length at most5.

**P**1 **P**2 **P**3 **P**4 **P**5

**Figure 5.4:**Short paths

**C**3 **C**4 **C**5

**Figure 5.5:**Small cycles

If**G** (*V*,*E*)and**H** (*W*,*F*)are graphs, we say**G**is**isomorphic**to**H**and write
**G** **H**when there exists a bĳection *f* : *V* −−−→1–1

onto *W* so that*x* is adjacent to *y* in**G**if
and only if *f*(*x*)is adjacent to *f*(*y*)in**H**. Often writers will say that**G**“contains”**H**
when there is a subgraph of**G**which is isomorphic to**H**. In particular, it is customary
to say that**G**contains the cycle**C***n*(same for**P***n*and**K***n*) when**G**contains a subgraph
isomorphic to**C***n. The graphs in*Figure 5.6are isomorphic. An isomorphism between
these graphs is given by

*f*(*a*)5, *f*(*b*)3, *f*(*c*)1, *f*(*d*)6, *f*(*e*)2, *f*(*h*)4.
*a*
*b*
*c*
*d*
*e*
*h* 1
2
3
4
5
6

**Figure 5.6:**A pair of isomorphic graphs

On the other hand, the graphs shown inFigure 5.7are*not*isomorphic, even though
they have the same number of vertices and the same number of edges. Can you tell
why?

*5.1 Basic Notation and Terminology for Graphs*
*a*
*b*