Josephus Problem - Recurrence - Revisited - Unrolled
I am restarting Concrete Mathematics (Graham, Knuth, Patashnik) due to a forced break due to a neurological problem called Anti-NMDA receptor encephalitis. I include this detail because it is a relatively newly discovered disease and misdiagnosis is common so, in a very small way, raising awareness.
Maths is my friend in the recovery process even though it is challenging. Perhaps because it is challenging.
This post goes over the recurrence only because I found that challenging. For some reason I find recursion harder than it should be π
Setting the Scene with Some ExamplesPermalink
While the concept of shooting each second remaining person sounds obvious I found it useful to step through it on pen and paper which I will attempt to reproduce here in text; really an animation is also useful to look at such as this one. I wonβt show a diagram because all you see is the end result which is not so useful
- Survivor is obviously because Josephus does not want to kill himself.- 1 shoots 2
- 1 survives
- 1 shoots 2
- 3 shoots 1
- 3 survives
- 1 shoots 2
- 3 shoots 4
- 1 shoots 3
- 1 survives
- β¦ and so on - see above linked video for a great explanation.
I was accidentally thinking the dead person was also shooting someone (π ) which meant I was messing up above. Here is a tabular form of the above as presented in the book:
I think the point the book is trying to make is that, at each go around, we are essentially at the same point as the round before except there are half as many people _and their numbers (aka βlabelβ or βpositionβ) have changed. Or, as Wikipedia puts it:
The first time around the circle, all of the even-numbered people die. The second time around the circle, the new 2nd person dies, then the new 4th person, etc.; it is as though there were no first time around the circle.
The RecurrencePermalink
This refers heavily to this post by, the ever helpful, Brian M. Scott. I am only adding even more details for my addled brain to help it understand.
First the recurrences (for base case, odd, and even) which is the notational expression of the above sentences:
UnrollingPermalink
The post by Brian M. Scott
shows the case for
Formatting note: I am using a comma followed by some notes. The font for the
\text{...}
is not beautiful but serves the purpose.
n = 1Permalink
This is the base case so
n = 2Permalink
n = 3Permalink
n = 4Permalink
n = 5Permalink
n = 6Permalink
ConclusionPermalink
Doing this manual unrolling really helps understand the nature of the problem when expressed in math notation. We can see how powers of two play a role which is useful in the closed for solution(s).