Professional Documents
Culture Documents
Recurrent Problems 2
Recurrent Problems 2
Chapter One
The Tower of Hanoi
Lines in the Plane
The Josephus Problem
Contents
2 Binary representation
2 Binary representation
Legend:
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem
Example, n = 10.
10
1
2
The elimination order is
2, 4, 6, 8, 10, 3, 7, 1, 9 .
9 3
So, we have J(10) = 5
8 4
7 5
6
The Josephus Problem – small numbers
Properties
J(1) = 1;
J(2n) = 2J(n) − 1, for n > 1;
J(2n + 1) = 2J(n) + 1, for n > 1.
3 Closed formula
Case n = 2m.
First trip eliminates all even numbers. Then
1 we change numbers and repeat:
10 2
9 3
Old number k 1 3 5 7 9
8 4
New number k’ 1 2 3 4 5
7 5 or
6
k = 2k 0 − 1
That correspondance beveen "old" and
"new numbers" givs us that:
J(2n) = 2J(n) − 1
.
The Josephus Problem – recurrent equation (1)
Case n = 2m.
First trip eliminates all even numbers. Then
1 we change numbers and repeat:
10 1 2
9 5 2 3
Old number k 1 3 5 7 9
8 4
New number k’ 1 2 3 4 5
7
4 3
5 or
6
k = 2k 0 − 1
That correspondance beveen "old" and
"new numbers" givs us that:
J(2n) = 2J(n) − 1
.
The Josephus Problem – recurrent equation (2)
Case n = 2m + 1.
First trip eliminates all even numbers. Then
1
we change numbers and repeat:
11 2
10 3
Old number k 1 3 5 7 9 11
9 4 New number k’ 0 1 2 3 4 5
8 5 or
7 6
k = 2k 0 + 1
That correspondence between "old" and
"new numbers" givs us that:
J(2n + 1) = 2J(n) + 1
.
The Josephus Problem – recurrent equation (2)
Case n = 2m + 1.
First trip eliminates all even numbers. Then
1
we change numbers and repeat:
11 0 2
5
10 13
Old number k 1 3 5 7 9 11
9 4 4 New number k’ 0 1 2 3 4 5
2
8
3
5 or
7 6
k = 2k 0 + 1
That correspondence between "old" and
"new numbers" givs us that:
J(2n + 1) = 2J(n) + 1
.
The Josephus Problem – application of recurrence
The equation
J(1) = 1;
J(2n) = 2J(n) − 1, for n > 1;
J(2n + 1) = 2J(n) + 1, for n > 1.
For example
J(86) = 2J(43) − 1 = 53
J(43) = 2J(22) + 1 = 27
J(22) = 2J(11) − 1 = 13
J(11) = 7
The Josephus Problem – closed formula
Teoreem
Q.E.D.
The Josephus Problem – closed formula (2)
2 Binary representation
Denote
n = (bm bm−1 . . . b1 b0 )2 ,
where bi ∈ {0, 1} and bm = 1.
n = bm 2m + bm−1 2m−1 + . . . b1 2 + b0
For example
Denote
n = (bm bm−1 . . . b1 b0 )2 ,
where bi ∈ {0, 1} and bm = 1.
n = bm 2m + bm−1 2m−1 + . . . b1 2 + b0
For example
Denote
n = (bm bm−1 . . . b1 b0 )2 ,
where bi ∈ {0, 1} and bm = 1.
n = bm 2m + bm−1 2m−1 + . . . b1 2 + b0
For example
Observations:
1 ` = (0bm−1 . . . b1 b0 )2
2 2` = (bm−1 . . . b1 b0 0)2
3 2m = (10 . . . 00)2 and 1 = (00 . . . 01)2
4 n = 2m + ` = (1bm−1 . . . b1 b0 )2
5 2` + 1 = (bm−1 . . . b1 b0 1)2
Corollary
Observations:
1 ` = (0bm−1 . . . b1 b0 )2
2 2` = (bm−1 . . . b1 b0 0)2
3 2m = (10 . . . 00)2 and 1 = (00 . . . 01)2
4 n = 2m + ` = (1bm−1 . . . b1 b0 )2
5 2` + 1 = (bm−1 . . . b1 b0 1)2
Corollary
Observations:
1 ` = (0bm−1 . . . b1 b0 )2
2 2` = (bm−1 . . . b1 b0 0)2
3 2m = (10 . . . 00)2 and 1 = (00 . . . 01)2
4 n = 2m + ` = (1bm−1 . . . b1 b0 )2
5 2` + 1 = (bm−1 . . . b1 b0 1)2
Corollary
Example
100 = 64 + 32 + 4
J(100) = J((1100100)2 ) = (1001001)2
J(100) = 64 + 8 + 1 = 73
Next section
2 Binary representation
Josephus function J : N −→ N
was defined using recurrences:
J(1) = 1;
J(2n) = 2J(n) − 1, for n > 1;
J(2n + 1) = 2J(n) + 1, for n > 1.
J =f , for α = 1, β = −1, γ = 1
Generalization
Josephus function J : N −→ N
was defined using recurrences:
J(1) = 1;
J(2n) = 2J(n) − 1, for n > 1;
J(2n + 1) = 2J(n) + 1, for n > 1.
J =f , for α = 1, β = −1, γ = 1
Generalization
Josephus function J : N −→ N
was defined using recurrences:
J(1) = 1;
J(2n) = 2J(n) − 1, for n > 1;
J(2n + 1) = 2J(n) + 1, for n > 1.
J =f , for α = 1, β = −1, γ = 1
Repertoire method
n f (n) Calculation
1 α f (1) = α
2 2α + β f (2) = 2f (1) + β
3 2α + γ f (3) = 2f (1) + γ
4 4α + 3β f (4) = 2f (2) + β
5 4α + 2β + γ f (5) = 2f (2) + γ
6 4α + β + 2γ f (6) = 2f (3) + β
7 4α + 3γ f (7) = 2f (3) + γ
8 8α + 7β f (8) = 2f (4) + β
9 8α + 6β + γ f (9) = 2f (4) + γ
Repertoire method for generalized f-n f : STEP 2
Observations:
For n=1, 2, . . . , 9, taking n = 2k + `
Coefficient of α is 2k ;
Coefficient of β is 2k − 1 − `;
Coefficient of γ is `;
Repertoire method for generalized f-n f : STEP 3
Proposition:
f (1) = α;
f (2n) = 2f (n) + β , for n > 1;
f (2n + 1) = 2f (n) + γ, for n > 1,
where
A(n) = 2k ;
B(n) = 2k − 1 − `;
C (n) = `.
Proof of the proposition (1)
A(1) = 20 = 1
Step: Let assume that A(2k−1 + `) = 2k−1 , where 0 6 ` < 2k−1 . Two cases:
If n is even, then ` is even as well and
or
1=α ; 1 = 2+β ; 1 = 2 + γ.
The solution is α = 1 and β = γ = −1.
Proof of the proposition (3)
or
1=α ; 2n = 2n + β ; 2n + 1 = 2n + γ.
The solution is α = 1, β = 0 and γ = 1.
Proof of the proposition (4)
that gives
C (n) = `
From Lemma 2 follows
2 Binary representation
Definition
f (1) = α
f (2n + j) = 2f (n) + βj , for j = 0, 1 and n > 0.
Definition
f (1) = α
f (2n + j) = 2f (n) + βj , for j = 0, 1 and n > 0.
2n = (bm bm−1 . . . b1 b0 )2
or
2n = bm 2m + bm−1 2m−1 + . . . + b1 2 + b0
where bi ∈ {0, 1}, b0 = 0 and bm = 1.
Hence
n = bm 2m−1 + bm−1 2m−2 + . . . + b2 2 + b1
or
n = (bm bm−1 . . . b1 )2
Binary representation of generalized GJ-function (3)
2n + 1 = (bm bm−1 . . . b1 b0 )2
or
2n + 1 = bm 2m + bm−1 2m−1 + . . . + b1 2 + b0
where bi ∈ {0, 1}, b0 = 1 and bm = 1.
We get
2n + 1 = bm 2m + bm−1 2m−1 + . . . + b1 2 + 1
2n = bm 2m + bm−1 2m−1 + . . . + b1 2
n = bm 2m−1 + bm−1 2m−2 + . . . + b2 2 + b1
or
n = (bm bm−1 . . . b1 )2
Binary representation of generalized GJ-function (3)
2n + 1 = (bm bm−1 . . . b1 b0 )2
or
2n + 1 = bm 2m + bm−1 2m−1 + . . . + b1 2 + b0
where bi ∈ {0, 1}, b0 = 1 and bm = 1.
We get
2n + 1 = bm 2m + bm−1 2m−1 + . . . + b1 2 + 1
2n = bm 2m + bm−1 2m−1 + . . . + b1 2
n = bm 2m−1 + bm−1 2m−2 + . . . + b2 2 + b1
Same results for cases A and B indicates that we don’t need to consider even
and odd cases separately.
Binary representation of generalized GJ-function (4)
Let’s evaluate:
where
β1 , if bj = 1
βbj =
β0 if bj = 0
Let’s evaluate:
where
β1 , if bj = 1
βbj =
β0 if bj = 0
f (1) = 1
f (2n) = 2f (n) − 1
f (2n + 1) = 2f (n) + 1
Compute