SlideShare a Scribd company logo
1 of 9
Download to read offline
Recurrent Problems
In recurrence, solution to a problem depends on the solution to smaller instance of the
same problem.
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 large one onto a smaller.
Fig: Tower of Hanoi with 8 disks
Consider small cases:
0 0T  , [0 disk requires 0 move]
2 3T 
3 7T  , [Transferring small 2 disks to middle peg requires 3 moves. Then moving the
largest disk from left peg to right peg requires only 1 move. Finally, moving 2 smaller
disks from middle peg to right peg requires another 3 moves. Thus, total 3+1+3=7 moves
require for moving 3 disks from one peg to another]
Similarly, for n disks to transfer from one peg to another we require:
0 0T 
12 1n nT T   , for n > 0
We can find out the closed form of any recurrence to get quick result from the problem.
12 1n nT T  
= 22(2 1) 1nT   
= 2
22 2 1nT   
= 2
32 (2 1) 2 1nT    
= 3 2
32 2 2 1nT    

= ( 1) ( 2) 2
2 2 2 2 2 1n n n
n nT  
      
= ( 1) ( 2) 2 1 0
02 2 2 2 2 2n n n
T  
     
T1 1, [1 disk requires only 1 move]
Tn  Tn1 1Tn1  2Tn1 1
Thus, the recurrence for Tower of Hanoi stands
Page 1 of 2
[Top disk from L to M; Bottom Disk from L to R; Finally, Top disk from M to R (see the Note below!)]
(These Two are
Constraints)
0 1 2 ( 2) ( 1)
2 2 2 2 2n n
nT  
     
=
2 1
2 1
n


[
1
0 1 2
1
n
n a
a a a a
a

    

 ]
= 2 1n

2 1n
nT   is called the closed form solution of the “Tower of Hanoi” problem.
Mathematical induction is a general way to prove any closed form solution. It has three
parts.
 Basis – prove the formula for smallest possible value.
 Hypothesis – Consider that, the formula is true for first n values.
 Induction – Try to prove the formula for (n+1)-th value.
For example, we are going prove the closed from of Tower of Hanoi solution.
Basis: 0
0 2 1 1 1 0T     
Hypothesis: Let, 2 1n
nT  
Induction: 1 1
1 2 1 2(2 1) 1 2 2 1 2 1n n n
n nT T  
           (Proved)
Try to prove
1
0 1 2
1
n
n a
a a a a
a

    

 using Mathematical induction method.
☺Good Luck☺
Page 2 of 2
*** Also, Solve DOUBLE TOH and TRIPLE TOH ***
(OK, because We know T0 is 0)
(or, first n-1 values)
(or, n-th value, if hypothsis true for n-1 values)
Excluded
-1
Recurrent Problems
Lines in the Plane: We have to find out how many slices of pizza can a person obtain
by making n straight cuts with a knife. Academically, what is the maximum number of
regions, nL defined by n lines in the plane? We can start by looking at small cases.
0 1L  1 2L  2 4L  3 4 3 7L   
If there exists 1n  lines in the plane, then n-th line have to cut previous 1n  lines to
produce maximum number of new region in the plane. The 1n  intersection points
create n new region in the plane. Thus, the recurrence for line in the plane therefore
0 1L 
1n nL L n  , for 0n 
We can find out the closed form of the recurrence through unfolding it to the end.
1n nL L n 
= 2 ( 1)nL n n   
= 3 ( 2) ( 1)nL n n n     

= ( 1) ( 2) ( 1)n nL n n n n n         
= 0 1 2 3 ( 2) ( 1)L n n n        
= 1nS  , where 1 2 3 ( 2) ( 1)nS n n n        
nS is called the triangular number because it is number of bowling pins in an n-row
triangular array. For example the usual four-row array has 4 10S  pins.
n 01 02 03 04 05 06 07 08 09 10
nS 01 03 06 10 15 21 28 36 45 55
We can evaluate nS using the following trick:
nS = 1 + 2 + 3 +  +( 2)n  +( 1)n  + n
+ nS = n +( 1)n  +( 2)n  +  + 3 + 2 + 1
2 nS =( 1)n  +( 1)n  + ( 1)n  +  +( 1)n  +( 1)n  +( 1)n 
( 1)
2
n
n n
S

 , for 0n 
Now, we have our closed form for lines in the plane problem.
( 1)
1
2
n
n n
L

  , for 0n 
1
2
1
1
2
3
4
1a
2
3a
4a
4b
3b1b
But, if the newly added line goes thru any of the previous intersection
points, then there will be less than "n new regions". For example:
1a
1b
2
4
3a
3b
(Also, if the new line is parallel to any previous line
then, we will get less regions. Check it yourself!!!)
6 in stead of
7 regions
L2 = L1 + 2L1 = Lo + 1 L3 = L2 + 3
Suppose instead of straight lines we use bent lines, each containing one “zig”. We have to
find out the maximum number of regions, nZ created by n such bent lines in the plane.
Fig: Bent lines in the plane
From small cases, we realize that a bent line is like two straight lines except that region
merge when the “two” lines don’t extent past their intersection point. Region 2, 3, 4
which would be distinct with two lines, become single region when there is a bent line,
we lose two region. Thus
2 2n nZ L n 
=
2 (2 1)
1 2
2
n n
n

 
= 2
2 1 2n n n  
= 2
2 1n n  , for 0n 
Comparing closed forms of straight and bent lines in the plane, we find that for large n,
2
2
1
2
2
n
n
L n
Z n


So, we get about four times as many regions with bent lines as with straight lines.
☺Good Luck☺
1
2
3
4
Zn = Maximum no. of regions obtained from n intersecting Zig shapes
in the plane
Also Find,
ZZn = Maximum no. of regions obtained from n intersecting ZigZag shapes
Wn = Maximum no. of regions obtained from n intersecting W shapes
Recurrent Problems
Josephus Problem: We start with n people numbered 1 to n around a circle and we
eliminate every second remaining person until only one survives. For example, here is the
starting configuration for n = 10.
The elimination order is 2 4 6 8 10 3 7 1 9        , so 5th
person survives.
The problem is to determine the survivor’s number, J(n). In this example J(10) = 5.
Consider, we have 2n people, then after 1st
round of elimination, we are left with n
people and 3rd
person will be the next person waiting for elimination. This is just like
starting with n people, except that every person’s number has been doubled and
decreased by 1. Similarly, if we start with 2 1n  people, then after 1st
round of
elimination number 1 will be eliminated. Then, we almost have the same situation with n
people like previous one, but this time their numbers are doubled and increased by 1.
Fig: Start with 2n people Fig: Start with 2 1n  people
(2 ) 2 ( ) 1J n J n  , for 1n  (2 1) 2 ( ) 1J n J n   , for 1n 
Combining these equations with (1) 1J  gives us a recurrence that defines J in all cases:
(1) 1J 
(2 ) 2 ( ) 1J n J n  , for 1n  (1)
(2 1) 2 ( ) 1J n J n   , for 1n 
Our recurrence makes it possible to build a table of small values which can helps us to
guess the closed form of Josephus problem.
( )J n is always 1 at the beginning of a group and it increases by 2 within a group. So, if
we write n in the form 2m
n l  , where 2m
is the largest power of 2 not exceeding n
where 2m
l n  satisfies 1
0 2 2 2m m m
l 
    , the solution to our recurrence would be
(2 ) 2 1m
J l l   , for 0m  and 0 2m
l 
1
2
3
4
5
6
7
8
9
10
1
3
5
7

2 3n 
2 1n 
3
5
7
9

2 1n 
2 1n 
n 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
J(n) 01 01 03 01 03 05 07 01 03 05 07 09 11 13 15 01
Find J(100) using thess recurrences:
J(100) = 2 J(50) -1
= 4 J(25) -2 -1 = 8J(12) + 4 - 2 -1
=16 J(6) -8 +4 -2 -1
= 32 J(3) - 16 -8 + 4 -2 -1
= 64 J(1) + 32 -16 -8 +4 -2 -1 = 64 + 32 -16-8+4-2-1 = 73 (ANS)
J(n) =
Write the
Recurrence
for Josephus
Problem
Establish the
logic for
these
Recurrences
To illustrate the solution let’s compute J(100).
6
(100) (2 36) 2 36 1 73J J     
Try to prove, (2 ) 1m
J 
Every solution to a problem can be generalized so that it applies to a wider class of
problems. Power of 2 played an important role in our recurrence solution. Thus it’s
natural to look at the radix 2 representation of n and J(n).
1 2 2 1 0 2( )m m mn b b b b bb   i.e. 1 2 2
1 2 2 1 02 2 2 2 2m m m
m m mn b b b b b b 
       
where, each bit ib is either 0 or 1 and the leading bit mb is 1. Recalling that 2m
n l  ,
we have, successively,
1 2 2 1 0 2(1 )m mn b b b bb  
1 2 2 1 0 2(0 )m ml b b b b b  
1 2 2 1 0 22 ( 0)m ml b b b bb  
1 2 2 1 0 22 1 ( 1)m ml b b b b b   
1 2 2 1 0 2( ) ( )m m mJ n b b b bb b  
We have proved that, 1 2 2 1 0 2 1 2 2 1 0 2( ) (( ) ) ( )m m m m m mJ n J b b b b bb b b b bb b     
For example, 2 2(100) ((1100100) ) (1001001) 64 8 1 73J J     
We can find out special cases solution of Josephus problem if required. For example, we
going to find when ( )
2
n
J n  is true.
( )
2
n
J n 
2
2 1
2
m
l
l

 
1
(2 2)
3
m
l  
For all m, if
1
(2 2)
3
m
l   is an integer, then solution exists. We can verify this equation
m ( ) 2 1 / 2J n l n  
1 0 002 01
3 2 010 05
5 10 042 21
7 42 170 85
Now, we are going to find out the closed form of more general recurrence of Josephus
problem introducing constants ,  and .
(1)f 
(2 ) 2 ( )f n f n   , for 1n  (2)
(2 1) 2 ( )f n f n    , for 1n 
n  2^m  ll=1/3*
(2^m-2)
Binary Property of the Josephus Problem:
l = 1/5 (2^m-3)
Q: Find the minimum three values of n for which J(n) = n/3
Q: Find threee values of n for which J(n) = n
Question: Find J(100)by
using the Binary
Property of the
Josephus Problem
l must be integer
see the file : "Josephus Add On.docx" for such problems
Q: Derive the Binary Property of the Josephus problem
This is called
General
Recurrence of
the Josephus
Problem
LHS = J(2^m) = 2 J(2^m-1) - 1 = 4 J(2^m-2) - 2 -1 = 8 J(2^m-3) - 4 - 2 -1 = ... ... ...
= 2^m J(1) - 2^m-1 - 2^m-2 - ... -1 = 2^m - (2^m - 1) = 1
We can construct the following general table for small values of n.
n f(n)
1 
2 2 + 
3 2 + 
4 4 +3 
5 4 +2  + 
6 4 +  +2
7 4 +3
8 8 +7 
9 8 +6  + 
Thus, we can express f(n) as following form
( ) ( ) ( ) ( )f n A n B n C n     (3)
where A(n), B(n) and C(n) are coefficients of ,  and  respectively.
Considering the special case 1, 0     , we get ( ) ( )f n A n and recurrence
becomes
(1) 1A 
(2 ) 2 ( )A n A n , for 1n 
(2 1) 2 ( )A n A n  , for 1n 
Solving the above recurrence we get ( ) (2 ) 2m m
A n A l  
Plugging the constant function ( ) 1f n  into equation (2), we get
1
1 2 1 1
1 2 1 1

 
 

     
     
Putting the values of ,  and  in equation (3), we get
1 ( ) ( ) ( )A n B n C n   (4)
Similarly, we can plug in ( )f n n into equation (2).
1
2 2 0
2 1 2 1
n n
n n

 
 

   
    
Putting the values of ,  and  in equation (3), we get
( ) ( )
( ) ( )
n A n C n
C n n A n
 
  
2 2m m
l
l
  

Q: Write the General Recurrence of Josephus Problem.
Solve the recurrence (Or, find the closed form
expression of the recurrence) by Using
Repertoire Method. (start from prev page (the
recurrences) + this Page Full + next page upto
the point where you get all of A(n), B(n), C(n) )
Better: See Scanned Lecture (Pages 21-24)
Better explained in Scanned Lecture
Putting the values of A(n) and C(n) into equation (4), we can find B(n).
( ) ( ) ( ) 1B n A n C n  
(1)f 
(2 ) 2 ( ) jf n j f n    , for j = 0, 1 and 1n 
where 0  and 1  , and this recurrence unfolds, binary-wise
01 2 2 1 0 2 1 2 2 1 2(( ) ) 2 (( ) )m m m m m m bf b b b b b b f b b b b b      
1 0
1 0
2 1 0
2 1 0
1 2 3 2 2
2
1 2 3 2 2
2
1 2 3 2
3 2
1 2 3 2
2(2 (( ) ) )
2 (( ) ) 2
2 (2 (( ) ) ) 2
2 (( ) ) 2 2
m m m b b
m m m b b
m m m b b b
m m m b b b
f b b b b b
f b b b b b
f b b b b
f b b b b
 
 
  
  
 
 
 
 
  
  
   
   





1 2 2 1 0
1 2 2 1 0
1 2 2 1 0
1 2 2
2
1 2 2
2
2 (( ) ) 2 2 2 2
2 2 2 2 2
( )
m m
m m
m m
m m m
m b b b b b
m m m
b b b b b
b b b b b
f b     
     
    
 
 
 
 
 
      
      




To verify our new general formula, we are going to check the solution with previously
known value of Josephus problem. For example, when n = 100 = 2(1100100) , our
original Josephus value 01, 1      and 1 1   yield
n = (1 1 0 0 1 0 20) = 100
 0 0 1 0 0 2)
= ( 1 1 1 1 1 1 21)
= +64 +32 16 8 +4 2 1 = 73
We can generalize even more. The recurrence
( ) jf j  , for 1 j d 
( ) ( ) jf dn j cf n    , for 0 j d  and 1n 
is the same as the previous one except that we start with numbers in radix d and produce
values in radix c i.e. it has the radix-changing solution.
1 2 2 1 01 2 2 1 0(( ) ) ( )m m mm m m d b b b b b b cf b b b b bb          
 2m
l 1
The above method of solving recurrence problems is called repertoire method. In this
method first we find settings of general parameters for which we know the solution, this
gives us a repertoire of special cases that we can solve. Then we obtain the general case
by combining the special cases.
We can write the generalized recurrence of equation (2) as
n = ((1 1 0 0 1 0 0)2 )
= ( 1
Question: Find J(100)
by using the
Radix Based Property
of the
Josephus Problem
f(n)
*Q: Write The Radix Based Property
Of the Generalized Recurrence.
Use This Property to Find J(100) for
Josephus Recurrence.
(must write this: alpha, beta0, beta1)
Write the Recurrence for the
Generalized Josephus Problem
in original
For example, suppose we have the given recurrence
(1) 34
(2) 5
f
f


(3 ) 10 ( ) 76f n f n  , for 2n 
(3 1) 10 ( ) 2f n f n   , for 2n 
(3 2) 10 ( ) 8f n f n   , for 2n 
and suppose we want to compute f(19).
Here, we have d = 3 and c = 10.
3(19) ((201) )f f
2 0 1 10( )  
= (5 76 2 1 0
102) 5 10 76 10 2 10 500 760 2 1258          
which is our answer.
Though Easy, dont do like below (but you can
always verify your answer using this):
f(19) = f(3*6+1) =10f(6) - 2 = 10f(3*2) - 2
=10* [10f(2) + 76] - 2
=10* [10*5 + 76] - 2
= 100*5 +760 -2 ==> 1258
Question: Solve following recurrence using *Radix Based Properties* of the Generalized Josephus Problem
for n=3 (i.e., 6 persons, first 3 Good, next 3 Bad) => m= LCM(4,5,6) = 60
for n=4 (i.e., 8 persons, first 4 Good, next 4 Bad) => m= LCM(5,6,7,8) = 840
m = LCM of (3n, 3n-1, ... , n+1)
Read this Section from the Scanned Class Lecture
Pages 25 - 29 (more explanation and examples)

More Related Content

What's hot

recurence solutions
recurence solutionsrecurence solutions
recurence solutionssoumya8396
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsackAmin Omi
 
State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in aivikas dhakane
 
Insertion sort analysis
Insertion sort analysisInsertion sort analysis
Insertion sort analysisKumar
 
bag-of-words models
bag-of-words models bag-of-words models
bag-of-words models Xiaotao Zou
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IMohamed Loey
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithmMohd Arif
 
Counter propagation Network
Counter propagation NetworkCounter propagation Network
Counter propagation NetworkAkshay Dhole
 
Concept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithmConcept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithmswapnac12
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Convolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningConvolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningMohamed Loey
 
Travelling salesman problem
Travelling salesman problemTravelling salesman problem
Travelling salesman problemhamza haseeb
 
Back face detection
Back face detectionBack face detection
Back face detectionPooja Dixit
 

What's hot (20)

recurence solutions
recurence solutionsrecurence solutions
recurence solutions
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in ai
 
Insertion sort analysis
Insertion sort analysisInsertion sort analysis
Insertion sort analysis
 
bag-of-words models
bag-of-words models bag-of-words models
bag-of-words models
 
convex hull
convex hullconvex hull
convex hull
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Weiler atherton
Weiler athertonWeiler atherton
Weiler atherton
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Artificial Neural Network Topology
Artificial Neural Network TopologyArtificial Neural Network Topology
Artificial Neural Network Topology
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Counter propagation Network
Counter propagation NetworkCounter propagation Network
Counter propagation Network
 
Text Classification
Text ClassificationText Classification
Text Classification
 
Concept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithmConcept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithm
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Convolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningConvolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep Learning
 
Travelling salesman problem
Travelling salesman problemTravelling salesman problem
Travelling salesman problem
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
 
Back face detection
Back face detectionBack face detection
Back face detection
 

Similar to Recurrent problems: TOH, Pizza Cutting and Josephus Problems

Summation Series
Summation SeriesSummation Series
Summation SeriesMenglinLiu1
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)IJERD Editor
 
Recurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxRecurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxgbikorno
 
Hypothesis of Riemann's (Comprehensive Analysis)
 Hypothesis of Riemann's (Comprehensive Analysis) Hypothesis of Riemann's (Comprehensive Analysis)
Hypothesis of Riemann's (Comprehensive Analysis)nikos mantzakouras
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms IiSri Prasanna
 
Copy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerCopy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerJoepang2015
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrencesWaqas Akram
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrencesWaqas Akram
 
Formal expansion method for solving an electrical circuit model
Formal expansion method for solving an electrical circuit modelFormal expansion method for solving an electrical circuit model
Formal expansion method for solving an electrical circuit modelTELKOMNIKA JOURNAL
 
Location of Zeros of Polynomials
Location of Zeros of PolynomialsLocation of Zeros of Polynomials
Location of Zeros of Polynomialsijceronline
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transformAmr E. Mohamed
 
Binomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relationsBinomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relationsAqeel Rafique
 
General Solution for Josephus Problem
General Solution for Josephus ProblemGeneral Solution for Josephus Problem
General Solution for Josephus ProblemYoav Francis
 
Location of Regions Containing all or Some Zeros of a Polynomial
Location of Regions Containing all or Some Zeros of a PolynomialLocation of Regions Containing all or Some Zeros of a Polynomial
Location of Regions Containing all or Some Zeros of a Polynomialijceronline
 
FOUR-CORNER TRIANGLE ROTATION METHOD AND MAGIC SQUARES FROM THOSE OF THE LOHANS
FOUR-CORNER TRIANGLE ROTATION METHOD AND MAGIC SQUARES FROM THOSE OF THE LOHANSFOUR-CORNER TRIANGLE ROTATION METHOD AND MAGIC SQUARES FROM THOSE OF THE LOHANS
FOUR-CORNER TRIANGLE ROTATION METHOD AND MAGIC SQUARES FROM THOSE OF THE LOHANSLossian Barbosa Bacelar Miranda
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework HelpExcel Homework Help
 

Similar to Recurrent problems: TOH, Pizza Cutting and Josephus Problems (20)

Summation Series
Summation SeriesSummation Series
Summation Series
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
Recurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxRecurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptx
 
Hypothesis of Riemann's (Comprehensive Analysis)
 Hypothesis of Riemann's (Comprehensive Analysis) Hypothesis of Riemann's (Comprehensive Analysis)
Hypothesis of Riemann's (Comprehensive Analysis)
 
Number theory
Number theoryNumber theory
Number theory
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
 
Copy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerCopy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquer
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Stirling theorem
Stirling theoremStirling theorem
Stirling theorem
 
Hbam2011 09
Hbam2011 09Hbam2011 09
Hbam2011 09
 
Formal expansion method for solving an electrical circuit model
Formal expansion method for solving an electrical circuit modelFormal expansion method for solving an electrical circuit model
Formal expansion method for solving an electrical circuit model
 
Location of Zeros of Polynomials
Location of Zeros of PolynomialsLocation of Zeros of Polynomials
Location of Zeros of Polynomials
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transform
 
Binomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relationsBinomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relations
 
General Solution for Josephus Problem
General Solution for Josephus ProblemGeneral Solution for Josephus Problem
General Solution for Josephus Problem
 
Location of Regions Containing all or Some Zeros of a Polynomial
Location of Regions Containing all or Some Zeros of a PolynomialLocation of Regions Containing all or Some Zeros of a Polynomial
Location of Regions Containing all or Some Zeros of a Polynomial
 
FOUR-CORNER TRIANGLE ROTATION METHOD AND MAGIC SQUARES FROM THOSE OF THE LOHANS
FOUR-CORNER TRIANGLE ROTATION METHOD AND MAGIC SQUARES FROM THOSE OF THE LOHANSFOUR-CORNER TRIANGLE ROTATION METHOD AND MAGIC SQUARES FROM THOSE OF THE LOHANS
FOUR-CORNER TRIANGLE ROTATION METHOD AND MAGIC SQUARES FROM THOSE OF THE LOHANS
 
Stochastic Processes Assignment Help
Stochastic Processes Assignment HelpStochastic Processes Assignment Help
Stochastic Processes Assignment Help
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework Help
 

More from MenglinLiu1

Random variables
Random variablesRandom variables
Random variablesMenglinLiu1
 
Probability Basics and Bayes' Theorem
Probability Basics and Bayes' TheoremProbability Basics and Bayes' Theorem
Probability Basics and Bayes' TheoremMenglinLiu1
 
Math for anomaly detection
Math for anomaly detectionMath for anomaly detection
Math for anomaly detectionMenglinLiu1
 
Anomaly detection Full Article
Anomaly detection Full ArticleAnomaly detection Full Article
Anomaly detection Full ArticleMenglinLiu1
 
Questions on Anomaly Detection
Questions on Anomaly DetectionQuestions on Anomaly Detection
Questions on Anomaly DetectionMenglinLiu1
 

More from MenglinLiu1 (7)

Queueing theory
Queueing theoryQueueing theory
Queueing theory
 
Markov chain
Markov chainMarkov chain
Markov chain
 
Random variables
Random variablesRandom variables
Random variables
 
Probability Basics and Bayes' Theorem
Probability Basics and Bayes' TheoremProbability Basics and Bayes' Theorem
Probability Basics and Bayes' Theorem
 
Math for anomaly detection
Math for anomaly detectionMath for anomaly detection
Math for anomaly detection
 
Anomaly detection Full Article
Anomaly detection Full ArticleAnomaly detection Full Article
Anomaly detection Full Article
 
Questions on Anomaly Detection
Questions on Anomaly DetectionQuestions on Anomaly Detection
Questions on Anomaly Detection
 

Recently uploaded

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 

Recently uploaded (20)

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 

Recurrent problems: TOH, Pizza Cutting and Josephus Problems

  • 1. Recurrent Problems In recurrence, solution to a problem depends on the solution to smaller instance of the same problem. 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 large one onto a smaller. Fig: Tower of Hanoi with 8 disks Consider small cases: 0 0T  , [0 disk requires 0 move] 2 3T  3 7T  , [Transferring small 2 disks to middle peg requires 3 moves. Then moving the largest disk from left peg to right peg requires only 1 move. Finally, moving 2 smaller disks from middle peg to right peg requires another 3 moves. Thus, total 3+1+3=7 moves require for moving 3 disks from one peg to another] Similarly, for n disks to transfer from one peg to another we require: 0 0T  12 1n nT T   , for n > 0 We can find out the closed form of any recurrence to get quick result from the problem. 12 1n nT T   = 22(2 1) 1nT    = 2 22 2 1nT    = 2 32 (2 1) 2 1nT     = 3 2 32 2 2 1nT      = ( 1) ( 2) 2 2 2 2 2 2 1n n n n nT          = ( 1) ( 2) 2 1 0 02 2 2 2 2 2n n n T         T1 1, [1 disk requires only 1 move] Tn  Tn1 1Tn1  2Tn1 1 Thus, the recurrence for Tower of Hanoi stands Page 1 of 2 [Top disk from L to M; Bottom Disk from L to R; Finally, Top disk from M to R (see the Note below!)] (These Two are Constraints)
  • 2. 0 1 2 ( 2) ( 1) 2 2 2 2 2n n nT         = 2 1 2 1 n   [ 1 0 1 2 1 n n a a a a a a         ] = 2 1n  2 1n nT   is called the closed form solution of the “Tower of Hanoi” problem. Mathematical induction is a general way to prove any closed form solution. It has three parts.  Basis – prove the formula for smallest possible value.  Hypothesis – Consider that, the formula is true for first n values.  Induction – Try to prove the formula for (n+1)-th value. For example, we are going prove the closed from of Tower of Hanoi solution. Basis: 0 0 2 1 1 1 0T      Hypothesis: Let, 2 1n nT   Induction: 1 1 1 2 1 2(2 1) 1 2 2 1 2 1n n n n nT T              (Proved) Try to prove 1 0 1 2 1 n n a a a a a a         using Mathematical induction method. ☺Good Luck☺ Page 2 of 2 *** Also, Solve DOUBLE TOH and TRIPLE TOH *** (OK, because We know T0 is 0) (or, first n-1 values) (or, n-th value, if hypothsis true for n-1 values) Excluded -1
  • 3. Recurrent Problems Lines in the Plane: We have to find out how many slices of pizza can a person obtain by making n straight cuts with a knife. Academically, what is the maximum number of regions, nL defined by n lines in the plane? We can start by looking at small cases. 0 1L  1 2L  2 4L  3 4 3 7L    If there exists 1n  lines in the plane, then n-th line have to cut previous 1n  lines to produce maximum number of new region in the plane. The 1n  intersection points create n new region in the plane. Thus, the recurrence for line in the plane therefore 0 1L  1n nL L n  , for 0n  We can find out the closed form of the recurrence through unfolding it to the end. 1n nL L n  = 2 ( 1)nL n n    = 3 ( 2) ( 1)nL n n n       = ( 1) ( 2) ( 1)n nL n n n n n          = 0 1 2 3 ( 2) ( 1)L n n n         = 1nS  , where 1 2 3 ( 2) ( 1)nS n n n         nS is called the triangular number because it is number of bowling pins in an n-row triangular array. For example the usual four-row array has 4 10S  pins. n 01 02 03 04 05 06 07 08 09 10 nS 01 03 06 10 15 21 28 36 45 55 We can evaluate nS using the following trick: nS = 1 + 2 + 3 +  +( 2)n  +( 1)n  + n + nS = n +( 1)n  +( 2)n  +  + 3 + 2 + 1 2 nS =( 1)n  +( 1)n  + ( 1)n  +  +( 1)n  +( 1)n  +( 1)n  ( 1) 2 n n n S   , for 0n  Now, we have our closed form for lines in the plane problem. ( 1) 1 2 n n n L    , for 0n  1 2 1 1 2 3 4 1a 2 3a 4a 4b 3b1b But, if the newly added line goes thru any of the previous intersection points, then there will be less than "n new regions". For example: 1a 1b 2 4 3a 3b (Also, if the new line is parallel to any previous line then, we will get less regions. Check it yourself!!!) 6 in stead of 7 regions L2 = L1 + 2L1 = Lo + 1 L3 = L2 + 3
  • 4. Suppose instead of straight lines we use bent lines, each containing one “zig”. We have to find out the maximum number of regions, nZ created by n such bent lines in the plane. Fig: Bent lines in the plane From small cases, we realize that a bent line is like two straight lines except that region merge when the “two” lines don’t extent past their intersection point. Region 2, 3, 4 which would be distinct with two lines, become single region when there is a bent line, we lose two region. Thus 2 2n nZ L n  = 2 (2 1) 1 2 2 n n n    = 2 2 1 2n n n   = 2 2 1n n  , for 0n  Comparing closed forms of straight and bent lines in the plane, we find that for large n, 2 2 1 2 2 n n L n Z n   So, we get about four times as many regions with bent lines as with straight lines. ☺Good Luck☺ 1 2 3 4 Zn = Maximum no. of regions obtained from n intersecting Zig shapes in the plane Also Find, ZZn = Maximum no. of regions obtained from n intersecting ZigZag shapes Wn = Maximum no. of regions obtained from n intersecting W shapes
  • 5. Recurrent Problems Josephus Problem: We start with n people numbered 1 to n around a circle and we eliminate every second remaining person until only one survives. For example, here is the starting configuration for n = 10. The elimination order is 2 4 6 8 10 3 7 1 9        , so 5th person survives. The problem is to determine the survivor’s number, J(n). In this example J(10) = 5. Consider, we have 2n people, then after 1st round of elimination, we are left with n people and 3rd person will be the next person waiting for elimination. This is just like starting with n people, except that every person’s number has been doubled and decreased by 1. Similarly, if we start with 2 1n  people, then after 1st round of elimination number 1 will be eliminated. Then, we almost have the same situation with n people like previous one, but this time their numbers are doubled and increased by 1. Fig: Start with 2n people Fig: Start with 2 1n  people (2 ) 2 ( ) 1J n J n  , for 1n  (2 1) 2 ( ) 1J n J n   , for 1n  Combining these equations with (1) 1J  gives us a recurrence that defines J in all cases: (1) 1J  (2 ) 2 ( ) 1J n J n  , for 1n  (1) (2 1) 2 ( ) 1J n J n   , for 1n  Our recurrence makes it possible to build a table of small values which can helps us to guess the closed form of Josephus problem. ( )J n is always 1 at the beginning of a group and it increases by 2 within a group. So, if we write n in the form 2m n l  , where 2m is the largest power of 2 not exceeding n where 2m l n  satisfies 1 0 2 2 2m m m l      , the solution to our recurrence would be (2 ) 2 1m J l l   , for 0m  and 0 2m l  1 2 3 4 5 6 7 8 9 10 1 3 5 7  2 3n  2 1n  3 5 7 9  2 1n  2 1n  n 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 J(n) 01 01 03 01 03 05 07 01 03 05 07 09 11 13 15 01 Find J(100) using thess recurrences: J(100) = 2 J(50) -1 = 4 J(25) -2 -1 = 8J(12) + 4 - 2 -1 =16 J(6) -8 +4 -2 -1 = 32 J(3) - 16 -8 + 4 -2 -1 = 64 J(1) + 32 -16 -8 +4 -2 -1 = 64 + 32 -16-8+4-2-1 = 73 (ANS) J(n) = Write the Recurrence for Josephus Problem Establish the logic for these Recurrences
  • 6. To illustrate the solution let’s compute J(100). 6 (100) (2 36) 2 36 1 73J J      Try to prove, (2 ) 1m J  Every solution to a problem can be generalized so that it applies to a wider class of problems. Power of 2 played an important role in our recurrence solution. Thus it’s natural to look at the radix 2 representation of n and J(n). 1 2 2 1 0 2( )m m mn b b b b bb   i.e. 1 2 2 1 2 2 1 02 2 2 2 2m m m m m mn b b b b b b          where, each bit ib is either 0 or 1 and the leading bit mb is 1. Recalling that 2m n l  , we have, successively, 1 2 2 1 0 2(1 )m mn b b b bb   1 2 2 1 0 2(0 )m ml b b b b b   1 2 2 1 0 22 ( 0)m ml b b b bb   1 2 2 1 0 22 1 ( 1)m ml b b b b b    1 2 2 1 0 2( ) ( )m m mJ n b b b bb b   We have proved that, 1 2 2 1 0 2 1 2 2 1 0 2( ) (( ) ) ( )m m m m m mJ n J b b b b bb b b b bb b      For example, 2 2(100) ((1100100) ) (1001001) 64 8 1 73J J      We can find out special cases solution of Josephus problem if required. For example, we going to find when ( ) 2 n J n  is true. ( ) 2 n J n  2 2 1 2 m l l    1 (2 2) 3 m l   For all m, if 1 (2 2) 3 m l   is an integer, then solution exists. We can verify this equation m ( ) 2 1 / 2J n l n   1 0 002 01 3 2 010 05 5 10 042 21 7 42 170 85 Now, we are going to find out the closed form of more general recurrence of Josephus problem introducing constants ,  and . (1)f  (2 ) 2 ( )f n f n   , for 1n  (2) (2 1) 2 ( )f n f n    , for 1n  n  2^m  ll=1/3* (2^m-2) Binary Property of the Josephus Problem: l = 1/5 (2^m-3) Q: Find the minimum three values of n for which J(n) = n/3 Q: Find threee values of n for which J(n) = n Question: Find J(100)by using the Binary Property of the Josephus Problem l must be integer see the file : "Josephus Add On.docx" for such problems Q: Derive the Binary Property of the Josephus problem This is called General Recurrence of the Josephus Problem LHS = J(2^m) = 2 J(2^m-1) - 1 = 4 J(2^m-2) - 2 -1 = 8 J(2^m-3) - 4 - 2 -1 = ... ... ... = 2^m J(1) - 2^m-1 - 2^m-2 - ... -1 = 2^m - (2^m - 1) = 1
  • 7. We can construct the following general table for small values of n. n f(n) 1  2 2 +  3 2 +  4 4 +3  5 4 +2  +  6 4 +  +2 7 4 +3 8 8 +7  9 8 +6  +  Thus, we can express f(n) as following form ( ) ( ) ( ) ( )f n A n B n C n     (3) where A(n), B(n) and C(n) are coefficients of ,  and  respectively. Considering the special case 1, 0     , we get ( ) ( )f n A n and recurrence becomes (1) 1A  (2 ) 2 ( )A n A n , for 1n  (2 1) 2 ( )A n A n  , for 1n  Solving the above recurrence we get ( ) (2 ) 2m m A n A l   Plugging the constant function ( ) 1f n  into equation (2), we get 1 1 2 1 1 1 2 1 1                   Putting the values of ,  and  in equation (3), we get 1 ( ) ( ) ( )A n B n C n   (4) Similarly, we can plug in ( )f n n into equation (2). 1 2 2 0 2 1 2 1 n n n n                Putting the values of ,  and  in equation (3), we get ( ) ( ) ( ) ( ) n A n C n C n n A n      2 2m m l l     Q: Write the General Recurrence of Josephus Problem. Solve the recurrence (Or, find the closed form expression of the recurrence) by Using Repertoire Method. (start from prev page (the recurrences) + this Page Full + next page upto the point where you get all of A(n), B(n), C(n) ) Better: See Scanned Lecture (Pages 21-24) Better explained in Scanned Lecture
  • 8. Putting the values of A(n) and C(n) into equation (4), we can find B(n). ( ) ( ) ( ) 1B n A n C n   (1)f  (2 ) 2 ( ) jf n j f n    , for j = 0, 1 and 1n  where 0  and 1  , and this recurrence unfolds, binary-wise 01 2 2 1 0 2 1 2 2 1 2(( ) ) 2 (( ) )m m m m m m bf b b b b b b f b b b b b       1 0 1 0 2 1 0 2 1 0 1 2 3 2 2 2 1 2 3 2 2 2 1 2 3 2 3 2 1 2 3 2 2(2 (( ) ) ) 2 (( ) ) 2 2 (2 (( ) ) ) 2 2 (( ) ) 2 2 m m m b b m m m b b m m m b b b m m m b b b f b b b b b f b b b b b f b b b b f b b b b                                      1 2 2 1 0 1 2 2 1 0 1 2 2 1 0 1 2 2 2 1 2 2 2 2 (( ) ) 2 2 2 2 2 2 2 2 2 ( ) m m m m m m m m m m b b b b b m m m b b b b b b b b b b f b                                             To verify our new general formula, we are going to check the solution with previously known value of Josephus problem. For example, when n = 100 = 2(1100100) , our original Josephus value 01, 1      and 1 1   yield n = (1 1 0 0 1 0 20) = 100  0 0 1 0 0 2) = ( 1 1 1 1 1 1 21) = +64 +32 16 8 +4 2 1 = 73 We can generalize even more. The recurrence ( ) jf j  , for 1 j d  ( ) ( ) jf dn j cf n    , for 0 j d  and 1n  is the same as the previous one except that we start with numbers in radix d and produce values in radix c i.e. it has the radix-changing solution. 1 2 2 1 01 2 2 1 0(( ) ) ( )m m mm m m d b b b b b b cf b b b b bb            2m l 1 The above method of solving recurrence problems is called repertoire method. In this method first we find settings of general parameters for which we know the solution, this gives us a repertoire of special cases that we can solve. Then we obtain the general case by combining the special cases. We can write the generalized recurrence of equation (2) as n = ((1 1 0 0 1 0 0)2 ) = ( 1 Question: Find J(100) by using the Radix Based Property of the Josephus Problem f(n) *Q: Write The Radix Based Property Of the Generalized Recurrence. Use This Property to Find J(100) for Josephus Recurrence. (must write this: alpha, beta0, beta1) Write the Recurrence for the Generalized Josephus Problem in original
  • 9. For example, suppose we have the given recurrence (1) 34 (2) 5 f f   (3 ) 10 ( ) 76f n f n  , for 2n  (3 1) 10 ( ) 2f n f n   , for 2n  (3 2) 10 ( ) 8f n f n   , for 2n  and suppose we want to compute f(19). Here, we have d = 3 and c = 10. 3(19) ((201) )f f 2 0 1 10( )   = (5 76 2 1 0 102) 5 10 76 10 2 10 500 760 2 1258           which is our answer. Though Easy, dont do like below (but you can always verify your answer using this): f(19) = f(3*6+1) =10f(6) - 2 = 10f(3*2) - 2 =10* [10f(2) + 76] - 2 =10* [10*5 + 76] - 2 = 100*5 +760 -2 ==> 1258 Question: Solve following recurrence using *Radix Based Properties* of the Generalized Josephus Problem for n=3 (i.e., 6 persons, first 3 Good, next 3 Bad) => m= LCM(4,5,6) = 60 for n=4 (i.e., 8 persons, first 4 Good, next 4 Bad) => m= LCM(5,6,7,8) = 840 m = LCM of (3n, 3n-1, ... , n+1) Read this Section from the Scanned Class Lecture Pages 25 - 29 (more explanation and examples)