Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having trouble understanding how the author Steven Skiena of the book The Algorithm Design Manual used the induction method to prove the following algorithm that represents/returns y = y + 1 in pseudocode:

Increment(y)
        if y = 0 then return(1) else
            if (y mod 2) = 1 then
                 return(2 · Increment(y/2)) 
            else return(y + 1)


Specifically I don't understand how he got from the first equation/equality 2·Increment(m + 1/2) to the next one 2·Increment(m) in the proof below. In his full text he states that:

"For the odd numbers, the answer depends upon what is returned by Increment(y/2). Here we want to use our inductive assumption, but it isn’t quite right. We have assumed that increment worked correctly for y = n − 1, but not for a value which is about half of it. We can fix this problem by strengthening our assumption to declare that the general case holds for all y ≤ n−1. This costs us nothing in principle, but is necessary to establish the correctness of the algorithm.

Now, the case of odd y (i.e. y = 2m + 1 for some integer m) can be dealt with
as:

2·Increment((2m + 1)/2) = 2·Increment(m + 1/2)
                        = 2·Increment(m)
                        = 2(m + 1)
                        = 2m +2 = y + 1

"

What I have tried:

I understand that the algorithm is recursive and that it is correct for both even and odd numbers always incrementing the input value of y. However, the author is using induction to prove the algorithm and for the case where y = m + 1, I don't know why the + 1/2 just dissapeared. I don't think it fits the cases where m is just to big that 1/2 is almost insignificant since we're talking whether m + 1 is even or odd.
Posted
Updated 7-May-19 0:25am
v3
Comments
Richard MacCutchan 7-May-19 4:36am    
You could always ask the author.
[no name] 7-May-19 4:52am    
2·Increment((2m + 1)/2) = 2·Increment(m + 1/2)
= 2·Increment(m)
= 2(m + 1)
= 2m +2 = y + 1

Induction only works on whole numbers to start with*, so even if the author didn't make any other statement as to the numbers being used, it's reasonable to assume everything is completely in the realm of integers.

Also, in case of calculations resulting in non-integral value, the non-integral part is cut off, not rounded. This is standard integer mathematics: 5/2 = 2 (plus remainder)

Under these assumptions, m+1/2 is interpreted as m.

*: to be more precise, induction works on any set that is ordered and countable (even countably infinite), but the implication is always the set of whole numbers, unless stated otherwise.


On a sidenote, I find it unfortunate that the author chose not to be clearer. Induction is not a trivial method to explain, it doesn't help to needlessly introduce tripping stones in the example(s).
 
Share this answer
 
Comments
TheRealJ 9-May-19 4:05am    
Thank you very much for taking the time! I understand now what I was missing. Great explanation ;)
The author was perfectly clear. In the book it's not m + 1/2, it's Increment(floor(m + 1/2)) which drops everything after the decimal resulting in Increment(m)
 
Share this answer
 
Comments
CHill60 29-Oct-21 4:12am    
This is not a solution. If you want to comment on a post then use the "Have a Question or Comment?" link next to it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900