Recursion
- Karla G
- 28 mar 2015
- 1 Min. de lectura
Recursion Defined
What is recursion? Sometimes a problem is too difficult or too complex to solve because it is too big. If the problem can be broken down into smaller versions of itself, we may be able to find a way to solve one of these smaller versions and then be able to build up to a solution to the entire problem. This is the idea behind recursion; recursive algorithms break down a problem into smaller pieces which you either already know the answer to, or can solve by applying the same algorithm to each piece, and then combining the results.
(by Sparknotes)
Looking for further information? Go to sparknotes, seriusly. This page explains it all:
http://www.sparknotes.com/cs/recursion/whatisrecursion/section1.rhtml
Now, a little example of recursion:
We all know what a factorial is, if not, go look for it and then continue.
Here is the pseudocode for developing a factorial :
function fact (n is a non-negative integer)
if n is 0 then
return 1 [by the convention that 0! = 1]
else
return factorial(n – 1) times n [recursively invoke factorial with the parameter 1 less than n]
end if
end function
Recursion is literally a function calling itselve n times until it get a result.
Here you can see how the pseudocode is executed for n=6

References:
Sparknotes. (2015). What is Recursion?. 27 March 2015, de Sparknotes LLC Sitio web: http://www.sparknotes.com/cs/recursion/whatisrecursion/section1.rhtml
Comments