Table Of Content“mcs-ftl” — 2010/9/8 — 0:40 — page i — #1
Mathematics for Computer Science
revisedWednesday8th September,2010,00:40
Eric Lehman
GoogleInc.
F Thomson Leighton
DepartmentofMathematicsandCSAIL,MIT
AkamaiTechnologies
Albert R Meyer
MassachusetsInstituteofTechnology
Copyright©2010, EricLehman,FTomLeighton,AlbertRMeyer.Allrightsreserved.
“mcs-ftl” — 2010/9/8 — 0:40 — page ii — #2
“mcs-ftl” — 2010/9/8 — 0:40 — page iii — #3
Contents
I Proofs
1 Propositions 5
1.1 CompoundPropositions 6
1.2 PropositionalLogicinComputerPrograms 10
1.3 PredicatesandQuantifiers 11
1.4 Validity 19
1.5 Satisfiability 21
2 PatternsofProof 23
2.1 TheAxiomaticMethod 23
2.2 ProofbyCases 26
2.3 ProvinganImplication 27
2.4 Provingan“IfandOnlyIf” 30
2.5 ProofbyContradiction 32
2.6 ProofsaboutSets 33
2.7 Good ProofsinPractice 40
3 Induction 43
3.1 TheWellOrderingPrinciple 43
3.2 OrdinaryInduction 46
3.3 Invariants 56
3.4 StrongInduction 64
3.5 StructuralInduction 69
4 NumberTheory 81
4.1 Divisibility 81
4.2 TheGreatestCommonDivisor 87
4.3 TheFundamentalTheoremofArithmetic 94
4.4 AlanTuring 96
4.5 ModularArithmetic 100
4.6 ArithmeticwithaPrimeModulus 103
4.7 ArithmeticwithanArbitraryModulus 108
4.8 TheRSAAlgorithm 113
“mcs-ftl” — 2010/9/8 — 0:40 — page iv — #4
iv Contents
II Structures
5 GraphTheory 121
5.1 Definitions 121
5.2 MatchingProblems 128
5.3 Coloring 143
5.4 GettingfromAtoB inaGraph 147
5.5 Connectivity 151
5.6 AroundandAroundWeGo 156
5.7 Trees 162
5.8 PlanarGraphs 170
6 DirectedGraphs 189
6.1 Definitions 189
6.2 TournamentGraphs 192
6.3 CommunicationNetworks 196
7 RelationsandPartialOrders 213
7.1 BinaryRelations 213
7.2 RelationsandCardinality 217
7.3 RelationsonOneSet 220
7.4 EquivalenceRelations 222
7.5 PartialOrders 225
7.6 PosetsandDAGs 226
7.7 TopologicalSort 229
7.8 ParallelTaskScheduling 232
7.9 Dilworth’sLemma 235
8 StateMachines 237
III Counting
9 SumsandAsymptotics 243
9.1 TheValueofanAnnuity 244
9.2 PowerSums 250
9.3 ApproximatingSums 252
9.4 HangingOutOvertheEdge 257
9.5 DoubleTrouble 269
9.6 Products 272
“mcs-ftl” — 2010/9/8 — 0:40 — page v — #5
v Contents
9.7 AsymptoticNotation 275
10 Recurrences 283
10.1 TheTowersofHanoi 284
10.2 MergeSort 291
10.3 LinearRecurrences 294
10.4 Divide-and-ConquerRecurrences 302
10.5 AFeelforRecurrences 309
11 CardinalityRules 313
11.1 CountingOneThingbyCountingAnother 313
11.2 CountingSequences 314
11.3 TheGeneralizedProductRule 317
11.4 TheDivisionRule 321
11.5 CountingSubsets 324
11.6 SequenceswithRepetitions 326
11.7 CountingPractice: PokerHands 329
11.8 Inclusion-Exclusion 334
11.9 CombinatorialProofs 339
11.10ThePigeonholePrinciple 342
11.11AMagicTrick 346
12 GeneratingFunctions 355
12.1 DefinitionsandExamples 355
12.2 OperationsonGeneratingFunctions 356
12.3 EvaluatingSums 361
12.4 ExtractingCoefficients 363
12.5 SolvingLinearRecurrences 370
12.6 CountingwithGeneratingFunctions 374
13 InfiniteSets 379
13.1 Injections,Surjections,andBijections 379
13.2 CountableSets 381
13.3 PowerSetsAreStrictlyBigger 384
13.4 InfinitiesinComputerScience 386
IV Probability
14 EventsandProbabilitySpaces 391
14.1 Let’sMakeaDeal 391
14.2 TheFourStepMethod 392
“mcs-ftl” — 2010/9/8 — 0:40 — page vi — #6
vi Contents
14.3 StrangeDice 402
14.4 SetTheoryandProbability 411
14.5 InfiniteProbabilitySpaces 413
15 ConditionalProbability 417
15.1 Definition 417
15.2 UsingtheFour-StepMethodtoDetermineConditionalProbability 418
15.3 APosterioriProbabilities 424
15.4 ConditionalIdentities 427
16 Independence 431
16.1 Definitions 431
16.2 IndependenceIsanAssumption 432
16.3 MutualIndependence 433
16.4 PairwiseIndependence 435
16.5 TheBirthdayParadox 438
17 RandomVariablesandDistributions 445
17.1 DefinitionsandExamples 445
17.2 DistributionFunctions 450
17.3 BernoulliDistributions 452
17.4 UniformDistributions 453
17.5 BinomialDistributions 456
18 Expectation 467
18.1 DefinitionsandExamples 467
18.2 ExpectedReturnsinGamblingGames 477
18.3 ExpectationsofSums 483
18.4 ExpectationsofProducts 490
18.5 ExpectationsofQuotients 492
19 Deviations 497
19.1 Variance 497
19.2 Markov’sTheorem 507
19.3 Chebyshev’sTheorem 513
19.4 BoundsforSumsofRandomVariables 516
19.5 MutuallyIndependentEvents 523
20 RandomWalks 533
20.1 UnbiasedRandomWalks 533
20.2 Gambler’sRuin 542
20.3 WalkinginCircles 549
“mcs-ftl” — 2010/9/8 — 0:40 — page 1 — #7
I Proofs
“mcs-ftl” — 2010/9/8 — 0:40 — page 2 — #8
“mcs-ftl” — 2010/9/8 — 0:40 — page 3 — #9
Introduction
This text explains how to use mathematical models and methods to analyze prob-
lems that arise in computer science. The notion of a proof plays a central role in
thiswork.
Simplyput,aproofisamethodofestablishingtruth. Likebeauty,“truth”some-
timesdependsontheeyeofthebeholder,anditshouldnotbesurprisingthatwhat
constitutesaproofdiffersamongfields. Forexample, inthejudicialsystem, legal
truthisdecidedbyajurybasedontheallowableevidencepresentedattrial. Inthe
businessworld,authoritativetruthisspecifiedbyatrustedpersonororganization,
or maybe just your boss. In fields such as physics and biology, scientific truth1 is
confirmed by experiment. In statistics, probable truth is established by statistical
analysisofsampledata.
Philosophical proof involves careful exposition and persuasion typically based
on a series of small, plausible arguments. The best example begins with “Cogito
ergo sum,” a Latin sentence that translates as “I think, therefore I am.” It comes
fromthebeginningofa17thcenturyessaybythemathematician/philosopher,Rene´
Descartes, and it is one of the most famous quotes in the world: do a web search
onthephraseandyouwillbefloodedwithhits.
Deducingyourexistencefromthefactthatyou’rethinkingaboutyourexistence
isaprettycoolandpersuasive-soundingidea. However,withjustafewmorelines
of argument in this vein, Descartes goes on to conclude that there is an infinitely
beneficent God. Whether or not you believe in a beneficent God, you’ll probably
agree that any very short proof of God’s existence is bound to be far-fetched. So
1Actually,onlyscientificfalsehoodcanbedemonstratedbyanexperiment—whentheexperiment
failstobehaveaspredicted.Butnoamountofexperimentcanconfirmthatthenextexperimentwon’t
fail.Forthisreason,scientistsrarelyspeakoftruth,butratheroftheoriesthataccuratelypredictpast,
andanticipatedfuture,experiments.
“mcs-ftl” — 2010/9/8 — 0:40 — page 4 — #10
4 PartI Proofs
eveninmasterfulhands,thisapproachisnotreliable.
Mathematicshasitsownspecificnotionof“proof.”
Definition. Amathematicalproof ofapropositionisachainoflogicaldeductions
leadingtothepropositionfromabasesetofaxioms.
The three key ideas in this definition are highlighted: proposition, logical de-
duction, and axiom. These three ideas are explained in the following chapters,
beginningwithpropositionsinChapter1. Wewillthenprovidelotsofexamplesof
proofsandevensomeexamplesof“falseproofs”(thatis,argumentsthatlooklike
a proof but that contain missteps, or deductions that aren’t so logical when exam-
inedclosely). Falseproofsareoftenevenmoreimportantasexamplesthancorrect
proofs, because they are uniquely helpful with honing your skills at making sure
eachstepofaprooffollowslogicallyfrompriorsteps.
Creating a good proof is a lot like creating a beautiful work of art. In fact,
mathematiciansoftenrefertoreallygoodproofsasbeing“elegant”or“beautiful.”
As with any endeavor, it will probably take a little practice before your fellow
students use such praise when referring to your proofs, but to get you started in
therightdirection, wewillprovidetemplatesforthemostusefulprooftechniques
in Chapters 2 and 3. We then apply these techniques in Chapter 4 to establish
someimportantfactsaboutnumbers;factsthatformtheunderpinningofoneofthe
world’smostwidely-usedcryptosystems.