Christopher Dearlove
11/4/2008 10:12:00 AM
"James Kanze" <james.kanze@gmail.com> wrote in message
news:899fde9e-356f-4d4d-bd12-3b42697e6530@k36g2000pri.googlegroups.com...
>On Nov 4, 5:56 am, Muzammil <muzammilPeer...@gmail.com> wrote:
>> i want good practice over recursion.
>> can any one give me links for recursion questions site.?? or
>> question.
>Well, factorial and fibonaci are the classical examples,
>although both have iterative solutions which are perhaps
>simpler. What you might try is a simple expression parser which
>handles parentheses.
The first example I ever saw that showed recursion was useful
(factorial does not, anyone who can understand it can see that
iteration is easier) was the Tower of Hanoi. Summarising the
solution, in a manner that obviously works, and maps directly to
recursion
To move N discs from A to B, first move N-1 discs from A to C,
then move disc N from A to B, then move N-1 discs from B to C.
A non-recursive solution exists (of course) but is a lot less obvious.
(I'm assuming the underlying problem is well-known. If not, I'm sure
Google will give you many explanations.)