The Beauty of Recursion
Declaration: this article is in long time editing…
Here comes some beautiful recursive solutions to some problems.
Examples
Some of the problems have a very nice recursive structure, we can deal with them just using one step recursion.
Fibonacci Numbers
The first comes very famous Fibonacci Numbers, which is a sequence of 0, 1, 1, 2, 3, 5, 8, 13 … The structure is easily captured, if we use $\text{fib}(n)$ to denote the $n^{\text{th}}$ Fibonacci Number (n is assumed to start from 0). $$ \text{fib}(n) = \begin{cases} n, &\text{ if } n \le 1 \newline \text{fib}(n-1) + \text{fib}(n-2), &\text{ if } n > 1. \end{cases} $$ That is why we can write easily a procedure to compute the fibs. If we use MIT Scheme, we can write as follows: