100% found this document useful (3 votes)
58 views

Discrete Mathematics Computing A Set of Lectures Malik Magdon-Ismail All Chapters Instant Download

Computing

Uploaded by

zehidaaleser
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
58 views

Discrete Mathematics Computing A Set of Lectures Malik Magdon-Ismail All Chapters Instant Download

Computing

Uploaded by

zehidaaleser
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Discrete Mathematics Computing A Set of Lectures


Malik Magdon-Ismail

https://textbookfull.com/product/discrete-mathematics-
computing-a-set-of-lectures-malik-magdon-ismail/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Understand Mathematics Understand Computing Discrete


Mathematics That All Computing Students Should Know Arnold
L. Rosenberg
https://textbookfull.com/product/understand-mathematics-understand-
computing-discrete-mathematics-that-all-computing-students-should-
know-arnold-l-rosenberg/
textboxfull.com

Discrete Mathematics 8e Richard Johnsonbaugh

https://textbookfull.com/product/discrete-mathematics-8e-richard-
johnsonbaugh/

textboxfull.com

50 years of Combinatorics Graph Theory and Computing


Discrete Mathematics and Its Applications 1st Edition Fan
Chung (Editor)
https://textbookfull.com/product/50-years-of-combinatorics-graph-
theory-and-computing-discrete-mathematics-and-its-applications-1st-
edition-fan-chung-editor/
textboxfull.com

Essentials of Discrete Mathematics Third Edition David


James Hunter

https://textbookfull.com/product/essentials-of-discrete-mathematics-
third-edition-david-james-hunter/

textboxfull.com
A Journey Through Discrete Mathematics A Tribute to Ji■í
Matoušek Martin Loebl

https://textbookfull.com/product/a-journey-through-discrete-
mathematics-a-tribute-to-jiri-matousek-martin-loebl/

textboxfull.com

Discrete Mathematics An Open Introduction Oscar Levin

https://textbookfull.com/product/discrete-mathematics-an-open-
introduction-oscar-levin/

textboxfull.com

Discrete Mathematics An open Introduction Oscar Levin

https://textbookfull.com/product/discrete-mathematics-an-open-
introduction-oscar-levin-2/

textboxfull.com

Discrete mathematics with ducks Second Edition Belcastro

https://textbookfull.com/product/discrete-mathematics-with-ducks-
second-edition-belcastro/

textboxfull.com

Discrete Mathematics and Applications 2nd Edition Ferland

https://textbookfull.com/product/discrete-mathematics-and-
applications-2nd-edition-ferland/

textboxfull.com
D is c r e t e
M a t h e m a t ic s
S z

C o m p u t in g
A S et of Lectures
The book website DMC-book. com contains supporting
material for instructors and readers.
(Solutions to pop-quizzes and exercises, slides, . . . )

Book feedback: magdondmcbookOgmaiI.com.


D isc r e t e M a th e m a t ic s
&
C o m pu t in g
A S et of Lectures

M alik M agdon-Ism ail


Rensselaer Polytechnic Institute
Malik Magdon-Isrnail
Department of Computer Science
Rensselaer Polytechnic Institute
Troy, NY 12180, USA
magdonOcs. r p i . edu

I S B N 10: 0 - 5 78-5 678 7-7


I S B N 13: 9 7 8 - 0 -578 -567 87-7

© 2020 M a lik M a g d o n - l s m a i l . v. 2020.02

All r i g h ts re se rv e d . 'This w o rk m a y n o t b e t r a n s l a t e d o r co])ied in w h o l e o r in p a r t w i t h o u t t h e w r i t t e n p e r m i s s i o n o f


t h e a u t h o r s . N o |) a r t of t h i s p u b l i c a t i o n m a y b e r e p r o d u c e d , s t o r e d in a r e tr i e v a l s y s t e m , o r t r a n s m i t t e d in a n \ ' fo r m
o r by a n y m e a n s e le c t r o n i c , m e c h a n i c a l , p h o t o c o p y i n g , s c a n n i n g , o r oth erw is e' w i t h o u t p r i o r w r i t t e n p e r m i s s i o n o f
t h e a u t h o r s , e x c e p t a s p e r m i t t e d u n d e r S e c ti o n 107 o r 108 o f t h e 1976 Uniteel S t a t e s C o p x r i g h t . \ c t .

L im it o f L ia b ility D i s c l a i n u 'r o f W a r r a n t y : W h i l e t lu ' a u t h o r s h a v e u s e d t lu 'i r In'st e lf o r t s in p r e i i a r i u g t h i s b o o k , the_\-


m a k e n o re p re se 'iita tio n o r w a r r a n t i e s w i t h r e s p e c t t o tlu- a c c u r a c y o r c o m p h 't e n e s s of t h e e-ontents o f t h i s b o o k a n d
sjje'cilically d i s c la i m a n y ini|)lied w a r r a n t i e s o f n u 'r c h a n t a b i l i t y o r (itne ss for a p a r t i e i i l a r p u r p o s e . .No w a r r a n t y ma\-
b e c r e a t( 'd or ('xte'iuh'd by s a h 's r e p re s ( 'n t a ti v ( 's o r w r i t t e n sa les m a t i 'r ia l s . 1 lu' a d v i c e a n d s t r a t e g i e s c o n t a i u i 'd h e ro in
m a y n o t b e s u i t a b l e for yotii' s i t u a t i o n . You s h o u l d c o n s u l t w i t h a i)rolessional w lu 're a p p r o p r i a t e . I'he a u t h o r s s h a l l
not b e lia ble for a n y loss o f |)rolit oi' a n y ot lu'r c o m m e r c i a l d a m a g e's , i n c l u d i n g b u t not lim iti'd t o spee'ial, i n c i d e n t a l ,
c o iise ( |u e n tia l, o r o t i u 'r d a m a g e s .

'Lh(' use in t h i s p u b l i c a t i o n o f t l a d e n a m i 's , t r a d e 'in a r k s , se'iyice m a r k s , a n d s i m il a r t i'r m s , evi'ii if t he>- are' ue>t ielent ilie'el
a s sue h, is ue>t t o be' teike'ii a s a n e'xpre'ssiem e)f e)piuiou a s te> whe'lhe'l' eir ue>t the'\- are' stibje'e t te) p r e ip r i e t a r v r i g h ts .

T h i s bexik w a s ty p e 's e t b y the' em theers emel w a s p r in le 'd anel benm el in the' I'uite-el Sleete's eif .\m e'rie';\.
To m y teachers, and to m y students.

M a th e m a tic s
She is patien t.
She sits,
She w aits in silence.

A tr u th once found,
A tr u th shall be.
In a n tiq u ity and hereafter.
So please, oh please, we beg, we pray.
Go throw your TV set away.
And in its place you can install
A lovely bookshelf on the wall. - Roald Dahl
No wi-fi. Please just talk to each other and get drunk.
- bar on Kollwitzstrasse, Berlin.
I have been a happy man ever since January 1, 1990, when I no
longer had an email address. - Donald E. Knuth
Preface

T h is book is a sto ry w hich s ta r ts w ith d iscrete m a th e m a tic s and ends a t th e th eo ry of com puting. T he end
p o in ts as well as th e jo u rn e y are b eau tifu l. Dtie to physical c o n strain t, our passage th ro u g h th e com plex
lan d scap e is linear, c h a ra c te r by c h a ra c ter, w ord by word. T h e tru e sto ry is neith er linear nor short, so it
goes w ith o u t saying th a t o u r ta le is n o t entire. We striv e to m ake th e sto ry relavent to th e life of a com puter
scien tist, w ho, a fte r all, is th e biggest consum er of discrete m a th em atics in th e m odern era.
Be su re to d istin g u ish th e p ro g ra m m e r from th e co m p u ter scientist. P rogram m ing is b u t one of th e skills
req u ired of a c o m p e te n t c o m p u te r scien tist. T h e o th e r is to solve problems using algorithms. T his trife c ta of
pro b lem solving using a lg o rith m s p ro g ram m ed on one of a m yriad different co m p u tin g platform s is everywhere.
A nd everyw here in th is trife c ta , you will find a role for th e o ry and form al reasoning. It behoves us to solve
th e se c o m p u tin g pro b lem s carefully because, today, th e com m on citizen tru s ts th e ir life to com puting system s.
I t ’s b e st t h a t th o se system s w ork as th e y are su p posed to, provably so. W e are n o t alone in th is observation.

"Too few people recognize that the high technology so celebrated today is a mathematical technology."
"A programmer must demonstrate that their program has the required properties. If this comes as an
afterthought, it is all but certain that they won't be able to meet this obligation. Only if this obligation
influences the design is there hope to meet it. Pure a posteriori verification denies you that wholesome
influence and is therefore putting the cart before the horse. But that is exactly what happens in the
software houses where "programming" and "quality assurance" are done by different groups. Needless to
say, those houses deliver without warranty."
"The required techniques of effective reasoning are pretty formal, but as long as programming is done by
people who don't master them, the software crisis will remain with us and will be considered an incurable
disease. And you know what incurable diseases do: they invite the quacks and charlatans in, who in this
case take the form of Software Engineering Gurus." - Edsger Dijkstra

You m ay use th e b o o k for self-study, b u t th e sp irit o f th e p re sen ta tio n is a set of lectures for a th eo ry course.
W e are old fashioned a n d ad h ere to th e te a ch e r-a p p re n tice philosophy. M axim um value will be reaped w ith
a n in s tru c to r a t th e helm , for one sh o u ld n ’t u n d e re stim a te th e gu id e’s ability to d am pen th e m eanderings of
th e fiedgling-trekker. A course im poses an inflexible b a n d w id th co n stra in t and effort was needed to respect
t h a t c o n stra in t. W e h a d to carefully choose w h a t to include, and m ore im p o rta n tly w h at to exclude.^ It is on
good a u th o rity th a t effort sp e n t identifying only th a t w hich is absolutely necessary is effort well spent:
"I didn't have time to write a short letter, so I wrote a long one instead," - Mark Twain
"This report, by its very length, defends itself against the risk of being read." - Winston Churchill
To c o m p e n sa te for o m itte d to p ics, th e re are 250+ w orked quizzes an d exercises and 1.500+ problem s suitable
for hom ew orks or exam s. M any of th e p roblem s are a sp rin g b o ard into m ore advanced techniques.
T o t h e in s t r u c t o r . E ach lectu re is sh o rt an d m eant to be covered in whole. O nce or twice, we reneg
on t h a t in te n tio n to p resen t to p ics of p a rtic u la r relevance to co m p u ter science (for exam ple th e RSA-
c ry p to sy ste m ). T h e m a te ria l is su ita b le for a fast-paced single-sem ester course. O ne could also teach each
p a r t (p a rt I on d iscrete m a th e m a tic s an d p a rt II on th e th e o ry of com iuiting) as se})arate sem ester courses, in
w hich case all th e d etails could be covered, including som e challenging problem s.
T h e flexibility offered by s ta n d a rd te x ts a d a p ts well to a variety of teaching philosophies. B ut. th a t
flexibility is a t a price. E xperien ce show s th a t stu d e n ts re ac t well to a linear i)ath w ith o u t diversions. \ \ liile
^Suggestions that further shorten the text will receive iny gratitude squared. All other feedback is greatly appreciated too.

Vll
P reface

a lecturer is skilled a t selecting w h at to cover, a stu d en t may not be skilled a t deciding w h a t to focus on as
they read. O ur presentation does not offer a w ealth of options for m eandering. I have picked a p a th . S tu ents
eager to explore can quench th a t th irs t in th e problem s section. In the end, it is n o t th e stu d e n t s p a th b u t
th e passion they develop th a t m atters.

To build a ship, d o n ’t d ru m up people to collect wood and d o n ’t assign th em task s an d work.


R ath er, teach th em to long for th e endless im m ensity of th e sea. - A ntoine de S ain t-E x u p ery

T o t h e s t u d e n t . D on’t be a sp ectato r. You have to do theory, not read ab o u t it. A typical begining stu d e n t
should m ake an effort to work all th e pop-quizzes and a tte m p t all th e exercises. T h e pop-quizzes check if
you are still awake. T he exercises are to stretch th e muscles. T reat th e pop-quizzes and exercises as w orked
exam ples. To reap m axim um benefit you m ust try to solve th em first, before looking to th e solutions. T h e
end-of-chapter problem s give an o p p o rtu n ity to strain th e muscles, and in some cases stra in th e m a lot. An
advanced stu d en t m ay quickly read th e te x t, do th e exercises and focus on th e problem s. You can learn a lot
by m astering all th e problem s.
B la n k e t A c k n o w le d g e m e n t. E verything in this book has been done before. P e rh a p s som e of th e presen­
ta tio n is original, b u t even th ere, I can n o t say to w h at ex te n t I was influenced by th e m any beloved te x ts I
grew up on. So, w h at th e n is th e purpose of such a book, which produces n o thing new ? P u rely pedagogical!
To give an analogy, everything is on th e in tern et. So, w h at th en is th e purpose of Google'^"? G oogle’^'” does
not create novel content, ra th e r it plays a search and discovery role. W hen you w ant som ething, Google'^”
finds it and presents it in ju s t th e right order - G oogle’s’^'"' opinion of th e right order. T h e re ’s a w ealth of
m ath em atics o u t there, and you can get it all using Google'^“ . B u t you d o n ’t need it all for a sophom ore-level
theory course. I’ve collected w h at I th in k is needed, and presented it in my own way an d my own order.
Hopefully, my th o u g h ts m atch up w ith som e higher order tr u th , w ho knows. To focus on pedagogy. I gave up
on detailed references in th e te x t. Instead , I pay a blanket trib u te here, to:
Biggs E pp G raham ; K n u th : P a ta sh n ik
G rim rnett; Stirzaker H opcroft; M otwani; U llm an K leinberg: T ardos
Lehm an; Leighton; Meyer Lewis; P ap adim itriou Lovasz; Pelikan: V esztergom bi
Polya Rosen Sipser
Scheinerm an Skiena Stanley
van Lint; W ilson W est Zeitz

l l i e above au th o rs developed ideas in unique ways th a t m ay have affected th e wa>- I present c e rta in topics,
either explicitly or intangibly. W hen th e resem blence is extrem e. I have tried to give credit w ith in th e
local context. In cases where 1 have u n d erestim ated th e resem blence. I apologize in advance, and hope th e
acknow ledgem ent above reduces a little of th e w rongdoing. A sim ilar consideration goes for exercises mid
problem s, which in some cases have been lifted form olym piads, problem -books. etc. W ith age com es th e
ability to forget th e original source of m any a problem , esjiecially those encountered main- years ago.
I give a sjiecial th a n k s to those stu d en ts, colleagues and teaching assistan ts who were th e sandbox for early
drafts of this book, especially M ark K. G oldberg who took on the first draft.
P u m p elstiltsk in is still spinning gold for Z ainab. Zain, Deem Pafi and Sofya who p a tien tly endureil th e
dem ands of w riting a book. W hen th e little ones grow into tlii'ir m ath em atics shoes. 1 hope th ey will read
this book. I t ’s tim e to tu rn on the lights and enter.

Malik .Magdou-lsmail
Irov. .New N'ork
[email protected]
■lulv 2:!. 2D2t).

vm
Contents

P r e fa c e Vll

I D isc re te M a th em a tics 1
0 B a c k g r o u n d a n d P e p T a lk 3

1 A T a s t e o f D is c r e t e M a t h e m a t ic s 7
1.1 M odeling E p i d e m i c s ...................................................................................................................................... 7
1.2 S peed D a t i n g .................................................................................................................................................... 8
1.3 F rien d sh ip N etw orks an d A d s .................................................................................................................... 8
1.4 M odeling C o m p u t e r s ...................................................................................................................................... 9
1.5 P r o o f ...................................................................................................................................................................... 9
1.6 P ro b lem s ............................................................................................................................................................ 11

2 D is c r e te O b je c ts 15
2.1 S e t s ...................................................................................................................................................................... 15
2.2 S e q u e n c e s ........................................................................................................................................................... 17
2.3 G r a p h s ................................................................................................................................................................... 17
2.4 E asin g in to P r o o f s .......................................................................................................................................... 19
2.4.1 A n A xiom : T h e W ell-O rdering P r in c ip le ................................................................................. 20
2.5 P ro b lem s ............................................................................................................................................................ 23

3 M a k in g P r e c is e S t a t e m e n t s 25
3.1 C o m p o u n d P r o p o s i t i o n s ............................................................................................................................... 26
3.2 T r u t h - T a b l e s .................................................................................................................................................... 28
3.2.1 P ro v in g an I m p lic a tio n ..................................................................................................................... *10
3.3 Q uantifiers: S ta te m e n ts A b o u t M any T h i n g s ..................................................................................... 30
3.3.1 P r e d i c a t e s .............................................................................................................................................. 31
3.3.2 N eg atio n .............................................................................................................................................. 33
3.3.3 M ixing Q u a n t i f i e r s ............................................................................................................................ 33
3.3.4 P ro o fs w ith Q u an tifiers ................................................................................................................. 34
3.4 D e d u ctio n V ersus I n d u c t i o n ........................................................................................................................ 34
3.5 P ro b lem s ............................................................................................................................................................

4 P r o o fs
4.1 D irect P r o o f ........................................................................................................................................................
4.1.1 D isproving I m p lic a tio n .....................................................................................................................
4.2 P ro o f by C o n t r a p o s i t i o n ...............................................................................................................................
4.3 E quivalence: If a n d O n ly I f ........................................................................................................................
4.4 P ro o f by C o n tra d ic tio n (R ed u ctio ad A b s u r d u m ) .............................................................................. "10
4.5 P ro o fs a b o u t S e t s .............................................................................................................................................

ix
C ontents

50
4.6 Problem s
55
In d u c tio n : P r o v in g “ f o r al l . . . ”
57
5.1 O rd in ary I n d u c tio n ........................
58
5.1.1 Sum of Powers of Integers
61
5.1.2 In duction Gone W rong . .
63
5.2 Induction and W ell-ordering . . .
64
5.3 Problem s .........................................
71
S tr o n g In d u c tio n
71
6.1 S trengthening th e Induction H ypothesis
74
6.2 Leaping In duction ......................................
75
6.3 S trong I n d u c t i o n .........................................
78
6.4 M any Flavors of I n d u c tio n ........................
6.5 Problem s ....................................................... 80

R e c u r sio n 85
7.1 Recursive Functions ..................................................................................................................................
7.1.1 R e c u rre n c e s ................................................................................................................................ 89
7.1.2 Recursive P r o g r a m s ............................................................................................................... 90
7.2 Recursive S e t s ................................................................................................................................................. 91
7.3 Recursive S tru ctu res - T r e e s ............................................................................................................... 92
7.4 Problem s .......................................................................................................................................................

8 P r o o fs vi^ith R e c u r s iv e O b je c ts
8.1 S tru c tu ra l I n d u c t i o n .................................................................................................................................. 191
8.2 S tru c tu ra l In d u ctio n on N ........................................................................................................................ 193
8.3 P a lin d ro m e s .................................................................................................................................................... 19-1
8.4 W ell-Formed A rith m etic E x p r e s s io n s ................................................................................................... 194
8.5 P ro p erties of R ooted B inary ' f r e e s ....................................................................................................... 195
8.6 Problem s ....................................................................................................................................................... 19 ‘

9 S u m s a n d A s y m p t o t ic s 113
9.1 C om puting S u m s ......................................................................................................................................... HI
9.2 A sym ptotics: B ig -'fh eta, B ig-O h an d R ig - O m e g a ............................................................................. 117
9.3 A pproxim ation via Integration .............................................................................................................. 119
9.4 Problem s ....................................................................................................................................................... 122

10 N u m b e r T h e o r y 129
10.1 G reatest C om m on D iv is o r ........................................................................................................................ 130
10.2 F u n d a m e n ta l'fh e o re m of A r i t h m e t i c .................................................................................................... 132
10.3 M odular A rithm etic and C ry ])t()g rap h y ................................................................................................ 133
10.3.1 .Modular .M ultiplicative I n v e r s e .................................................................................................. 135
10.3.2 RSA Public Key C r y p to g r a p h y .................................................................................................. 136
10.4 Problem s ........................................................................................................................................................ i;ip

11 G r a p h s 145
11.1 1)egree S e ([U ('n e ('.......................................................................................................................................... 145
I 1.1.1 1la n d s h a k in g 'f h e o r c 'm ................................................................................................................... pps;
1 1.2 T r e e s ................................................................................................................................................................... 149
11.3 P lanar G rap h s ............................................................................................................................................. 149
11.1 ( ) ( lu'r I’ypes of G r a p h s ...............................................................................................................
150
1 1. 1.1 D irected G rap h s ( D ig r a p lis ) .......................................................................................
11.5 Problem Solving w ith G r a p h s .................................................................................................
C ontents

11.6 P ro b lem s ......................................................................................................................................................... I 54

12 M a t c h in g a n d C o lo r in g 161
12.1 B ip a rtite G ra p h M atchings ....................................................................................................................... 162
12.1.1 S tab le M arriage: M a th e m a tics of D a t i n g ................................................................................... 164
12.2 C o l o r in g .............................................................................................................................................................. 166
12.3 W h irlw in d T onr of G ra p h P ro b lem s ..................................................................................................... 168
12.4 P ro b lem s .......................................................................................................................................................... 170

1 3 C o u n t in g 179
13.1 C o u n tin g Sequences ..................................................................................................................................... 179
13.2 B u ild -u p C o u n t i n g ......................................................................................................................................... 182
13.3 C o u n tin g O ne Set B y C o u n tin g A nother; B i j e c t i o n ......................................................................... 184
13.3.1 B ijection ............................................................................................................................................ 184
13.3.2 B ijection an d C o u n tin g ................................................................................................................ 185
13.4 P e rm u ta tio n s an d C o m b in atio n s ........................................................................................................... 186
13.5 P ro b lem s ........................................................................................................................................................... 188

14 A d v a n c e d C o u n t in g 197
14.1 In c lu s io n -E x c lu s io n ....................................................................................................................................... 199
14.1.1 U nion of M ore th a n Two S e t s ...................................................................................................... 200
14.2 P igeonhole P r i n c i p l e .................................................................................................................................... 202
14.3 P ro b lem s ......................................................................................................................................................... 206

15 P r o b a b ilit y 211
15.1 C o m p u tin g P r o b a b i l i t ie s ............................................................................................................................. 211
15.1.1 T h e E v en t of In te re st .................................................................................................................... 213
15.2 P ro b a b ility an d S e t s .................................................................................................................................... 216
15.3 U niform P ro b a b ility S p a c e s ...................................................................................................................... 218
15.4 Infin ite P ro b a b ility S p a c e s ......................................................................................................................... 219
15.5 P ro b lem s ......................................................................................................................................................... 221

1 6 C o n d it io n a l P r o b a b ilit y 225
16.1 D e f i n i t i o n ......................................................................................................................................................... 225
16.2 E x a m p l e s ......................................................................................................................................................... 226
16.3 C o n d itio n a l P ro b a b ility T r a p s ................................................................................................................... 229
16.3.1 S am pling B ias .................................................................................................................................. 229
16.3.2 T ran sp o sed C o n d i t i o n a l ................................................................................................................ 230
16.4 Law o f T o ta l P r o b a b i l i ty ............................................................................................................................. 231
16.5 P ro b lem s .......................................................................................................................................................... 234

17 In d e p e n d e n t E v e n ts
17.1 C oincidence: T h e B irth d a y P a r a d o x ...................................................................................................... 246
17.1.1 H a s h i n g ................................................................................................................................................
17.2 R a n d o m W alk a n d G a m b le r’s R u i n ......................................................................................................... 250
17.3 P ro b lem s ...........................................................................................................................................................
259
1 8 R a n d o m V m ia b le s
18.1 P ro b a b ility D istrib u tio n F u n ctio n ( P D F ) .............................................................................................. 26(
18.1.1 J o in t P ro b a b ility D i s tr ib u tio n ...................................................................................................... 262
18.1.2 C u m u lativ e D istrib u tio n F u n ctio n (C D F ) ............................................................................. 264
2G5
18.2 B e r n o u l l i / B i n a r y ............................................................................................................................................
18.3 U n i f o r m ..............................................................................................................................................................
18.4 B in o m ia l..............................................................................................................................................................

xi
C ontents

268
18.5 W aiting T im e to S u c c e s s ............................................................................................................................
18.6 Problem s .......................................................................................................................................................
277
19 E x p e c t e d V a lu e
19.1 E xpected Value of Com m on R andom V a r i a b l e s ..............................................................................
280
19.1.1 B inom ial D i s t r i b u t i o n .................
280
19.1.2 W aiting T im e to S u c c e ss..............
281
19.2 C onditional E x p e c t a t i o n ...........................
284
19.2.1 Law of T otal E x p ectatio n . . . .
287
19.3 Problem s .......................................................

20 E x p e c t e d V a lu e : S u m s a n d O t h e r T o o ls 293
293
20.1 L inearity
20.2 Iterated E x p e c t a ti o n ...................................................................................................................................
20.3 B uild-up E x p ectatio n ................................................................................................................................
20.4 E xpected Value of a P ro d u c t ..................................................................................................................
20.5 Sums of I n d i c a t o r s .......................................................................................................................................
20.6 Problem s ........................................................................................................................................................

21 D e v ia tio n s fro m t h e M e a n
21.1 V a r ia n c e ............................................................................................................................................................
21.1.1 C om puting V a r i a n c e ......................................................................................................................
21.1.2 V ariance is N o n - N e g a tiv e ............................................................................................................ 312
21.2 V ariance of a S u m ....................................................................................................................................... 313
21.3 Law of Large N u m b e r s ................................................................................................................................. 315
21.3.1 W eak Law of Large N u m b e r s ..................................................................................................... 317
21.3.2 S trong Law of Large N um bers .................................................................................................. 317
21.4 Problem s ......................................................................................................................................................... 319

II Theory o f C om puting 325

22 In fin ity 327


22.1 C o u n ta ld e ......................................................................................................................................................... 327
22.1.1 Every C o untable Set C an Be Listed ....................................................................................... 329
22.1.2 H ationals are C o u n t a b l e ................................................................................................................ 331
22.2 Heals are U n c o u n ta b le ................................................................................................................................. 332
22.3 Infinity and C o m p u t i n g ............................................................................................................................. 334
22.4 Problem s ......................................................................................................................................................... ;135

23 L a n g u a g es: W h a t is C o m p u tin g ? 33 9
23.1 Decision P r o b l e m s ........................................................................................................................................ 339
23.2 L a n g u a g e s ......................................................................................................................................................... 341
23.2.1 D escribing a L a n g u a g e '................................................................................................................... 340
23.3 Com plexity of a Coni])nt ing P r o b k 'i n ................................................................................ 343
23.4 Proble: 346

24 D e te r m in is tic F in ite A u to m a ta 349


24.1 Regular L a n g u a g e s ...................................................................................................................................... 351
24.2 Provably N o n - R e g u la i'............................................................................................................................... 355
24.3 A dding E xternal M e m o r y ........................................................................................................................ 35(i
24.1 Probk'ins ........................................................................................................................................................ 358
C ontents

25 C o n te x t F ree G ra m m a rs 365
25.1 P arse 'l Y e e s ....................................................................................................................................................... 369
25.2 P u sh d o w n A u to m a ta ( P D A ) ....................................................................................................................... 371
25.3 P ro v ab ly N ot C o n te x t Fi’ee ....................................................................................................................... 372
25.4 P ro b lem s .......................................................................................................................................................... 374

2 6 T u r in g M a c h in e s 377
26.1 T ra n sd u c e r T u rin g M a c h iu e s ....................................................................................................................... 381
26.2 Infin ite L o o p s ................................................................................................................................................... 383
26.3 E n co din g s o f T u rin g M a c h in e s .................................................................................................................... 384
26.4 P ro b lem s ........................................................................................................................................................... 386

2 7 U n s o lv a b le P r o b le m s 38 7
27.1 S ketching T u rin g M achines ....................................................................................................................... 387
27.2 P ro g ra m m a b le T u rin g M a c h in e s................................................................................................................ 388
27.3 £ tm is U ndecidable: T h e re ’s No M e g a -C o m p ile r................................................................................ 390
27.4 O th e r U nsolvable Problem s: R ed u ctio n ............................................................................................... 391
27.4.1 P o s t’s C o rresp o n d en ce P ro blem ( P C P ) .................................................................................... 393
27.4.2 P ro g ra m V erification: ’‘Hello W orld!’’ ........................................................................................ 394
27.4.3 N on-R ecognizable L a n g u a g e s ...................................................................................................... 395
27.5 P ro b lem s ........................................................................................................................................................... 396

2 8 E ffic ie n c y : T h e C I eiss P 40 3
28.1 T im e C o m p le x ity ............................................................................................................................................. 404
28.2 Efficiently Solvable Problem s: T h e C lass P ........................................................................................ 405
28.3 A D ecidable N on-P o ly n o m ial P r o b l e m .................................................................................................. 409
28.4 B o u n d a ry B etw een Efficient an d Inefficient ........................................................................................ 411
28.5 P ro b lem s ........................................................................................................................................................... 412

2 9 H a r d P r o b le m s : NP 41 3
29.1 V erifiable versus Solvable ........................................................................................................................... 413
29.1.1 NP: Poly n o m ialy V e r i f i a b l e ......................................................................................................... 414
29.1.2 NP an d N o n d e te rm in is m ................................................................................................................ 416
29.2 A H a rd e st P ro b lem in N P ........................................................................................................................... 418
29.2.1 C irc u its an d S a t i s f i a b i l i t y ............................................................................................................. 418
29.2.2 CIRCUTT-SAT is H ard er th a n E very P roblem in N P ........................................................... 418
29.3 O th e r H ard est Problem s: N P - c o m p le tn e s s ........................................................................................... 421
29.4 P ro b lem s ...........................................................................................................................................................

E p ilo g u e

THE END

3 0 S o lu t io n s t o Q u iz e s & E x e r c is e s ^
End Quiz and Exercise S o lu t i o n s sol - 9o
43 3
F u r th e r R e a d in g
437
G lo s s a r y o f N o t a t i o n

T ^ 441
In d ex

xm
N otation

A table of the notation used in this book starts on page 435,


before the index. We suggest referring to it as needed.

XIV
Part I

Discrete M athematics
Good mathematics is not about how many answers you know. It's about
how you behave when you don't know. - unknown
The only way to learn math is to do math. - Paul Halmos
Don't let anyone work harder than you. - Serena Williams
To make a great dream come true, the first requirement is a great
capacity to dream; the second is persistence. - Cesar Chavez

Chapter 0

Background and Pep Talk

1: The basics, the resources and putting yourself in the right mood.

E ven “self-co n tain ed ’’ boo k s s ta r t som ew here an d build. W e c a te r to 2nd-year u n d e rg rad u ates in a m ath e­
m a tic a l, engineering or scientific discipline wdio have h ad one year of c o m p u ter science (p ro g ram m in g /d ata-
s tru c tu re s ) an d one y ear of calcuhis. In sh o rt, we assum e high-school m ath e m atic s (num bers, geom etry, alge­
b ra , . . . ) , som e p ro g ram m in g a n d som e calculus. Here are som e refresher questions. A nswer th em , perhaps
w ith a little h elp from th e solu tio n s

TO S TUDY THIS HOOK YOU MUS T .\ 0 ' l ’ USE F.LErTHO.XIU


DEVICES UNLESS E X P L I C I T L Y A SK E D TO DO SO.

N u m b e r san d S e ts.
1. W h a t is th e p rim e fa c to riz atio n of 252?
2. W h a t is th e m in im u m elem ent in th e set { 8 ,9 ,3 ,1 0 ,1 9 } ?
3. W h a t is th e u n io n o f th e sets { 8 ,9 ,3 ,1 0 ,1 9 } an d { 3 ,1 0 ,1 , 7}? W h a t is th e intersection?
4. D oes th is set of p o sitiv e n u m b ers have a m inim um elem ent:
{ 2 5 ,9 7 .1 0 7 ,1 0 0 .1 8 ,3 3 ,9 9 ,2 7 ,2 0 1 4 .2 2 0 0 ,2 3 ,...}

T h e se t could be infinite. You only know th a t every n u m ber is positive.


5. G ive exam ples of an integer, a ra tio n a l n um ber and a real num ber.
6 . L et k he & w hole n u m b er (e.g. k = 7). W hich of th e following are divisible by 3:
3/c, 3 /t- f - l, 3fc + 2, 3A:-T3, 3/c + 4, 3k + 5.

L o g a r ith m s a n d E x p o n e n t ia ls .
1. ln(2) w 0.693; ln(3) « 1.098. W h a t is ln(12)?
2. 2^° = 1024 a 1,000. W h a t is 22°?
3. How a re ln ( l x 2 x 3 x • • • x 10) an d (In 1 -T In 2 -T In 3 -T • • ■-T In 10) related?

4. How are 2“ /2*’ a n d 2“ “ *' re la te d ? W h a t is 2®?


5. Show log2 100 = log2 10 X logio 100. M ore generally, show th a t log„ x = log„ /3 x X.

S u m s an d P r o d u c ts.
1. W h a t are: (a) 1 + 2 + 3 + • • • + 1000 (b) 1 + 2 + 3 + • • • + n (c) 1 + } + ^ + ^ + ^ +

2. W h a t is 5!? W h a t is n!? W h a t is 0!?


0. B ack g ro und and P ep T alk

3. ^ is an inv itatio n to add. asks you to add /(?:) for th e whole num bers i w hich satisfy th e
lower bound in th e lower lim it and th e upp er bound in th e u p per lim it,
i<10
£ / ( z ) = / ( 1) + / ( 2) + --- + / ( 10).
i>i
Similarly, f ] is an invitatio n to m ultiply,
i<10
r i / ( d = / ( l ) x / ( 2) x - - - x / ( 10).
i> l

10 10
We often sim plify th e n o ta tio n even m ore and w rite f { i ) and H /(*)■
1=1 1=1
1000 1000 1000
W h at is Y W h at is Y W h a t is Y W h a t is Y
4=1 k=l k=l | i- l|< 5

k n
4. W h a t i s l + 2 + 3 + -- - + A:? W h a t is Y W h a t is Y
4=1 k=l
k k
5. W rite th e next two q u an tities using factorials: Y H *•
4=1 4=1
4<1
6. “E m pty" sum s, e.g. Y T are 0. “E m p ty ” p ro ducts, e.g. 2° and 0!, are 1. H ere's why.
i >3
You want the sum of the numbers in the set {3,10,1,7}. You are lazy, but your two friends are
not. You split the set into two disjoint subsets {3,10} and {1, 7}, give one subset to each friend, and
request the subset-sums. You receive the subset-sums 13 and 8, and add these two numbers to get
the full sum of 21. This simple procedure should work no m atter how you split up your original set.
Suppo.se you gave one friend all the numbers, and the other none of them. For the procedure to work,
your friend with none of the numbers (who computes an empty sum) must return 0.
To get the product instead of the sum, your friends would give you the subset-products 30 and 7.
which you multiply to get 210. If one friend gets all the numbers, and the other none of them, the
procedure still works if the friend with no numbers (who computes an empty product) returns 1.

A lg eb r a .
1. W h at is (1 + 2)''^?
2. W h at is (a + h)'^l W h at a b o u t (« + (i)'^?
3. W h at ar(> th e solutions to — 5.7; - 0 = 0?
4. W h at are th e solutions to - 5c'' - 0 = 0?
5. W h at are ;r and /y when x + ly = 2 and 2.r + 3iy = 7?

0. U.s(‘ p artial fractions to sim plify th ('('x p ressio n s — - ;, m]


(i 4- (i,,. () ■

C a lc u lu s.
1. hich of the.se sc'i ies converges;

I + 2 + 2- + 2'* + 2 ' + • • ■
l + f + ( f ) “ + ( B " + ( B ' + ---
1- 1+1 1 + 1 H H - 1+ ■..
1t ' + i + ]

2. W h a t a r e I h e ( l e i i v a t iv e s of: ./■'*: 2 '; ; In .r; log.,./-; In 2 /'''


0. B ackground and P ep T alk

3. W h a t are th e ind efin ite in teg rals of: 2^;


T .x~';
X -'; X- - 2 ?

4. W h a t is th e lim it as x 0 of th e functions:
- 1 - 1 - 1 6 -^ - 1 c - 1
sin (2x) ’ 1+ X’ siii(x 2 ) ’ X -f x '^ ’
g2x _ 1

_ 1
e ^ - 1
5. W h a t is th e lim it as x oo of th e functions:
:2x _ 1 ’ x 3 q- 2 e ^ ’ x L '

6 . W h a t is th e T aylor ex p an sio n of / ( x ) = 1 /(2 + sin (x )) aro u n d x = tt/2 ?

7. W h a t is d x (1 + x '^ ) “ Q

8 . Define th e fu n ctio n f { t ) = J ^ d x s in (l + x^e^). W h a t is

S e ttin g U p E x p ec ta tio n s
T h is b o o k is by no m eans a co m p lete coverage of discrete m a th e m a tic s and com puting. We chose some topics
to cover, an d w 'ithin th o se to p ics we left o u t m any advanced concepts to satisfy th e b a n d w id th co n strain ts of
a course. To co m p en sate, we have given a generous helping of quizzes, exercises and problem s:

• p o p quizzes ask you if you are still awake;

• exercises s tre tc h y our m uscles w ith in th e c u rre n t context;

• easier pro b lem s te s t y our know ledge an d provide practice w ith th e concepts;

• h a rd e r pro b lem s guide you th ro u g h som e of th e m ore advanced concepts.

T h e re are several boo k s w hich delve m ore deeply or m ore com pletely into discrete m ath em atics. As for th e
d ee p e r b ooks, we will say m ore in th e epilogue. H ere are som e m ore com plete books a t th is level:

• Discrete Ma t he ma t ic s a nd its Applications, by Rosen.

• Discrete Ma t he ma t ic s with Applications, by E pp.

• M at he ma t ic s f o r C o m p u t e r Science, by L ehm an, L eighton, an d M eyer. (M IT o p e n course.)

A nalogous b ooks for th e th e o ry of c o m p u ta tio n are

• Introduction to the Theory o f Computation, by Sipser.

• E l e me n ts o f the Theory o f Computation, by Lewis an d P ap ad im itrio u .

• Introduction to A u t o m a t a Theory, Languages, a nd Computation, by H opcroft. M otw ani, and U llm an.

T h e in te rn e t is an endless resource for en rich m en t. C om bined w ith th e above books which have m any soh-ed
exercises, th e re is no sh o rta g e of p ra c tic e problem s. M a th em a tic s is like any sp o rt. You have to train .

F in a l E x a m . You relaxed all winter and ran the spring Boston Marathon. You got destroyed.
The next year, you put in some intense 5-hour workouts three days before the race. You got
destroyed. The third year you wisened up and got a coach 3 months ahead of the race. You
took notes which helped fine-tune your 5-hour workouts three days before the race. You still
got destroyed. Finally on the 4th attempt you tried something new. You got the coach as
before and incorporated the coach’s teachings into a 3 hour work-out every day. You were
getting fitter. Three days before the race, you ramped up your training. W ow ! You finished in
the top-10% of runners in the race.,4;? Your Boston Marathon is the final exam in the course.
0. B a c k g r o u n d and P ep T alk

Pep Talk
Society w on’t o bject if you say “M ath isn’t for m e,” and yet i t ’s as ridiculous as saying “R unning isn ’t for me,
or "English isn 't for me.” If you move to USA, to get around you learn English. A nyone can do it. If you
wish to precisely m odel “stuff”, you learn m ath . A nyone can do it, enough said. Yes, m a th is h ard . B u t so is
learning English. M ath is for anyone who will p u t in the effort. You must p u t th e effort.
You also can learn to ‘th in k ”, to be creative and solve problem s. Solving a problem s ta rts w ith strateg ic
considerations, th e forem ost being to p repare th e psychology. Two classics on th a t front are
How to Solve It: A New Aspect o f Mathematical Method by G eorge Polya;
The A r t and Craft o f Problem Solving, by Paul Zeitz.
To get into th e right s ta te of m ind, listen well to th e sto ry of P olya’s little mouse.

“A mouse tries to escape from an old fashioned cage. After many futile attempts
bouncing back-and-forth, thumping his body against the cage bars, he finally finds one
place where the bars are slightly wider apart. The mouse, bruised and battered escapes
through this small opening, and to his elation, finds freedom.” - Polya

Try. try and try again. Vary th e trials th a t you m ay find th e rare favorable p a th to a discovery. T h e sto ry of
the m ouse is for everyone. W hen you hit an in teresting problem ju s t outside th e reach of your fam iliar realm ,
d o n 't throw your h ands in th e air out of subm ission because a solution d o esn ’t m agically ap p ear.
The solution to an interesting problem is not obvious.
T h a t is th e law. W hen you d o n ’t see th e solution im m ediately, d o n 't be discouraged. R ealize th a t such
situatio n s are faced by every explorer entering th e unknow n. All th a t C olum bus needed was a curiosity,
perseverance and a little good luck. C olum bus m arched forw ard despite adversity. A m a th e m a tic s problem
can throw much adversity your way. D on’t fret: d o n ’t give up. Be p atien t: persevere. Be th a t m ouse, try in g
this and th a t. E ventually a sm all opening will ap p ear and you m ay th en walk th ro u g h . M ost im p o rtan tly ,
realize th a t these are th e rules for everyone, from th e a m a te u r to th e professional m ath e m a tic ian .
It m ay be tru e th a t th ere is an innateness to m ath em atical creativity, ju st as not everyone is a M ozart.
-Alas, some m ay ap p ear b e tte r at m ath em atics th a n others. T hey m ay be b e tte r tra in e d , or ju s t b e tte r. In all
cases, it doesn't m atter. Leave them to th e ir business, and you focus on yours. To w arm up to th e im p o rtan ce
of perseverance, try not to tu rn an o th er page until you solve th is visual connection puzzle, w hich we have
lifted directly from The Ar t and Craft of Problem Solving.

P o p Q u iz 0.1 [C onnection puzzle]


Connect tiles of the same letter with wires that don’t cross, enter tiles, or exit the
box (you may bend wires). If you think it can't be done, why not?
Don't be too quick to dismiss either conclusion, or to peek at theanswer.Patience.
Try this and that. Fiddle around. Make sure you understand the challenge.
To solve such problems, "You need brains and good luck. But, you mustalso sit tight
and wait till you get a bright idea.” - Polya.

.Ask this puzzle of your best m ath em atician friends. It will drive home th e fact th a t everyone ha.s to th in k
about a problem . Everyone ha.s to try one or two things th at fail, th e n one or two things th a t p a rtia lly succeed,
riirongh jM'iseverance. these' failures and p a rtia l succes.ses are w hat n ltim ately shine light on th e way out.
O ur prim ary goal is to im part tlu' knowledge and tools of discrete m atlu 'iu aties to you. R u t. you are the
one who mnst use- the.se tools to solve' preible'ins. A nd. te) solve' proble'ins, yeui must prep are yourself m entally
for a tough road. D on't be' afraiel to e'-xjeeriiiK'nt. Don't be afraid to erash your C P U eer e'enrupt your eiperating
system you can always pe'rform a fre'sh install of linux. P ut yemrself in the right fram e of m ind.

[ B e th e m ouse! ]
bet IIS Ix'gin.
Go down deep enough into anything and you will find mathematics.
- Dean Schlicler
If you don't believe mathematics is simple, it is only because you don’t
realize how complicated life is. - John von Neumann
To ask the right question is harder than to answer it. - Georg Cantor
Learning is a treasure that follows its owner. - Chinese Proverb

Chapter 1

A Taste of Discrete M athematics

1: W heting the appetite: epidemics; speed-dating; and, friendship networks.

D iscrete m a th e m a tic s deals w ith “o b je c ts th a t we co u n t.” W hen you cook your favorite T h a i dish, you perform
“d iscrete” ste p s in a sequence. W e can co u n t th o se steps. W h en delegates sit a t a b an q u et, each “discrete”
d eleg ate sits a t a single “d iscrete” seat. Processes th a t tak e place in well defined steps, involving o b jects th a t
com e in in divisible u n its a re th e focus of d iscrete m a th em atic s. T h e m ost fam ous discrete ob ject is th e digital
c o m p u te r w hich ex ecu tes in stru c tio n s in seq uential step s an d uses a discrete scratc h -p a p er called RAM to
sto re in te rm e d ia te re su lts d u rin g its calcu lations. If th a t is n o t enough reason to stu d y th e su b ject, th en for
b e a u ty ’s sake do it. L et us begin w ith som e exam ples of discrete m a th e m a tics in th e real world.

1.1 M odeling Epidem ics


O u tb re a k s of a d ead ly v iru s E BO L A re c u r every now an d th e n . T h e nam e of th e virus is
n o t im p o rta n t. People live on a grid, th in k of a chess b o a rd w ith only w hite squares. Each
grid sq u a re is a p erson. A d jacen t sq u ares th a t share a side are neighbors. Initially, some
p eople are infected , in gray. Infectio n is p e rm a n e n t an d if a t least tw o of your neighbors
are infected to d ay , th e n to m o rro w you will be infected. W h o will u ltim ate ly get infected?
F or exam ple, will th e sq u are sh ad ed red ev entually get infected on th e 7 x 7 grid show n?
L et us tin k e r. T in k erin g is an essen tial p a rt of discrete m ath em atics. So. sta rtin g from
th e in itia l g ray infections, le t’s see how th e infection spread s over a few days. O n each
day, th e p revious infectio n s are in black an d th e new infections are in gray.

■ ■ ■ ■ ■ ■ ■
d ay 1 d ay 2 d ay 3 day 4 day 5 dav 6 day 7 day 8

P o p Q u iz 1 .1
Continue to tinker with the epidemic spread above. Does the red square eventually get infected?

T h e epidem ic sp re a d is indeed a d iscrete process. People are e ith e r infected or not. T im e is discretized into
days. W e identified th e a c to rs as people living on a grid an d th e process dynam ics - a t least two of youi
n eig h b o rs m u st be infected to infect you. T hese are m odeling assum ptions. M odeling assum ptions are critical,
a n d you m ay arg u e w ith th e m . People m ay n o t live on a grid. P erh ap s one neighbor being infected suffices to
infect you. A good m odel is m ore likely to give correct conclusions. T h e beginning of a discrete m athem atical
an aly sis is alw ays a m odel of th e p h enom enon you are analyzing. In our case, th e m odel was a 2-contact
1. A T a s t e of D iscrete M a t h e m a t i c s _______________________________________ 1.2. S peed D atin g

threshold for epidem ic spread on a grid. We do not address m odeling, which is very application dependent.
We care ab o u t w h at hap p en s next. You ask questions. Here are a few interesting questions.
1. Given th e in itial infection, who will u ltim ately get infected?
2. W h a t is th e fewest in itial infections needed to ultim ately infect th e whole com m unity?
3. If you had a few vaccines, w ho should you im m unize to m inim ize th e u ltim ate infection?
4. Given th e cu rren t observed sta te of th e epidem ic, can one determ ine th e “points of e n try defined as th e
sm allest set of initially infected people th a t could have produced th e observed infections?
do get answers, one m ust analyze th e m odel, and th a t is w here discrete m ath em atics enters.

E x e r c ise 1.2
Can you infect the entire 7 x 7 grid, starting with an initial infection of just 6 people?

Before we sw itch gears, observe th a t o u r m odel for EBOLA spread can apply to o th e r contexts: virus spread
in a com puter netw ork; com pany-defaults in an econom ic crisis; adoption of a technology in a social netw ork.

1.2 Speed D ating


You analyze disease spread in your spare tim e, b u t your real jo b is to ru n a sp eed -d atin g club. E very night
you get 16 people, 8 boys an d 8 girls. Anyone can d a te any o th e r person. H ere is how th e night plays out.
You have four tables, and th ere are 4 rounds of speed dating. In each round, 4 people sit a t each ta b le to
“speed d a te ” in a group settin g . R ound 1 of speed d atin g is show n below. T h e le tte rs are th e first initial of
the clients. In round 1, A m eets B , C an d D\ B m eets A , C and D\ and so on.

® ® © @
® ^ ® © ^® ® ^ ®
© © ® ®
You succeed if you hook uj) m any couples, so you w ant everyone to m eet as m any people as possible du rin g
th e night. T h a t’s th e m odel. Here are some in teresting (piestions.
1. W h a t does “ .. .m eet as m any people as possible . . . " m ean? Do you care a b o u t th e average num ber of
encounters your clients had or th e client who had th e fewest encounters?
2. C an one efficiently configure th e rounds so th a t everyone m eets at least 10 peo[)le?
.3, W h at would hapi)en if you random ly assigned clients to tables in each round?
Tinker a little. C an yon come up w ith good ways to configure th e 4 rounds of sp eed-dating. See if you can
hgure out why I am so confident th a t no m a tte r how much you tinker, no one will m eet m ore th a n 12 people.
1 can also say th a t if you configured th e rounds random ly, everyone would expect to m eet a b o u t !) people, so
random is not th a t bad. You can n o t b e a t 12 for anyoiii', and random gets yt)u to a b o u t 9 for ew ry o n e .

1.3 Friendship Networks and Ads


Six ])eople Alice (.4). Bob (Zi). Cliarles (C ), David {D). Edw ard {E) and Fiona {F) form a
friendship or social network. Circles are th e people and tlii' links arc the friendships Ix'tw een
l)airs of p('oplc. Two p('oplc, i.e. circles, a n ' friends if tlu'y are coniu'cted by a line. \'o u might
recognize the friendship cli(iiies b('tweeu j.- l.C ,/) } and { D , B . K ] whili' /•' looks likt' a loner.'
W e can visually analyze our small friendship lU'twork, but what about an online social netw ork w ith a
billion people.^ \ \ c ccrtaiiily can I draw it on this jiage. So how would you gii about identifying all th e large
Iricndsliii) cli(|iies? T his tiiriis out to b e a vi'iy iiitcresting challcngi', but why do wi' care?
'In n tri('inlslii|) clicinc, ('vcrvdnc is trirnils wilh cvcrx(imi'-cIsc.
1. A T a s t e o f D i s c r e t e M a t h e m a t i c s _______________ M o d e lin g C om p u te r s

A n a d v e rtise r w ho w an ts to m a rk e t a now sm a rtp h o n e m ay try to convince David (D) to ad o p t th e device


in th e hopes th a t everyone in D av id ’s friendship cliques m ight also buy th e device. T h a t would be a huge
payoff. To m ak e such ad v ertisin g d ream s in to realities, we need to m odel social netw orks in a way th a t can be
re p re se n te d on a co m p u ter, an d find all th e large friendship-cliques or social “com m unities” so th e advertiser
can id en tify w hom to ta rg e t. F in d in g th e large cliques is a to u g h discrete m ath em atics problem .

1.4 M odeling Com puters


Y ou’ve now seen som e flavors of discrete m a th em atic s. C o m p u ter scientists use discrete m ath em atics to m odel,
analy ze a n d solve real w orld problem s. T h e su m m it of our ad v en tu re is going to be a grand m odel, a m odel
of th e d ig ita l c o m p u te r a model o f computing. We w an t a realistic m odel th a t ca p tu re s your desktop as well
as sm a rtp h o n e , G P U or fitb it. B u t, it should be sim ple enough to analyze, for we have deep questions to ask.
1. W h a t can we co m p u te?
2. W h a t c an ’t we c o m p u te?
3. A re th e re th in g s we can c o m p u te in principle, b u t it tak es to o long?

In answ ering th e se q u estio n s, we w ill jo u rn ey th ro u g h th e w orld of discrete m ath em atics. d d d


W h a t is co m p u tin g ? L e t’s get a feel for it using a dom ino puzzle. T h e to p and b o tto m
e n try in each of th e th re e dom inos d i , d 2 , d s on th e rig h t is a b in ary string. A sequence
0 oT no
100 llil)
o f d o m in o es p ro d u ces a com bined dom ino in w hich th e to p strin g is th e co n caten atio n of
all th e to p strin g s in o rd er, a n d sim ilarly for th e b o tto m string. For exam ple,

dsdids —
TTojfo pio' w hich gives th e com bined dom ino
1100110

iJ b o o J b i. 1110011

To solve th e dom ino puzzle, find a sequence of dom inos for w hich th e com bined to p and b o tto m strings m atch.
R e p e titio n o f d om inos is allow ed an d you need n o t use all dom inos. In th is case, you can verify th a t d 3 d 2 d 3 d\
solves th e puzzle. T h a t ’s nice, b u t w h a t does a sim ple k id s’ puzzle have to do w ith com puting? C ould you
w rite a p ro g ra m to solve th e dom ino puzzle? Y our p rogram w ould read in a te x t file w here each row of the
file describ es a dom ino, tw o co m m a s e p a ra te d b in ary strin g s. Your program should o u tp u t a sequence of
dom inos w hich solves th e puzzle, or say it c a n ’t be done. Now, does th a t look like a com puting problem to
you, so m eth in g t h a t could be o n a p ro g ram m in g assignm ent?

C h a l l e n g e . I ’m feeling sly an d evil. A prize of $ 1 ,0 0 0 inflation ad ju ste d goes to th e first correct


p ro g ra m th a t solves th e dom ino puzzle for any in p u t file of dom inos. T h ere are tw o catches.
(i) Y our p ro g ra m m u st stop a n d o u tp u t th e correct answ er no m a tte r w h a t th e in p u t dom ino file.
(ii) You m u st give a proof t h a t y our p ro g ra m is correct.

W e c a n ’t rely on in tu itio n to say w h a t is a n d is n o t co m puting. W e need a precise m odel. Stay tuned.

1.5 P ro o f
It is H u m an to seek proof, to ask why. If your neighbor says ev acuate because of hurricanes, w ouldn t you
seek verificatio n ? If you claim to have a p e rp e tu a l m otion m achine, I w on’t take you a t your word. We each
have different th re sh o ld s to be convinced of som ething. In life, a few tru e instances are often enough - th a t
is in d u ctiv e proof. T h e su n h as risen every m orning. T h a t’s enough for us e arth y beings to conclude th a t
th e su n will alw ays rise. Logically, a few cases of th e sun having risen does not prove “T h e sun rises every
m o rn in g .” I t only m ean s th e s ta te m e n t is n o t obviously false. In m ath em atics, we have th e sam e urge for
v erification, b u t o u r e x p e c ta tio n s are high. W e require ded u ctiv e proof.
In th e s p e e d -d a tin g ritu a l on page 8 , n o b o d y m eets m ore th a n 12 people. Here is a jiroof. In any round a
p e rso n m e e ts a t m o st 3 new people. So, a fte r 4 ro u n d s th e y m eet a t m ost 4 x 3 = 12 new people. A ren t you
u tte rly convinced? T h e b e a u ty of d ed u ctiv e p ro o f is th a t it leaves no room for d o ubt.
1. A T a s te o f D is c r e t e M a th em a tics 1.5. P roof

B e c o m in g G o o d a t D is c r e t e M a t h . You’re no stran g er to reasoning in real life. You can look a t a


rental co n tract and determ ine when you can break th e lease w ith o u t penalty. M athem atics, reasoning a b o u t
ab stra c t objects, is sim ilar yet seems difficult. D on’t fret. You had a lifetime of train in g for everyday reasoning.
W ith sim ilar train ing , you can build stam in a for m athem atics. B u t you m ust be diligent. M ath em atics is no
spectato r sport. D o n 't "read” or “stu d y ”. Do\ W ork th e exam ples, exercises and problem s. W rite in th e book.
A nno tate definitions and theorem s w ith p ictures or sim ple exam ples. Make sure you u n d e rstan d w h a t is being
said. No one speed reads m athem atics. Even to those fluent in th e language, it is a foreign tongue.

In m athem atics, if you’re m issing som ething, you’re m issing everything. Work th e te x t, quizzes
and exercises, w ith pencil and p a p e r in hand. You m ust agree w ith th e sm allest detail.

It is w orth showcasing th e recurring workflow an ex p ert uses to solve a problem . M em orize it.

1: M odel th e problem you are try in g to solve using a discrete m a th em a tic al object.
2: T inker w ith easy cases to u n d erstan d th e m odel. T in k e r in g is e s s e n tia l.
3: Based on th e tinkering, form ulate a conjecture a b o u t your problem m odel.
4: Prove th e conjecture and m ake it a theorem . You now know som ething new.

The novice builds th e m odel and stares a t it w ith o u t know ing w h at to prove, because of a failure to tinker.

E x e r c is e 1 .3 [A S isy p h e a n P u z z le to T e e th e On]
Zeus punished King Sisyphus of Corinth to an eternity of rolling a boulder up a hill
only to see it roll down when near the top. Sisyphean tasks are laborious yet futile.
Three boxes start with 100, 200 and 300 boulders, the configuration (100,200,300).
A move places a stone from one box into another. For example, moving a stone
from the box with 200 to the box with 100 gives configuration (101,199,300).
Each move gains or loses gold coins and debt is allowed. The gain is larger for a
move from a box with many stones to a box with few stones. Specifically,
gain = ^ stones left in originating box (after move) — # stones in destination box (before move).
Here is a sequence of moves with the corresponding payments.
start configuration end configuration gain
(100.200.300) (101,199,300) 199 - 100 = +99
(101.199.300) (101,198,301) 198 - 3 0 0 = - 1 0 2
(101.198.301) (102.198,300) 300- 101 =+199
The profit for these three moves is +196 coins (= 99 - 102 + 199). Sisyphus can move stones, but must
return to the start configuration. How much can Sisyphus profit? Can you prove it?

M a t h e m a t i c s a n d ‘" P a r tia l C r e d i t ” . 1 licv doii t mcsli well, lii scIiodI, i>artial r redit is a learuiug-aiile. It s
com forting to know you're close to a solution, and p a rtial credit delivers the m essage. .M athem atics is not so
forgiving. A proof is right or wrong. T h ere's no alm ost |)roven. C o m p u ter program s are m a th e m a tic a l o b jects
I iinning on inathem atical d e\’ices. program works or it doc'sn t. It a builder m akes one w rong join th e whole
stru ctu re can fall. ’\o n don t g(>t .(-crt'dit tor sending soiiK'one to the m oon but forgetting to bring th e m back.
A in-ograin that m ostly works is a cata.strophe w aiting to happen. Check ont Therac-25 on W ikipedia;

"Because of concurrent programming errors, it sometimes gave its patients radiation doses
that were hundreds of times greater than normal, resulting in death or serious injury."

W ho cares if Therac-25 had one bug or 17 bugs'.’ Should we be lenimit because Therac-25 w orked 99 9'T of th e
tim e, only failing in ran- boundary ca.ses'.’ Then- is a fundam ental ditlereiuv lu-tween alg o rith m s th a t alwavs
work an.l henristics which often work, but w ithout g u a ra n t.v . bih- docs not give credit for p a rtia l solutions
C ritical coinpntm- sy.steins from trafli.- control to robotic surgerv to self-driving cars m ust fullv work all
the tiiiK-. otherwi.se people will sulfer. Take th e precaution to proiH yonr program w orks O th e rs relv on it

H)
1. A T a s te o f D is c r e t e M a th em a tics 1 g P r o b ie m s

1.6 Problem s

P r o b le m 1 .1 . The parity of an integer is 0 if it is even and 1 if it is odd. Which operations preserve parity:
(a) Multiplying by an even, (b) Multiplying by an odd. (c) Raising to a positive integer power.

P r o b le m 1 .2 . W hat's wrong with this comparison: Google's nett worth in 2017, about $700 billion, exceeds the
G D P of many countries, e.g. Argentina's 2016-GDP was about $550 billion. (Look up nett worth and GDP.)

P r o b le m 1 .3 . Consider 2-contact e b o l a on a grid. You have one immunization vaccine. iiii p, - , , ,


W e show two different immunization scenarios, where you immunize the green square. Show !S f5 ::
the final infection in each case and determine which person you prefer to immunize?
How many vaccines are needed to ensure that nobody else gets infected? ■
P r o b le m 1.4. For the speed-dating problem with 16 people, 4, B , . . . , P and four tables, arrange the rounds so that:
(a) In two rounds, everyone meets 6 people. (c) In four rounds, everyone meets 12 people.
(b) In three rounds, everyone meets 9 people. (d) In five rounds, everyone meets 15 people?

P r o b le m 1.5 ( S o c ia l G o lfe r P r o b le m ) . 32 golfers form 8 groups of 4 each week. Eachgroup plays a round of
golf. No two golfers can be in the same group more than once. For how many weeks can this golfingactivity go on?
(a) "Prove" that this golfing activity cannot go on for more than 10 weeks.
(b) Try to create a scheduling of players for as many weeks as you can. (10 is possible.)
(c) How is this problem related to the speed-dating problem?
In general you must schedule g groups of golfers each of size s for w weeks so that no two golfers meet more than once
in the same group. Given (g ,s,w ), can it can be done and what is the schedule? This is a hard problem.

P r o b le m 1.6. Students form a friendship network (right). To advertise a new smartphone,


you plan to give some students free samples. Here are two models for the spread of phone-adoption.
Model 1 ( W e a k M a j o r i t y ): People buy a phone if at least as many friends have the phone as don't.
Model 2 ( S t r o n g M a j o r i t y ): People buy a phone if more friends have the phone than don't
(a) Use your intuition and determine the most "central" of the people in this friend-network.
(b) If you give a phone only to this central node, who ultimately has a phone in: (i) Model 1 (ii) Model 2?
(c) How many phones must you distribute, and to whom, so that everyone switches to your phone in Model 2?
(d) Repeat part (c), but now you cannot give a phone to the central node.
(A slight change to a model can have a drastic impact on the conclusions. A good model is important.

P r o b le m 1.7. Five radio stations (red stars) broadcast to different regions, as shown. The FCC
assigns radio-frequencies to stations. Two radio stations with overlapping broadcast regions must
use different radio-frequencies so that the common listners do not hear garbled nonsense.
W hat is the minimum number of radio-frequencies the government needs?

r Discrete math problems are like childhood puzzles. Parity, symmetry and invariance often yield simple solutions.

P r o b le m 1 .8 . Two players take turns placing identical circular quarters on a circular table. Coins cannot overlap and
must remain on the table. The last person to play wins. Do you want to go first or second? [Hint: symmetry.]

P r o b le m 1 .9 . A chocolate-bar has 50 squares (5 x 10). How many breaks are necessary to break the bar into its 50
individual squares? You may only break a piece along a straight line from one side to the other. No stacking allowed.
[Hint: Define the invariant A = [[pieces — [[breaks. What happens to A with each break?]
P r o b le m 1 .1 0 . A single-elimination tournament has 57 players. Players may receive byes in some rounds. How many
matches are played before a winner is declared? Does it depend on how the tournament is configured? [Hint: Define
the invariant A = [[players remaining + [[matches played. What happens to A after a match?]
P r o b le m 1 .1 1 . Five pirates must share 100 gold coins. The most senior pirate proposes a division of coins and all
pirates vote. If at least half the pirates agree, the coins are divided as proposed. If not, the proposer is killed and the
process continues with the next most senior pirate. A pirates priority is to stay alive, and then to get as much gold as
possible. W hat should the senior pirate propose? [Hint: Sometimes it is better to start with a smaller problem.]

P r o b le m 1 .1 2 . Can you color squares of a 9 x 9 grid blue or red so that every square has one opposite color neighbor
(neighbors are left, right, up or down).

11
1 .6 . P roblems
1. A T a s te o f D is c r e t e M a th em a tics

P r o b le m 1 .1 3 . 57 security guards are positioned so that no two pairs of guards are the same distance apart. Every
guard watches the guard closest to him. Is there an arrangement of the guards so that every guard is being watched?

P r o b le m 1 .1 4 . 10 trucks each have 100 gallons of fuel and use 1 gallon of fuel per mile. How far can you deliver a
chest that fits in one truck? (You can transfer the chest and/or fuel from truck to truck.)

P r o b le m 1 .1 5 . A camel owner wants to sell his 300 bananas at a market 100 miles away. The camel can carry at
most 100 bananas, but eats a banana for every mile travelled. How many bananas can be sold at the market?

P r o b le m 1 .1 6 . Show that fewer than n initial infections cannot infect the whole n x n grid in 2-contact e b o l a .
[Hint: For a square, define 4-outgoing links (N,S,E,W) to its 4 neighbors. Pretend boundary-squares have neighbors.
For an infected square, remove all outgoing links to infected neighbors. Let A, the "wavefront o f the infected area, be
all remaining outgoing links for infected squares. Can A increase? What is A when all squares are infected?]

P r o b le m 1 .1 7 (C h o m p ). In the grid of chocolate, if you eat the top-left square, you lose.
Each player takes turns to eat a square plus all the chocolate below it and to the right. We show
a possible first move and the chocolate that removed in blue. Do you want to go first or second?

'/y X/
[Hint: Either eating the bottom right piece wins or not. If not, what should you do?]

P r o b le m 1.18. A man has a boat which can carry him and one other thing. How can the man get a fox, a chicken
and a bag of corn across the river, if, when unattended, the fox eats the chicken and the chicken eats the corn.

P r o b le m 1.19. Tasks involving covering an area using different shaped tiles are a treasure trove of interesting puzzles.
(a) Remove the top left and bottom right squares on an 8 x 8 chess board. Can you tile the remaining 62 squares
with 31 dominos? [Hint: Show that #black squares - ifw hite squares is an invariant when you place a domino?]
(b) On an 8 X 8 chess board, show that if you remove any two squares of different colors, you can
tile the remainder of the board with dominos. [Hint: See illustration on the right. We show
a path starting from the top-left. You can tile the board by placing dominos along this path.
You may assume that the first square removed is white (why?). Show that you can still tile
the remaining board along the path.].
(c) On a 8 X 8 chess board, show that if you remove any corner square, you cannot tile the
remainder of the board with straight triominos ( I I I I). It is possible to tile the board with
triominos after removing one square. Can you identify which squares can be removed (there
are 4)? [Hint: See illustration on the right. We have colored the squares on the chess board
so that a triomino must cover one square o f each color.].
(d) Can you cover a 10 x 10 chessboard with 25 straight tetrominos ( I I I I I). If yes, how?

P r o b le m 1 .2 0 . There are 13 purple, 15 red and 17 green chameleons. When chameleons of different colors meet they
both transform to the third color. Will all 45 chameleons ever be the same color? [Hint: Consider A = ffp u rp le -ifre d .]

P r o b le m 1.21. A building has 1000 floors. You wish to determine the highest floor from which you can drop an
egg without the egg breaking. If you had 1000 identical eggs, you could drop one from each floor and seewhicheggs
survive. How many egg drop trials do you need if you have: (a) One egg. (b) Two identical eggs.

P r o b le m 1.22. Four boys take Imin, 2min, 7min and lOmin to cross a bridge. The bridge only holds two boys at
a time. It is dark and there is only one flashlight, which is needed to cross the bridge. Two boys cross at the speed of
the slower boy who holds the flashlight. All four boys must get across the bridge. If the fastest boy acts as chauffeur
for the other three, all four can cross in 21 min. Can all four get across the bridge faster?

P r o b le m 1.23. Two consecutive positive numbers n and n + 1 are given to you and a friend. One player gets n
and the other gets n. f I, at random. You look at your number and shout out your opponents number if youknow it,
otherwise you pass the turn to your opponent. Will this game ever stop?

P r o b le m 1.24. You have a gold chain with 63 links. You would like to cut some links to obtain a set of links of
different sizes. You goal is to be able to represent any number of links from 1 to 63 as a collection of someof your
pieces in order to trade. What is the minimum number of links you need to cut to be able to do so?

P r o b le m 1.25. Three ants a.h.c are on the vertices .1. Ii.< 'o f a triangle. Each ant randomly picks one of the other
vertices and walks to it. What are the chances that no ants colide on an edge or at a destination vertex)?
What if there are four ants ii.h.c.il on the vertices .1, H.( /) of a tetrahedron?

12
1. A T a s t e o f D i s c r e t e M a t h e m a t i c s ______________________________ ^ 0 P r o b lfm s

P r o b le m 1 .2 6 . Two players alternately pick numbers without replacement from the set {1, 2 , 3 ,..., 9 }. The first
player to obtain three numbers that sum to 15 wins. What is your strategy?

P r o b le m 1 .2 7 . A maharaja has 100 amphoras of wine. A traitor poisons one amphora, gets detected and killed.
The poisoned amphora is not known and the poison kills in exactly one month. The maharaja uses tasters to tell if wine
is safe, depending on whether the taster lives or dies after a month.
(a) The maharaja wants to safely drink wine in a month, what is the minimum number of tasters he needs.
(b) The maharaja wants to use all safe amphoras to throw an orgy in a month. What is the minimum number of
tasters he needs. A simple solution is 100 tasters, one on each amphora. One can do much better though.

P r o b le m 1 .2 8 . Two players take turns picking a coin from either end of a line of 20 coins. In the example below,
if player 1 always takes from the left and player 2 from the right, then player I's coins total 80, and player 2 ’s total is 146.

- © 0 0 ® ® © © © © © © ® ® © ® © ® © © ©
The player with the highest total wins, player 2 in the example. Do you want to play first or second?

P r o b le m 1 .2 9 . To weigh sugar, you have a comparison scale that can compare weights (illustrated).
Give the fewest weights that are needed to measure out 1 . 2 , . . . , 1 2 1 pounds of sugar.
For example, to measure 3 pounds of sugar with 2 and 5 pound weights, place the sugar and 2 pounds
on the one side, and 5 pounds on the other side. The sugar weighs 3 pounds if the scale balances.

P r o b le m 1.30. More than half of 99 processors are good and the rest are bad. You may ask a processor to evaluate
another processor. A good processor always gives the correct answer and a bad one gives the wrong answer. How many
times must you ask some (any) processor to evaluate another before you can identify a good processor?

P r o b le m 1.31. A plane has fuel capacity to fly half way around the world. A plane can refuel from another plane in
mid-air. All planes are at the airport. How many planes and tanks of gas do you need so that you can support a single
plane to fly around the world? All planes must return to the airport.

P r o b le m 1.32 . 25 horses have different speeds. You can race up to 5 horses at a time and observe the order in
which the horses finish. You have no stop-watch. Show that 7 races suffice to determine the fastest 3 horses.

P r o b le m 1.33. 100 prisoners are up for a pardon. Prisoners will be lined in random order with a randomly chosen
red or blue hat on each head. A prisoner sees only those ahead of them in the line. The last in line shouts the color of
his hat. If he gets it right, he is pardoned. Then the second-last prisoner gets a chance and so on until the first in line.
The night before pardoning, the prisoners may strategize. During the pardoning process, the prisoners cannot commu­
nicate except to shout out a hat color. If the prisoners optimally strategize the night before, what are the chances that
the first to shout is pardoned, the second to shout, the third to shout and so on up to the final prisoner?

P r o b le m 1.34. At a puzzle-party with 32 guests, the host will shuffle a 52-card deck and paste a card on each guest's
forhead. A guest will see every other guest's card but not their own card. After the cards are pasted on forheads, each
guest, one by one, must shout out a card (e.g. 4<|k). At the end the number of guests who correctly shouted out their
card is multiplied by $1 , 0 0 0 to get a prize amount which is split evenly among all guests.
Intense discussion breaks out among the guests as they arrive. A philosopher suggests breaking into 16 pairs. In each
pair, the first to shout says their partner's card so the partner can guess correctly. This strategy guarantees $16,000. A
FOCS-student claims, "I can guarantee we will share $31,000.” Can you come up with a strategy to guarantee $31,000?

P r o b le m 1.35. Three friends A , B , C each have tokens a , 6 ,c. At every step a random pair of friends is picked
to swap whatever tokens they currently have. If the first pair picked is ( A , B) and then {A, C) then the tokens are
distributed c, a, b after the two swaps. What are the chances each friend has their own token after 2015 swaps?

P r o b le m 1.36. On a table are some red and blue cards. Two players take turns picking two cards. If the two cards
picked are the same color, both cards are replaced by one red card. If the two cards picked are different colors, both
cards are replaced by one blue card. When one card remains, you win if it is blue and your opponent wins if it is red.
(a) Must the game always end, or can it go on forever?
(b) Who wins if there are 8 blue and 11 red cards to start? Does it matter who goes first? [Hint: Parity invariant.]

P r o b le m 1.37. Dad normally picks Sue from school which ends at 3pm. School ended early at 2pm, so Sue started
walking home and dad picked her up on the way, returning home 20min earlier than usual. For how long did Sue walk?

P r o b le m 1.38. Pick any six kids. Show that either 3 of them know each other or 3 of them do not know each other.

13
1. A T a s t e of D iscrete M at h em at ics
1 .6 . P roblems

P r o b le m 1 .3 9 . Fifteen houses are in a row. A thief robs a house. On each subsequent night, the thief robs a
neighbor of the house robbed the previous night. The thief may backtrack and rob the same house. A policeman can
watch any one house per night. Is there a strategy for the policeman to guarantee catching the thief?

P r o b le m 1 .4 0 . 5 of 10 coins are showing heads. You can move coins to form two sets, and you can flip over any
coins you wish. How will you guarantee that both sets have the same number of heads showing, blindfolded?

P r o b le m 1 .4 1 . Baniaz and her twin kids pass a gumball machine with 2 red, 3 blue and 4 green gumballs. Gumballs
cost 1$ each and come out randomly. Baniaz buys gumballs until she can give each of her kids one gumball of the same
color. In the worst case, how much must Baniaz be willing to spend? What if she had quadruplets instead?

P r o b le m 1.42. Two 1 meter fuses (strings) each burn non-uniformly in 60 sec. How can you measure 45 sec?

^ Here come hard problems that take you to the boundaries of mathematics and computing, j

P r o b le m 1 .4 3 ( C o lla t z /3 n + 1 P r o b le m ) . Given an integer n > 1, repeat as follows until you reach 1 ;


n/ 2 if n is even;
I 3n + 1 if n is odd;
Example: 6 ->• 3 10 5 -> 16 ^ 8 -A 4 2 1. Do you reach 1 for every n? This “simple" problem is unsolved!

P r o b le m 1 .4 4 (S u b s e t S u m ). Find two different subsets of this set of one hundred 27-digit numbers, with the
requirement that the numbers in each subset
1: 5719825393567961346558155629 35; 8794353172213177612939776215 69 7549684656732941456945632221
2: 5487945882843158696672157984 36: 2989694245827479769152313629 70 2397876675349971994958579984
3: 4767766531754254874224257763 37: 6117454427987751131467589412 71 4675844257857378792991889317
4; 1855924359757732125866239784 38: 2761854485919763568442339436 72 2832515241382937498614676246
5: 4289776424589197647513647977 39: 6884214746997985976433695787 73 8755442772953263299368382378
6: 7967131961768854889594217186 40: 8671829218381757417536862814 74 9833662825734624455736638328
7: 2572967277666133789225764888 41: 9431156837244768326468938597 75 5298671253425423454611152788
8: 1294587141921952639693619381 42: 4788448664674885883585184169 76 9857512879181186421823417538
9: 4764413635323911361699183586 43: 3624757247737414772711372622 77 1471226144331341144787865593
10: 1474343641823476922667154474 44: 9361819764286243182121963365 78 3545439374321661651385735599
11; 2578649763684913163429325833 45: 9893315516156422581529354454 79 6735367616915626462272211264
12: 5161596985226568681977938754 46: 5913625989853975289562158982 80 2141665754145475249654938214
13: 2242632698981685551523361879 47: 8313891548569672814692858479 81 8481747257332513758286947416
14: 7474189614567412367516833398 48: 2265865138518379114874613969 82 9961217236253576952797397966
15: 6211855673345949471748161445 49: 3477184288963424358211752214 83 9941237996445827218665222824
16: 4942716233498772219251848674 50: 6321349612522496241515883378 84 6242177493463484861915865966
17: 5516264359672753836539861178 51: 1796439694824213266958886393 85 4344843511782912875843632652
18: 5854762719618549417768925747 52: 6366252531759955676944496585 86 7568842562748136518615117797
19: 5313691171963952518124735471 53: 8545458545636898974365938274 87 2776621559882146125114473423
20: 6737691754241231469753717635 54 3362291186211522318566852576 88 6174299197447843873145457215
21: 4292388614454146728246198812 55: 8464473866375474967347772855 89 5387584131525787615617563371
22: 4468463715866746258976552344 56: 2892857564355262219965984217 90 5317693353372572284588242963
23: 2638621731822362373162811879 57; 4296693937661266715382241936 91 6612142515552593663955966562
24: 1258922263729296589785418839 58: 8634764617265724716389775433 92 1314928587713292493616625427
25: 4482279727264797827654899397 59: 8415234243182787534123894858 93 2446827667287451685939173534
26: 8749855322285371162986411895 60: 2267353254454872616182242154 94 9786693878731984534924558138
27: 1116599457961971796683936952 61: 4689911847578741473186337883 95 2926718838742634774778713813
28: 3879213273596322735993329751 62: 4428766787964834371794565542 96 3791426274497596641969142899
29: 9212359131574159657168196759 63: 7146295186764167268433238125 97 2831727715176299968774951996
30: 3351223183818712673691977472 64: 2273823813572968577469388278 98 3281287353463725292271916883
31: 8855835322812512868896449976 65: 6686132721336864457635223349 99 9954744594922386766735519674
32: 4332859486871255922555418653 66: 3161518296576488158997146221 100 341433914354532429S85324S718
33: 2428751582371964453381751663 67: 1917611425739928285147758625
34: 6738481866868951787884276161 68: 3516431537343387135357237754

P r o b le m 1 .4 5 (V eriH or for “H o llo Wi


In p u t: Any f '' ' program F.cpp (an ASCII text file).
O u tirn t: Yes if:when you compile and run F.cpp. it prints "Hello World", and eventually stops.
No if:when you compile and run F.cpp. the program loops forever or stops without printing "Hello World”
Would you have guessed that a solver forthe domino puzzle (Section 1.4) can be used to build a Hello-World-verifier?
Another Random Scribd Document
with Unrelated Content
pictures, at sunny midday, or beneath the hushed twilight, or in the expectant morning
before [297]the shadows come,—all these had suddenly taken wing, driven away by
mud-grubbing animals with a notion in their dull heads that they wanted deeper water
about the site they had chosen for their house of sticks. It was too bad, too hopeless! I
might have prevented the ruin had I known; but now it was beyond all remedy. With a
different interest, therefore, and still resentful that my pond was spoiled as thoroughly
as any lumberman would have spoiled it, I made my way around the flood to examine
the beavers’ work at the outlet.

[298]

[Contents]
XV
Beaver Work

Hidden among the larches at the lower end of my pond was a tiny outgoing stream,
which had proved hard to find when first I explored the region, and almost impossible
to follow afterward. Under a fallen log, so weathered and mossy that it seemed part of
the natural shore, a volume of water escaped without ripple or murmur, wandering
away under bending grasses to lose itself in an alder swamp, where innumerable
channels offered it lingering passage. From the swamp it found its way, creepingly,
among brooding cedars to a little brook, which went singing far down through the
woods to Upper Pine Pond; and beyond that on the farther side was a long dead-
water, [299]and then Pine Stream making its tortuous way through an untraveled
region to the Penobscot. The nearest beavers, a colony of four lodges which I
unearthed on a hidden branch of Pine Stream, were twelve or fifteen miles away, as
the water flowed; yet over all that distance an exploring family had made its lonely
way, guided at every turn by the flavor of distant springs, till one after another they
crept under the fallen log and entered my pond, which was solitary enough to satisfy
even their pioneer instincts. They had first picked a site for their new lodge, on a point
overlooking the lower half of the pond, and had then gone back to the outlet to raise
the water.

Their dam was a rare piece of wild engineering; so much I had to confess, even while
I wished that the beavers had chosen some other place to display their craft. Finding
where the water escaped, they stopped the opening beneath the log, and made a
bank of mud and alder-brush above it. This bank was carried out a dozen feet or more
on either side of the stream, the ends being bent forward (toward the pond above) so
as to make a very fine concave arch. On a small or quiet stream like this, beavers
almost invariably build a straight dam; and where swift water calls for a stronger or
curving structure, they present the convex side to the current; but here they had
[300]reversed both rules, for some reason or impulse which I could not fathom,—
except on the improbable assumption that the animals could foresee the end of their
work from the beginning. The finished dam was an amazingly good one, as you shall
see; but whether it resulted from planning or happy experiment or just following the
water, only a certain old beaver could tell.

Since there was no other outlet to my pond, the beavers were obliged to build here;
but the site was a poor one, the land being uniformly low on all sides, and no sooner
did they finish their dam than the rising water flowed around both ends of it. To
remedy this they pushed out a curving wing from either end of their first arch, so that
the line of their dam was now a pretty triple-curve. Again and again the outgoing
water crept around the obstacle; each time the beavers added other curving wings,
now on this side, now on that, bending them steadily forward till the top of their dam
suggested the rim of an enormous scallop-shell. Then, finding the water deep enough
for their needs, they thrust out a straight wing from either end of their dam, resting
their work on the slopes of two hillocks in the woods, some fifty yards apart,—this in a
straight line, or across the hinge of the scallop-shell: if measured on the curves, their
dam was three or four times that length. Their [301]next task was to build a lodge on
the point above; then they dug a canal through the bog to the nearest grove of
hardwood, and cut down a liberal part of the trees for their winter supply of bark. The
branches of these trees had been cut into convenient lengths, floated through the
canal, and stored in a great food-pile in the deep water near the lodge.

When I found the dam, several deer (to judge from the tracks) were already using the
top of it as a runway in passing from the flooded ground on one side of the pond to
the other. From either end a game-trail led upward along the shore, no longer
following immemorial paths over the bog, which was submerged with all its splendor
of color, but making a new and rougher way through the black growth. When I
followed one of these trails it led me completely around the pond, going confidently till
it neared the salt-lick, where it halted, wavered and trickled out in aimless wanderings.
There, where once the ground was trodden smooth by many feet, was now no ground
to be seen. The precious spring, over which a thousand generations of deer had
lingered, had vanished in a dull waste of water. Twice I watched the place from early
morning till owls began to cry the twilight; in that time only a few animals appeared,
singly, at long intervals; and after wandering about as if [302]seeking something and
finding it not, they disappeared in the dusky woods.

And so I went away, looking for the last time sadly on the little pond, as upon a place
one has owned and loved, but which has passed into other hands. Though the wild
ducks still breed or gather there, it is no longer the same. There is no restful spot from
which to watch the waters dance with the wind, or frown at the cloud, or smile at the
sunshine; the little larches are all dead beside their ancestors; the carpet of colored
moss is but a memory. When the beavers go to pioneer a remoter spot, I shall break
their dam and let the water return to its ancient level. Then, if happily I live long
enough for another fringe of larches to grow, and another mossy rug to crimson under
the waning sun, perhaps it will be my pond once more.
THE END
[Contents]
Colophon
Availability

This eBook is for the use of anyone anywhere at no cost and with almost
no restrictions whatsoever. You may copy it, give it away or re-use it under
the terms of the Project Gutenberg License included with this eBook or
online at www.gutenberg.org ↗️.

This eBook is produced by the Online Distributed Proofreading Team at


www.pgdp.net ↗️.

Metadata

How animals talk and


Title: other pleasant studies of
birds and beast
William Joseph Long Info
Author:
(1867–1952) https://viaf.org/viaf/15260441/
Charles Copeland Info
Illustrator:
(1858–1945) https://viaf.org/viaf/56202685/
File
2024-02-21 18:51:31
generation
UTC
date:
Language: English
Original
publication 1919
date:

Revision History

2024-02-04 Started.

Corrections
The following 3 corrections have been applied to the text:

Edit
Page Source Correction
distance
98 show-shoes snow-shoes 1
141 ‘ “ 1
161 How how 1
*** END OF THE PROJECT GUTENBERG EBOOK HOW ANIMALS
TALK ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright
in these works, so the Foundation (and you!) can copy and
distribute it in the United States without permission and without
paying copyright royalties. Special rules, set forth in the General
Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the


United States and most other parts of the world at no
cost and with almost no restrictions whatsoever. You may
copy it, give it away or re-use it under the terms of the
Project Gutenberg License included with this eBook or
online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the
country where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of the
copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute
this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite
these efforts, Project Gutenberg™ electronic works, and the
medium on which they may be stored, may contain “Defects,”
such as, but not limited to, incomplete, inaccurate or corrupt
data, transcription errors, a copyright or other intellectual
property infringement, a defective or damaged disk or other
medium, a computer virus, or computer codes that damage or
cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES -


Except for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU
AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE,
STRICT LIABILITY, BREACH OF WARRANTY OR BREACH
OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE
TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER
THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR
ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE
OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF
THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If


you discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person or
entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you do
or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like