Book on recursion tia sal2

Greetings all

I'm looking for a book or free online source / video that helps explains/teaches recusions

 

tia sal2

goal

What do you expect to learn?  Using recursion is simple enough, the best way is through practice.  More complicated is learning when and how to avoid recursion when it is inefficient.

When using recursion with Maple, one can frequently use the remember/cache option to significantly speed up a compuation.  For example, consider the classic Fibonacci sequence:

f(0) = 0:  f(1) = 1;  f(n) = f(n-1) + f(n-2):
fib := proc(n::nonnegint)
   if n = 0 then return 0
   elif n = 1 then return 1
   else return fib(n-1) + fib(n-2);
   end if:
 end proc:

This is quite inefficient:

time(fib(30));
                                 8.150

However, by adding the cache option, so that previous calls are cached, it becomes significantly faster

fib := proc(n::nonnegint)
option cache;
   if n = 0 then return 0
   elif n = 1 then return 1
   else return fib(n-1) + fib(n-2);
   end if:
end proc:

time(fib(1000));
                                     0.012

It is also possible to explicitly store results without using a cache/remember table.  That can be done with an assignment statement, fib(1) := 1. 

fib := proc(n::nonnegint)
   fib(n) := fib(n-1) + fib(n-2);
end proc:
fib(0) := 0:
fib(1) := 1:

time(fib(1000));
                                   0.012

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}