Table Of Content“mcs” — 2012/6/4 — 15:49 — page i — #1
Mathematics for Computer Science
revisedMonday4th June,2012,15:49
Eric Lehman
GoogleInc.
F Thomson Leighton
DepartmentofMathematics
andtheComputerScienceandAILaboratory,
MassachussettsInstituteofTechnology;
AkamaiTechnologies
Albert R Meyer
DepartmentofElectricalEngineeringandComputerScience
andtheComputerScienceandAILaboratory,
MassachussettsInstituteofTechnology
Copyright © 2012, Eric Lehman, F Tom Leighton, Albert R Meyer . All rights reserved.
“mcs” — 2012/6/4 — 15:49 — page ii — #2
“mcs” — 2012/6/4 — 15:49 — page iii — #3
Contents
I Proofs
1 WhatisaProof? 5
1.1 Propositions 5
1.2 Predicates 8
1.3 TheAxiomaticMethod 8
1.4 OurAxioms 9
1.5 ProvinganImplication 11
1.6 Provingan“IfandOnlyIf” 13
1.7 ProofbyCases 15
1.8 ProofbyContradiction 16
1.9 Good ProofsinPractice 17
2 TheWellOrderingPrinciple 25
2.1 WellOrderingProofs 25
2.2 TemplateforWellOrderingProofs 26
2.3 FactoringintoPrimes 28
2.4 WellOrderedSets 29
3 LogicalFormulas 37
3.1 PropositionsfromPropositions 38
3.2 PropositionalLogicinComputerPrograms 41
3.3 EquivalenceandValidity 44
3.4 TheAlgebraofPropositions 46
3.5 TheSATProblem 51
3.6 PredicateFormulas 52
4 MathematicalDataTypes 73
4.1 Sets 73
4.2 Sequences 77
4.3 Functions 77
4.4 BinaryRelations 80
4.5 FiniteCardinality 84
5 Induction 99
5.1 OrdinaryInduction 99
5.2 StrongInduction 108
5.3 StrongInductionvs.Inductionvs.WellOrdering 113
“mcs” — 2012/6/4 — 15:49 — page iv — #4
iv Contents
5.4 StateMachines 114
6 RecursiveDataTypes 151
6.1 RecursiveDefinitionsandStructuralInduction 151
6.2 StringsofMatchedBrackets 155
6.3 RecursiveFunctionsonNonnegativeIntegers 158
6.4 ArithmeticExpressions 161
6.5 InductioninComputerScience 166
7 InfiniteSets 179
7.1 InfiniteCardinality 180
7.2 TheHaltingProblem 184
7.3 TheLogicofSets 188
7.4 DoesAllThisReallyWork? 191
8 NumberTheory 203
8.1 Divisibility 203
8.2 TheGreatestCommonDivisor 208
8.3 PrimeMysteries 214
8.4 TheFundamentalTheoremofArithmetic 217
8.5 AlanTuring 219
8.6 ModularArithmetic 223
8.7 RemainderArithmetic 225
8.8 Turing’sCode(Version2.0) 228
8.9 MultiplicativeInversesandCancelling 230
8.10 Euler’sTheorem 234
8.11 RSAPublicKeyEncryption 241
8.12 WhathasSATgottodowithit? 244
II Structures
9 Directedgraphs&PartialOrders 273
9.1 Digraphs&VertexDegrees 275
9.2 AdjacencyMatrices 279
9.3 WalkRelations 282
9.4 DirectedAcyclicGraphs&PartialOrders 283
9.5 WeakPartialOrders 286
9.6 RepresentingPartialOrdersbySetContainment 288
9.7 Path-TotalOrders 289
9.8 ProductOrders 290
“mcs” — 2012/6/4 — 15:49 — page v — #5
v Contents
9.9 Scheduling 291
9.10 EquivalenceRelations 297
9.11 SummaryofRelationalProperties 299
10 CommunicationNetworks 325
10.1 CompleteBinaryTree 325
10.2 RoutingProblems 325
10.3 NetworkDiameter 326
10.4 SwitchCount 327
10.5 NetworkLatency 328
10.6 Congestion 328
10.7 2-DArray 329
10.8 Butterfly 331
10.9 Benesˇ Network 333
11 SimpleGraphs 345
11.1 VertexAdjacencyandDegrees 345
11.2 SexualDemographicsinAmerica 347
11.3 SomeCommonGraphs 349
11.4 Isomorphism 351
11.5 BipartiteGraphs&Matchings 353
11.6 TheStableMarriageProblem 358
11.7 Coloring 365
11.8 Gettingfromutov inaGraph 370
11.9 Connectivity 371
11.10OddCyclesand2-Colorability 375
11.11Forests&Trees 376
12 PlanarGraphs 413
12.1 DrawingGraphsinthePlane 413
12.2 DefinitionsofPlanarGraphs 413
12.3 Euler’sFormula 424
12.4 BoundingtheNumberofEdgesinaPlanarGraph 425
12.5 ReturningtoK andK 426
5 3;3
12.6 ColoringPlanarGraphs 427
12.7 ClassifyingPolyhedra 429
12.8 AnotherCharacterizationforPlanarGraphs 432
“mcs” — 2012/6/4 — 15:49 — page vi — #6
vi Contents
III Counting
13 SumsandAsymptotics 443
13.1 TheValueofanAnnuity 444
13.2 SumsofPowers 450
13.3 ApproximatingSums 452
13.4 HangingOutOvertheEdge 456
13.5 Products 463
13.6 DoubleTrouble 465
13.7 AsymptoticNotation 468
14 CardinalityRules 487
14.1 CountingOneThingbyCountingAnother 487
14.2 CountingSequences 488
14.3 TheGeneralizedProductRule 491
14.4 TheDivisionRule 495
14.5 CountingSubsets 498
14.6 SequenceswithRepetitions 500
14.7 CountingPractice: PokerHands 503
14.8 ThePigeonholePrinciple 508
14.9 Inclusion-Exclusion 518
14.10CombinatorialProofs 524
15 GeneratingFunctions 559
15.1 InfiniteSeries 559
15.2 CountingwithGeneratingFunctions 560
15.3 PartialFractions 567
15.4 SolvingLinearRecurrences 569
15.5 FormalPowerSeries 575
IV Probability
16 EventsandProbabilitySpaces 591
16.1 Let’sMakeaDeal 591
16.2 TheFourStepMethod 592
16.3 StrangeDice 601
16.4 SetTheoryandProbability 608
16.5 ConditionalProbability 614
16.6 Independence 626
“mcs” — 2012/6/4 — 15:49 — page vii — #7
vii Contents
17 RandomVariables 659
17.1 RandomVariableExamples 659
17.2 Independence 661
17.3 DistributionFunctions 662
17.4 GreatExpectations 670
17.5 LinearityofExpectation 682
18 DeviationfromtheMean 707
18.1 WhytheMean? 707
18.2 Markov’sTheorem 708
18.3 Chebyshev’sTheorem 710
18.4 PropertiesofVariance 714
18.5 EstimationbyRandomSampling 719
18.6 ConfidenceversusProbability 724
18.7 SumsofRandomVariables 725
18.8 ReallyGreatExpectations 735
19 RandomProcesses 755
19.1 Gamblers’Ruin 755
19.2 RandomWalksonGraphs 764
V Recurrences
20 Recurrences 783
20.1 TheTowersofHanoi 783
20.2 MergeSort 786
20.3 LinearRecurrences 790
20.4 Divide-and-ConquerRecurrences 797
20.5 AFeelforRecurrences 804
Bibliography 806
Index 808
“mcs” — 2012/6/4 — 15:49 — page viii — #8
“mcs” — 2012/6/4 — 15:49 — page 1 — #9
I Proofs