the towers of hanoi - math.cmu.edu

17
The Towers of Hanoi In the great temple of Brahma in Benares, India, on a brass plate under the dome that marks the center of the world, there are 64 disks of pure gold that the priests carry one at a time be- tween three diamond needles according to Brahma’s immutable law: No disk may be placed on a smaller disk. In the beginning of the world all 64 disks formed the Tower of Brahma on one needle. Now, however, the process of transfer of the tower from one needle to another is in mid course. When the last disk is finally in place, once again forming the Tower of Brahma but on a different needle, then will come the end of the world and all will turn to dust. Question? Suppose n disks are to be moved. How many moves are necessary? 1

Upload: others

Post on 26-Oct-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Towers of Hanoi - math.cmu.edu

The Towers of Hanoi

In the great temple of Brahma in Benares, India, on a brass

plate under the dome that marks the center of the world, there

are 64 disks of pure gold that the priests carry one at a time be-

tween three diamond needles according to Brahma’s immutable

law: No disk may be placed on a smaller disk. In the beginning

of the world all 64 disks formed the Tower of Brahma on one

needle. Now, however, the process of transfer of the tower from

one needle to another is in mid course. When the last disk is

finally in place, once again forming the Tower of Brahma but

on a different needle, then will come the end of the world and

all will turn to dust.

Question? Suppose n disks are to be moved. How many

moves are necessary?

1

Page 2: The Towers of Hanoi - math.cmu.edu

A bit of logic

To prove a proposition like “If P , then Q”, abbreviated “P ⇒Q” there are two options: prove the proposition directly, or

prove the logically equivalent contrapositive of the proposi-

tion ¬Q⇒ ¬P .

In the second method, called proof by contradiction, one

assumes that Q is false and shows that that assumption leads

to a contradiction of P .

Proposition. The square root of 2 is irrational.

The Pigeonhole Principle: If k + 1 or more pigeons are

placed into k pigeonholes, then there must be one pigeonhole

containing two or more pigeons.

Finally, we will need a bit of number theory:

Proposition. If two numbers have the same remainder when

divided by c, then their difference is divisible by c.

Problem. A group of 30 students wrote a dictation. John

Bull made 13 errors, and each of the rest made fewer than 13

errors. Prove that at least 3 students made the same number

of errors.

2

Page 3: The Towers of Hanoi - math.cmu.edu

Problem. Prove that, given any 12 distinct natural numbers,

we can choose two of them such that their difference is divisible

by 11.

Problem. Given a set S of 10 distinct numbers between 1

and 100, inclusive, there exist two distinct, disjoint subsets A

and B of S whose elements sum to the same number.

3

Page 4: The Towers of Hanoi - math.cmu.edu

Modular arithmetic

Modular arithmetic was developed by

Carl Friedrich Gauss and published

in his Disquisitiones Arithmeticae in

1801 when he was 21. It offers a con-

venient approach to questions of divis-

ibility.

Carl Friedrich Gauss

(1777 – 1855)

Definition: Let m be a fixed integer. For integers a and b we

say that a is congruent to b modulo m and write

a ≡ b (modm)

whenever m|(a− b). If m 6 |(a− b), we write a 6≡ b (modm).

Example. Clocks and modular arithmetic.

4

Page 5: The Towers of Hanoi - math.cmu.edu

Proposition. Let m be a fixed integer. Let a, b, and c be

integers. Then

(i) a ≡ a (modm).

(ii) If a ≡ b (modm), then b ≡ a (modm).

(iii) If a ≡ b (modm) and b ≡ c (modm), then a ≡ c (modm).

The properties enumerated in the Proposition are called, re-

flexive, symmetric, and transitive, respectively.

Proposition. If a ≡ a′, (modm) and b ≡ b′ (modm), then

(i) a + b ≡ a′ + b′ (modm)

(ii) a− b ≡ a′ − b′ (modm)

(iii) a · b ≡ a′ · b′ (modm)

Question? So addition, subtraction, and multiplication be-

have nicely! How about division? The following example illus-

trates the difficulty with division.

5

Page 6: The Towers of Hanoi - math.cmu.edu

Example. Note that 28 ≡ 10 (mod 6). Also, 2 divides both

28 and 10 so we might expect to divide by 2 and have 14 be

equivalent to 5 modulo 6.

But 14 6≡ 5 (mod 6).

What happened? Why can’t we “cancel” the 2 in this case?

The answer requires a couple of definitions. . .

The greatest common divisor of two integers a and b

is the largest integer d such that d|a and d|b. The greatest

common divisor of two integers is denoted by gcd(a, b).

Integers a and b are said to be relatively prime if gcd(a, b) =

1.

This allows an answer to when we can “cancel” in modular

arithmetic. . .

Proposition. If ac ≡ bc (modm) and gcd(c,m) = 1, then

a ≡ b (modm).

So we should not have expected 14 to be equivalent to 5 modulo

6 since gcd(2, 6) = 2.

Example. 20 · 2 ≡ 9 · 2 (mod 11) and therefore 20 ≡ 9

(mod 11) since gcd(11, 2) = 1.

So we can cancel a constant in a modular equivalence only when

the constant and the modulus are relatively prime.

6

Page 7: The Towers of Hanoi - math.cmu.edu

Proposition. a ≡ b (modm) if and only if a and b have

the same remainder when divided by m.

Proposition. An integer n is divisible by 9 if and only if the

sum of its digits is divisible by 9.

Example. Determine all solutions to 8x + 12y = b where x

and y are positive integers and 75 < b < 80.

Example. Determine the remainder when 237 is divided by7.

7

Page 8: The Towers of Hanoi - math.cmu.edu

Example. Divisibility by 7

To test an integer for divisibility by 7, subtract twice the last

digit from the other digits repeatedly until a single digit number

is obtained. If the number obtained is 0 or 7 then the integer is

divisible by 7.

Proposition. The test for divisibility by 7 described above is

correct.

Proof. Let m = an10n + an−110n−1 + · · · + a110 + a0 be the

number to test. We need to show m ≡ 0 (mod 7) and

an10n−1 + an−110n−2 + · · · + a1 − 2a0 ≡ 0 (mod 7)

are equivalent. Multiplying the second equation by 10 yields

an10n + an−110n−1 + · · · + a110− 20a0 ≡ 0 (mod 7),

and adding 21a0, which is zero modulo 7, yields

an10n + an−110n−1 + · · · + a110 + 21a0 − 20a0 ≡ 0 (mod 7).

But the left side is just m so

m = an10n + an−110n−1 + · · · + a110 + a0 ≡ 0 (mod 7)

The equivalence established here for one step in the processis maintained throughout the steps needed and thus the testworks. �

Proof suggested by Nathan Vallapureddy, PGSS 2016.

8

Page 9: The Towers of Hanoi - math.cmu.edu

For example, consider 5,355, 22,968, and 103,224:

535 2,296 10,322

-10 -16 -8

525 2,280 10,314

52 228 1,031

-10 -0 -8

42 228 1,023

4 22 102

-4 -16 -6

0 6 96

9

-12

-3

Since

5, 355 = 32·5·7·17, 22, 968 = 23·32·11·29, and 103, 224 = 2·3·4·11·17·23,

the test is three for three.

9

Page 10: The Towers of Hanoi - math.cmu.edu

Introduction to Graph Theory

A graph is a set of vertices and a set of edges such that each

edge is associated with an (unordered) pair of vertices.

A graph is simple if it contains at most one edge between any

pair of vertices and no loops, i.e., no edges that start and end

on the same vertex.

A path is a sequence of vertices such that consecutive vertices

are adjacent via an edge and no edge is used twice.

A graph is connected if there is a path joining each pair of

distinct vertices.

A path is Eulerian if it uses every edge in the graph exactly

once.

A circuit is a path that returns to its starting point.

The degree of a vertex is the number of edges incident on the

vertex.

10

Page 11: The Towers of Hanoi - math.cmu.edu

The Konigsberg Bridge Problem

The river Pregel flows through Konigsberg, and in Euler’s day

there were seven bridges connecting the North and South shores

and the two islands in the river. A popular puzzle in the town

was whether or not it was possible to walk in such a way as to

cross each bridge exactly once.

The Bridges of Konigsberg

Leonhard Euler

(1707 – 1783)

Euler’s Theorem. A graph has an Euler path if and only if

. . .

11

Page 12: The Towers of Hanoi - math.cmu.edu

A graph is planar if it can be drawn in the plane without its

edges crossing.

A graph is complete if every pair of distinct vertices is con-

nected by an edge. The complete graph with n vertices is

denoted by Kn.

Example. K4 is planar while K5 is not.

Utilities Puzzle

Connect all of the circles with all of the squares without arcs

crossing.

Unsolved problem. The question of the the minimum num-

ber of edge crossings required to draw Kn is unsolved for most

cases where n ≥ 13.

A graph is bipartite if it includes two disjoint sets of vertices

such that all edges connect a vertex in one of the sets with a

vertex in the other.

12

Page 13: The Towers of Hanoi - math.cmu.edu

Kn,m denotes the bipartite graph that includes all possible

edges joining a set of n vertices with a set of m vertices.

A graph H is a subgraph of a graph G if every vertex and

every edge of H is also a vertex or an edge of G.

Kuratowski’s Theorem. A graph is planar if and only if it

does not contain K5 or K3,3 as a subgraph.

Two graphs are isomorphic if (ignoring their vertex labels)

one can be re-drawn to look like the other.

Thus, unlike a one-to-one function that establishes an isomor-

phism for sets, the one-to-one correspondence between the ver-

tices of isomorphic graphs must be accompanied by a one-to-one

correspondence between their edges in such a way that the in-

cidence relationships are preserved.

Question? So who cares if a graph is planar, or at least, close

to planar?

13

Page 14: The Towers of Hanoi - math.cmu.edu

In addition to the number of edges, e, and the number of ver-

tices, v, for a planar graph there is also the number f of faces.

When a planar graph is drawn without edge intersections, the

plane is divided into contiguous regions called faces. There is

also an unbounded face consisting of the region lying entirely

outside the graph.

Theorem. (Euler’s Formula) In a connected, planar

graph

e− v + 2 = f,

i.e., the number of edges minus the number of ver-

tices plus two equals the number of faces.

Proof. Use induction on the number of edges . . .

Theorem 6.1.7. In any graph G, the sum of the

degrees of the vertices is twice the number of edges.

Corollary 6.1.8. In any graph G, the number of

nodes with odd degree is even.

14

Page 15: The Towers of Hanoi - math.cmu.edu

Question? Can there exist a hydrocarbon with five

carbon atoms and three hydrogen atoms?

Two hydrocarbons

• • •

H

H

H HC

.......

.......

.......

.......

.......

.......

.......

.......

.......

.......

.......

.......

.......

.......

.......

.

..........................................................................................................

....................................................................................................................................................................................................................

METHANE

CH4

• •

• •

• •

C

H H

H H

C

..........................................................................................................

..........................................................................................................

..........................................................................................................

..........................................................................................................

ETHYLENE

C2H4

..........................

............................................................................................................................................

...............................................................................................................................................

.......................

What is the degree of each hydrogen atom?

What is the degree of each carbon atom?

Question? How many edges are there in Kn? How

about Kn,m?

Proposition. C(n + m, 2) = C(n, 2) + C(m, 2) + nm.

15

Page 16: The Towers of Hanoi - math.cmu.edu

Question? (The Party Problem.) Six guests are

invited to a party, and each pair of guests are ei-

ther friends or strangers. Is it true that among the

guests there are always three who are all friends or

three who are all strangers?

Example. Provide an example of a graph for a party

with five guests without a set of three who are all

friends or three who are all strangers.

Ramsey’s Theorem. For any pair of positive inte-

gers (r, s), there exists a least positive integer R(r, s)

such that for any complete graph on R(r, s) vertices,

whose edges are coloured red or blue, there exists

either a complete subgraph on r vertices which is

entirely blue, or a complete subgraph on s vertices

which is entirely red.

Unsolved problems. The Ramsey number R(r, s) is

known for small values of r and s, and there are

estimates for others, for example 40 ≤ R(10, 3) ≤ 42,

or 205 ≤ R(7, 7) ≤ 540. And 43 ≤ R(5, 5) ≤ 49. But the

search for exact values is full of open problems.

16

Page 17: The Towers of Hanoi - math.cmu.edu

Just how hard are these problems? Here is a quote

from Paul Erdos:

“Imagine an alien force, vastly more powerful than

us landing on Earth and demanding the value of

R(5, 5) or they will destroy our planet. In that case,

we should marshal all our computers and all our

mathematicians and attempt to find the value. But

suppose, instead, that they asked for R(6, 6), we

should attempt to destroy the aliens.”

17