Many combinatorial problems admit “exact” solutions, and in these cases, we will usu- ally try hard to find 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 pairm
andnof positive integers, there is a sequence ofmndistinct real numbers that has nei- ther an increasing subsequence of sizem+1nor a decreasing subsequence of sizen+1. To see this, consider the sequenceσdefined as follows: For each i 1,2, . . . ,m, let
Bi {j+(m−1)i : 1≤ j ≤ n}. Note that eachBi is a block ofnconsecutive integers. Then define a permutation σof the first mn integers by setting α < β if there exist distinct integersi1andi2so thatα∈ Bi1andβ∈ Bi2. Also, for eachi1,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 sizem1. On the other hand, any decreasing sequence inσis contained in a single block, soσhas no decreasing sequence of sizen+1.
As another example of an exact solution, the number of integer solutions to x1 +
x2+. . .xr n withxi > 0fori−1,2, . . . ,ris exactlyC(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 integern.
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 integern, let π(n)denote the number of primes among the firstn 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 infinity asngrows larger and larger. The answer is yes, and here’s a simple and quite classic argument. Suppose to the contrary that there were onlykprimes, wherekis a positive integer. Suppose thesekprimes are listed in increasing order asp1 < p2 < . . . < pk, and consider the numbern 1+p1p2· · ·pk. Then nis not divisible by any of these primes, and it is
larger thanpk, which implies thatnis either a prime number larger thanpkor divisible by a prime number larger thanpk.
So we know thatlimn→∞π(n)∞. In a situation like this, mathematicians typically want to know more about how fastπ(n)goes to infinity. Some functions go to infinity “slowly”, such aslognorlog logn. Some go to infinity quickly, like2n,n!or22n
. Since π(n) ≤ n, it can’t go to infinity as fast as these last three functions, but it might go infinity likelognor 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 infinity liken/lnn. To be more precise, he conjectured that
lim n→∞
π(n)lnn
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 thePrime 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 certificate can be found in polynomial time. This refers to problems for which there is some constantc>0so that there is an algorithmAfor solving the problem which has running timeO(nc)wheren is the input size. The symbolP is suggestive ofpolyno-
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 first two problems discussed in this chapter belong toPsince they can be solved with algorithms that have running timeO(n)andO(n3), respectively. Also, determining whether a graph is2-colorable
and whether it is connected both admit polynomial time algorithms.
We should emphasize that it may be very difficult 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 certificate for a yes answer whose correctness can be verified in poly- nomial time. More formally, this is called the class ofnondeterministic polynomial timeproblems. Our third problem definitely 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 difficult 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 finite problemcanbe 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 offered, “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 ofn integers, each of size at most100n. How many operations would it take you to do the following tasks (in answering these questions, we are interested primarily in whether it will takelogn,√n,n,n2,n3,2n, … steps. In other words, ignore multiplicative constants.):
(a) Determine if the number2n+7is in the list.
(b) Determine if there are two numbers in the list whose sum is2n+7.
(c) Determine if there are two numbers in the list whose product is2n+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 numberifor which all the numbers in the list are between
iandi+2n+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 integersx,yandzfrom the list so thatx+y z.
(h) Determine whether there are three integersx,yandzfrom the list so thatx2+y2 z2.
(i) Determine whether there are three integersx,yandzfrom the list so thatx yz. (j) Determine whether there are three integersx,yandzfrom the list so thatxy z. (k) Determine whether there are two integers x and y from the list so thatxy is a
prime.
(l) Determine the longest arithmetic progression in the list (a sequence(a1,a2, . . . ,at) is an arithmetic progression when there is a constantd ,0so thatai+1 ai+d, for eachi1,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 integersm, the list contains at least10%of the integers from
{1,2, . . . ,m}.
2. If you have to putn+1pigeons intonholes, you have to put two pigeons into the same hole. What happens if you have to putmn+1pigeons intonholes?
3. Consider the setX {1,2,3,4,5}and suppose you have two holes. Also suppose that you have10pigeons: the2-element subsets ofX. Can you put these10pigeons into the two holes in a way that there is no3-element subsetS {a,b,c} ⊂ Xfor which all pigeons fromSgo in the same hole? Then answer the same question ifX {1,2,3,4,5,6}with15C(6,2)pigeons.
4. Letn 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 has2n−1subsets. Discuss how you can share your hunch with
your friend in an effort to win the prize.
5. LetNdenote the set of positive integers. When f : N → Nis a function, letE(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
graphcan 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
AgraphGis a pair(V,E)whereV is a set (almost always finite) andEis a set of2-
element subsets ofV. Elements ofV are calledverticesand elements ofEare called
edges. We call V the vertex setof G and E is theedge set. For convenience, it is
customary to abbreviate the edge{x,y}as just x y. Remember though thatx y ∈ E
means exactly the same asyx ∈E. Ifxandyare distinct vertices fromV,xand yare
adjacentwhenx y ∈ E; otherwise, we say they arenon-adjacent. We say the edgex y
isincident tothe verticesxandy.
For example, we could define a graphG (V,E)with vertex setV {a,b,c,d,e}
perfectly permissible based on our definition. 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 graphGwe’ve just defined 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 drawGin any of several different 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, different authors use slightly dif- ferent notation and terminology for graphs. As an example, some usenodesandarcs rather than vertices and edges. Others refer to vertices aspointsand in this case, they often refer tolinesrather 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 areneighbors. And we will use the more or less standard terminology that theneighborhoodof a vertex
x is the set of vertices adjacent tox. Thus, using the graph Gwe have depicted in Figure 5.1, verticesdand aare neighbors, and the neighborhood ofd is{a,c}while the neighborhood ofe is the empty set. Also, thedegreeof a vertex vin a graphG, denoteddegG(v), is then the number of vertices in its neighborhood, or equivalently, the number of edges incident to it. For example, we havedegG(d) degG(a) 2, degG(c) degG(b) 1, anddegG(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 ofv.
WhenG(V,E)andH(W,F)are graphs, we sayHis asubgraphofGwhenW ⊆ VandF ⊆E. We sayHis aninduced subgraphwhenW ⊆VandF {x y∈E:x,y∈ W}. In other words, an induced subgraph is defined completely by its vertex set and the original graphG. We sayHis aspanning subgraphwhenW V. InFigure 5.2, we show a graph, a subgraph and an induced subgraph. Neither of these subgraphs is a spanning subgraph. A graphG(V,E)is called acomplete graphwhenx yis an edge inGfor every distinct pairx,y ∈ V. Conversely,Gis anindependent graphif
x y<E, for every distinct pairx,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
K1 K2 K3 K4 K5
Figure 5.3:Small complete graphs
the complete graphs with at most5vertices. A sequence(x1,x2, . . . ,xn)of vertices in a graphG(V,E)is called awalkwhenxixi+1is an edge for eachi 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 apath, and often to emphasize where a path starts and ends, we will say that a sequence(x1,x2, . . . ,xn)of distinct vertices is a path fromx1 toxn inG. Similarly, whenn ≥3, a path(x1,x2, . . . ,xn)ofndistinct vertices is called acyclewhenx1xnis also an edge inG. It is customary to denote a path onn vertices byPn , whileCndenotes a cycle onnvertices. Thelengthof a path or a cycle is the number of edges it contains. Therefore, the length ofPnisn−1and the length ofCnisn. InFigure 5.4, we show the paths of length at most4, and inFigure 5.5, we show the cycles of length at most5.
P1 P2 P3 P4 P5
Figure 5.4:Short paths
C3 C4 C5
Figure 5.5:Small cycles
IfG (V,E)andH (W,F)are graphs, we sayGisisomorphictoHand write G Hwhen there exists a bijection f : V −−−→1–1
onto W so thatx is adjacent to y inGif and only if f(x)is adjacent to f(y)inH. Often writers will say thatG“contains”H when there is a subgraph ofGwhich is isomorphic toH. In particular, it is customary to say thatGcontains the cycleCn(same forPnandKn) whenGcontains a subgraph isomorphic toCn. The graphs inFigure 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.7arenotisomorphic, 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