Concrete Mathematics: Chapter 2: Part 2
Topic: Maths, Date: 29/09/2016
Summation Factor
As mentioned in the previous blog, I need to go over a few things that were mentioned but never explained. The first is the summation factor. This is what is used in order to reduce a recursive equation down to a more simple version. So we can reduce a recursion from
anTn=bnTn−1+cn
to the form
Sn=Sn−1+sncn
by multiplying by a summation factor and then substituting in Sn=snanTn. This greatly reduces the recurrence so it is much easier to convert it into a summation with sigma notation. The above would then translate to the following summation:
Sn=s0a0T0+k=1∑nskck=s1a1T0+k=1∑nskck
It is important to note that there is the term s0a0T0 as this is used when the starting terms are non-zero or the summation factor is undefined. The book makes subtle use of this term with the quicksort example. I will talk a bit about that later on.
Now we know how to use the summation factor, we need to learn how to get the summation factor. In the first part for this chapter I just multiplied the tower of Hanoi recursion by 2−n without explaining where that was from. Well, it turns out that was found using the equation
sn=bnbn−1…b2an−1an−2…a1
Okay. Let's try that and see if we can get 2−n.
First we note that an=1, bn=2 and cn=1. This means that the formula is the following
snsnsn=2⋅2⋅…⋅21⋅1⋅…⋅1=2n−11=2−(n−1)(Substitute in the values)(There are n−1 terms of bn)(Rearrange)
That's weird, we ended up with a different summation factor than the one that's in the book. Not to worry, the book tells us that it's ok to use any multiple of the summation factor and it should still work. So let's carry on.
T0Tn=0;=2Tn−1+1,for n>0
Multiply by summation factor, 2−(n−1)
T0/2n−1Tn/2n−1=0=2Tn−1/2n−1+1/2n−1=Tn−1/2n−2+2−(n−1)
Let Sn=Tn/2n−1
Sn=Sn−1+2−(n−1)=k=1∑n2−(k−1)
Convert back to Tn
Tn/2n−1Tn=k=1∑n2−(k−1)=2n−1k=1∑n2−(k−1)
Now we can try some values to verify that this will indeed work. First n=3,
Tn=22(2−0⋅2−1⋅2−2)=4(1⋅21⋅41)=7
Great! Checking other n shows that this is a summation solution for the tower of Hanoi. However it is not as elegant as the solution the book gave when it used 2−n as the summation factor. So make sure to play with the summation factor when converting recurrences to sums.
Problem with quicksort example
So far this book has stumped me in a few places, but I can generally work through the problem until the answer clicks. However, the one I have spent the most time on was a problem with the quicksort example.
While working through their examples, I couldn't see where they gained the extra term for the final solution. Fortunately, I found the solution on math.stackexchange. I turns out that the summation factor is undefined for the early terms and so we need to add them to the summation which doesn't include the terms.
Sn=S2+k=3∑nskck=s2a2C2+k=3∑nskck=31⋅2⋅3+k=3∑nk(k+1)4k=2+4k=3∑nk+11
Then convert back to Cn
Cn=snanSn=2n+1(2+4k=3∑nk+11)=(n+1)(1+2k=1∑nk+11−2k=1∑2k+11)=(n+1)(1+2k=1∑nk+11−35)=(n+1)(2k=1∑nk+11−32)=2(n+1)k=1∑nk+11−32(n+1)
Many thanks to Brian M. Scott for answering the question posed by Cyril on StackExchange. I'd still be trying to figure it out otherwise.