92 Chapter 4 Number Theory
solution that approach gives:
.0; 0/
fill 21
! .21; 0/
pour 21 into 26
! .0; 21/
fill 21
! .21; 21/
pour 21 into 26
! .16; 26/
empty 26
! .16; 0/
pour 21 into 26
! .0; 16/
fill 21
! .21; 16/
pour 21 into 26
! .11; 26/
empty 26
!

numbers are getting smaller quickly (by at least a factor of 2 every two steps) and
so
Eulers Algorithm is quite fast. The fact that Euclids Algorithm actually produces
the GCD (and not something different) can also be proved by an inductive invariant
arg

In this problem, a matching will mean a way of assigning every man to a woman
so that different men are assigned to different women, and a man is always
assigned
to a woman that he likes. For example, one possible matching for the men is shown
in Figure 5

average, minority students tended to study with non-minority students more than
the other way around. They went on at great length to explain why this remarkable
phenomenon might be true. But its not remarkable at allusing our graph theory
formulation, we

is degree-constrained if deg.l/ _ deg.r/ for every l 2 L and r 2 R.
For example, the graph in Figure 5.11 is degree constrained since every node on
the left is adjacent to at least two nodes on the right while every node on the right
is incident to at mos

D 1 since there is precisely one walk of length 1
between vi and vj . Moreover, fvi ; vj g 2 E means that a.1/
ij
D aij D 1. So,
P.1/
ij
D a.1/
ij in this case.
Case 2: fvi ; vj g . E. Then P.1/
ij
D 0 since there cannot be any walks of length 1
between v

distinction since the graphs look the same!
Fortunately, we can neatly capture the idea of looks the same through the notion
of graph isomorphism.
Definition 5.1.3. If G1 D .V1;E1/ and G2 D .V2;E2/ are two graphs, then we
say that G1 is isomorphic to G2 i

0.142546543074
math.tan(0)
0.0
132
degrees (x) It converts angle x from
radians to degrees, where x
must be a numeric value.
math.degrees(3)
171.887338539
math.degrees(-3)
-171.887338539
math.degrees(0)
0.0
radians(x)
It converts angle x from
degrees to r

are shown in the box on the following page. Interestingly, well see that computer
scientists have found ways to turn some of these difficulties to their advantage.
4.1.1 Facts about Divisibility
The lemma below states some basic facts about divisibility t

! .0; 3/
The same approach works regardless of the jug capacities and even regardless
the amount were trying to produce! Simply repeat these two steps until the desired
amount of water is obtained:
1. Fill the smaller jug.
2. Pour all the water in the sma

could the Germans locate convoys better than the Allies could locate
U-boats or vice versa?
Germany lost.
But a critical reason behind Germanys loss was made public only in 1974:
Germanys
naval code, Enigma, had been broken by the Polish Cipher Bureau (se

BB@
0500
5060
0 6 0 3
0 0 3 0
1
CCA
(b)
Figure 5.9 Examples of adjacency matrices. (a) shows the adjacency matrix for
the graph in Figure 5.6(a) and (b) shows the adjacency matrix for the weighted
graph in Figure 5.8. In each case, we set v1 D a, v2 D b,

138 Chapter 5 Graph Theory
Proof. Well prove this by contradiction.
Assume, for the purposes of contradiction, that there is a stable matching. Then
there are two members of the love triangle that are matched. Since preferences in
the triangle are symmetr

other and who like each other better than their spouses, is called a rogue couple. In
the situation shown in Figure 5.13, Brad and Angelina would be a rogue couple.
Having a rogue couple is not a good thing, since it threatens the stability of the
marriag

warnings, Turing carried out chemistry experiments in his own home. Apparently,
her worst fear was realized: by working with potassium cyanide while
eating an apple, he poisoned himself.
However, Turing remained a puzzle to the very end. His mother was a

by government secrecy, societal taboo, and even his own deceptions.
At age 24, Turing wrote a paper entitled On Computable Numbers, with an
Application
to the Entscheidungsproblem. The crux of the paper was an elegant way
to model a computer in mathematic

empty 26
! .12; 0/
pour 21 into 26
! .0; 12/
fill 21
! .21; 12/
pour 21 into 26
! .7; 26/
empty 26
! .7; 0/
pour 21 into 26
! .0; 7/
fill 21
! .21; 7/
pour 21 into 26
! .2; 26/
empty 26
! .2; 0/
pour 21 into 26
! .0; 2/
fill 21
! .21; 2/
pour 21 into 26
!

_ Otherwise, we pour water from one jug to another until one is empty or the
other is full. By our assumption, the amount in each jug is a linear combination
of a and b before we begin pouring:
j1 D s1 _ a C t1 _ b
j2 D s2 _ a C t2 _ b
After pouring, one

woman has 6, for a percentage disparity of 233%. The ABC News study, aired
on Primetime Live in 2004, purported to be one of the most scientific ever done,
with only a 2.5% margin of error. It was called American Sex Survey: A peek
between the sheets. The

Informally, a graph is a bunch of dots and lines where the lines connect some pairs
of dots. An example is shown in Figure 5.1. The dots are called nodes (or vertices)
and the lines are called edges.
b
g
h
i
fd
ce
a
Figure 5.1 An example of a graph with 9

Lets consider what happens when the sender transmits a second message using
Turings code and the same key. This gives the Nazis two encrypted messages to
look at:
m_
1
D m1 _ k and m_
2
D m2 _ k
The greatest common divisor of the two encrypted messages, m

gcd.a; b/ j sa C tb (4.3)
for every s and t . In particular, gcd.a; b/ j m, which implies that gcd.a; b/ _ m.
Now, we show that m _ gcd.a; b/. We do this by showing that m j a. A
symmetric argument shows that m j b, which means that m is a common divisor

should learn at least a little number theory.
Unfortunately, Hollywood never lets go of a gimmick. Although there were no
water jug tests in Die Hard 4: Live Free or Die Hard, rumor has it that the jugs will
mcs-ftl 2010/9/8 0:40 page 85 #91
4.1. Divisibi

G2 D .V2;E2/ if V1 _ V2 and E1 _ E2.
For example, the empty graph on n nodes is a subgraph of Ln, Ln is a subgraph
of Cn, and Cn is a subgraph of Kn. Also, the graph G D .V;E/ where
V D fg; h; ig and E D f fh; ig g
is a subgraph of the graph in Figure 5.1

m, if w is crossed off ms list, then w has a suitor whom she prefers over m.
Lemma 5.2.13. P is an invariant for The Mating Ritual.
Proof. By induction on the number of days.
Base Case: In the beginning (that is, at the end of day 0), every woman is on ev

(which the Nazis may intercept), and k is the key.
Beforehand The sender and receiver agree on a secret key, which is a large prime
k.
Encryption The sender encrypts the message m by computing:
m_ D m _ k
Decryption The receiver decrypts m_ by computing:

_
1
1
2
_
1
1
3
_
1
1
5
_
D 300
_
1
2
_
2
3
_
4
5
_
D 80:
Corollary 4.7.5. Let n D pq where p and q are different primes. Then _.n/ D
.p 1/.q 1/.
Corollary 4.7.5 follows easily from Theorem 4.7.4, but since Corollary 4.7.5 is
important to RSA and we have

Xn
tD1
ai ta.k/
:
and so we must have P.kC1/
tj
ij
D a.kC1/
ij for all i; j 2 .1; n. Hence P.kC1/ is true
and the induction is complete. _
mcs-ftl 2010/9/8 0:40 page 151 #157
5.5. Connectivity 151
5.4.4 Shortest Paths
Although the connection between the p

math.floor(-45.17)
-46.0
math.floor(100.12)
100.0
math.floor(100.72)
100.0
fabs( x ) It returns the absolute
value of x, where x is a
numeric value.
math.fabs(-45.17)
45.17
math.fabs(100.12)
100.12
math.fabs(100.72)
100.72
exp( x ) It returns exponential