Tower of Hanoi
Fibonacci Numbers
Motivating Examples
On Recurrence Relation
Miliyon T.
April 10, 2019
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Outline
1 Tower of Hanoi
2 Fibonacci Numbers
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi Statement
Tower of Hanoi
We are given a tower of eight disks, initially stacked in decreasing
size on one of three pegs:
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi Statement
Tower of Hanoi
We are given a tower of eight disks, initially stacked in decreasing
size on one of three pegs:
The objective is to transfer the entire tower to one of the other
pegs,
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi Statement
Tower of Hanoi
We are given a tower of eight disks, initially stacked in decreasing
size on one of three pegs:
The objective is to transfer the entire tower to one of the other
pegs, moving only one disk at a time and
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi Statement
Tower of Hanoi
We are given a tower of eight disks, initially stacked in decreasing
size on one of three pegs:
The objective is to transfer the entire tower to one of the other
pegs, moving only one disk at a time and never moving a larger
one onto a smaller.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi Statement
Tower of Hanoi
We are given a tower of eight disks, initially stacked in decreasing
size on one of three pegs:
The objective is to transfer the entire tower to one of the other
pegs, moving only one disk at a time and never moving a larger
one onto a smaller.
Question: What is the minimum number of moves required to
solve a Tower of Hanoi puzzle?
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 1 Disc
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 1 Disc
Moved disc from pole 1 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 1 Disc
OK
1
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 2 Discs
1
2
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 2 Discs
2 1
Moved disc from pole 1 to pole 2.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 2 Discs
1 2
Moved disc from pole 1 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 2 Discs
1
2
Moved disc from pole 2 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 2 Discs
OK
1
2
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
1
2
3
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
2
3 1
Moved disc from pole 1 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
3 2 1
Moved disc from pole 1 to pole 2.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
1
3 2
Moved disc from pole 3 to pole 2.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
1
2 3
Moved disc from pole 1 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
1 2 3
Moved disc from pole 2 to pole 1.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
2
1 3
Moved disc from pole 2 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
1
2
3
Moved disc from pole 1 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 3 Discs
OK 1
2
3
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1
2
3
4
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
2
3
4 1
Moved disc from pole 1 to pole 2.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
3
4 1 2
Moved disc from pole 1 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
3 1
4 2
Moved disc from pole 2 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1
4 3 2
Moved disc from pole 1 to pole 2.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1
4 3 2
Moved disc from pole 3 to pole 1.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1 2
4 3
Moved disc from pole 3 to pole 2.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1
2
4 3
Moved disc from pole 1 to pole 2.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1
2
3 4
Moved disc from pole 1 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
2 1
3 4
Moved disc from pole 2 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1
2 3 4
Moved disc from pole 2 to pole 1.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1
2 3 4
Moved disc from pole 3 to pole 1.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1 3
2 4
Moved disc from pole 2 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
3
2 1 4
Moved disc from pole 1 to pole 2.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
2
3
1 4
Moved disc from pole 1 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
1
2
3
4
Moved disc from pole 2 to pole 3.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 4 Discs
OK 1
2
3
4
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Tower of Hanoi – 5 Disc
1
2
3
?
4
5
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
At this point if Hn is the minimum number of moves that will
transfer n disks from one peg to another, we notice that
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
At this point if Hn is the minimum number of moves that will
transfer n disks from one peg to another, we notice that
Hn = 2Hn−1 + 1
This equation with initial condition H1 = 1, is a recurrence relation
for the Tower of Hanoi.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Fibonacci Sequence
Fibonacci Sequence
“[A]ssuming that:
a newly born pair of rabbits, one male, one female, are put in
a field;
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Fibonacci Sequence
Fibonacci Sequence
“[A]ssuming that:
a newly born pair of rabbits, one male, one female, are put in
a field;
rabbits are able to mate at the age of one month so that at
the end of its second month a female can produce another
pair of rabbits;
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Fibonacci Sequence
Fibonacci Sequence
“[A]ssuming that:
a newly born pair of rabbits, one male, one female, are put in
a field;
rabbits are able to mate at the age of one month so that at
the end of its second month a female can produce another
pair of rabbits;
rabbits never die and a mating pair always produces one new
pair (one male, one female) every month from the second
month on.”
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Fibonacci Sequence
Fibonacci Sequence
“[A]ssuming that:
a newly born pair of rabbits, one male, one female, are put in
a field;
rabbits are able to mate at the age of one month so that at
the end of its second month a female can produce another
pair of rabbits;
rabbits never die and a mating pair always produces one new
pair (one male, one female) every month from the second
month on.”
“The puzzle that Fibonacci posed was: how many pairs will there
be in one year?”
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Let ♠ denote a newly born rabbit pair, and ♥ denote a mature
rabbit pair.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Let ♠ denote a newly born rabbit pair, and ♥ denote a mature
rabbit pair.
Month Rabbits # Pairs
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Let ♠ denote a newly born rabbit pair, and ♥ denote a mature
rabbit pair.
Month Rabbits # Pairs
1 ♠ 1
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Let ♠ denote a newly born rabbit pair, and ♥ denote a mature
rabbit pair.
Month Rabbits # Pairs
1 ♠ 1
2 ♥ 1
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Let ♠ denote a newly born rabbit pair, and ♥ denote a mature
rabbit pair.
Month Rabbits # Pairs
1 ♠ 1
2 ♥ 1
3 ♥♠ 2
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Let ♠ denote a newly born rabbit pair, and ♥ denote a mature
rabbit pair.
Month Rabbits # Pairs
1 ♠ 1
2 ♥ 1
3 ♥♠ 2
4 ♥♥♠ 3
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
Let ♠ denote a newly born rabbit pair, and ♥ denote a mature
rabbit pair.
Month Rabbits # Pairs
1 ♠ 1
2 ♥ 1
3 ♥♠ 2
4 ♥♥♠ 3
5 ♥♥♥♠♠ 5
6 ♥♥♥♥♥♠♠♠ 8
7 ♥♥♥♥♥♥♥♥♠♠♠♠♠ 13
Table:
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
How many rabbit pairs do we have at the beginning of the 8th
month?
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
How many rabbit pairs do we have at the beginning of the 8th
month?
Clearly, all 13 rabbit pairs we have in the 7th month remain
there and are all mature.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
How many rabbit pairs do we have at the beginning of the 8th
month?
Clearly, all 13 rabbit pairs we have in the 7th month remain
there and are all mature. So, the question is; how many newly
born rabbit pairs that we have?
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
How many rabbit pairs do we have at the beginning of the 8th
month?
Clearly, all 13 rabbit pairs we have in the 7th month remain
there and are all mature. So, the question is; how many newly
born rabbit pairs that we have?
The number of newly born rabbit pairs equals the number of
mature rabbit pairs we have.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
How many rabbit pairs do we have at the beginning of the 8th
month?
Clearly, all 13 rabbit pairs we have in the 7th month remain
there and are all mature. So, the question is; how many newly
born rabbit pairs that we have?
The number of newly born rabbit pairs equals the number of
mature rabbit pairs we have. This is also equal to the number
of rabbit pairs that we have in the 6th month, which is 8.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
How many rabbit pairs do we have at the beginning of the 8th
month?
Clearly, all 13 rabbit pairs we have in the 7th month remain
there and are all mature. So, the question is; how many newly
born rabbit pairs that we have?
The number of newly born rabbit pairs equals the number of
mature rabbit pairs we have. This is also equal to the number
of rabbit pairs that we have in the 6th month, which is 8.
Thus, we will have 13 + 8 = 21 rabbit pairs at the beginning of the
8th month.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
If we write down the sequence, we get the Fibonacci sequence:
1, 1, 2, 3, 5, 8, 13, 21, . . .
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
If we write down the sequence, we get the Fibonacci sequence:
1, 1, 2, 3, 5, 8, 13, 21, . . .
Again, what’s the next number in this sequence?
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
If we write down the sequence, we get the Fibonacci sequence:
1, 1, 2, 3, 5, 8, 13, 21, . . .
Again, what’s the next number in this sequence?
To be precise, let Fn be the nth number in the Fibonacci sequence.
(That is, F1 = 1, F2 = 1, F3 = 2, F4 = 3 and so on.)
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
If we write down the sequence, we get the Fibonacci sequence:
1, 1, 2, 3, 5, 8, 13, 21, . . .
Again, what’s the next number in this sequence?
To be precise, let Fn be the nth number in the Fibonacci sequence.
(That is, F1 = 1, F2 = 1, F3 = 2, F4 = 3 and so on.) We can define
the (n + 1)th number as
Fn+1 = Fn + Fn−1 , for n ≥ 2 with F1 = 1, F2 = 1.
Miliyon T. Motivating Examples
Tower of Hanoi
Fibonacci Numbers
If we write down the sequence, we get the Fibonacci sequence:
1, 1, 2, 3, 5, 8, 13, 21, . . .
Again, what’s the next number in this sequence?
To be precise, let Fn be the nth number in the Fibonacci sequence.
(That is, F1 = 1, F2 = 1, F3 = 2, F4 = 3 and so on.) We can define
the (n + 1)th number as
Fn+1 = Fn + Fn−1 , for n ≥ 2 with F1 = 1, F2 = 1.
Miliyon T. Motivating Examples