You are on page 1of 3

1. What is recursion?

Recurrence or recursion recursion is the way in which a process based on its own
definition is specified. It is a bit more precise, and to avoid seeming endless circle in
this definition:
A problem that can be defined in terms of size, is this N, can be divided into smaller
instances ( < N ) of the same problem and the explicit solution to the simplest
instances is known, what is known as the base case , induction can be applied on
smaller calls and assume that these are resolved .
-

Recursion in informatics
In programming, a usual method of simplification of a complex problem is the
division of this in subproblems of the same type. This programming technique is
known as divide and conquer and is the core design of many important algorithms,
and is also a fundamental part of dynamic programming

1. Examples of recursion in nature or in everyday life (not algorithm).

Ej:
-

A restaurant tables are sorted by row and columns, in the table 12 is in the first row
and the second column. The same applies to the seats of a theater or cinema.
The library books are classified by subject and number of book, is AN1305, is an
anatomy book that is in the box 13 and the book 05.
Letters of an office are classified by a sequence and the year or date: CFE052 /
030410, corresponding to the letter 52 of 3 April 2010 addressed to the Federal
Electricity Commission.

2. Comparison of algorithms: factorial of a number.

-algorithm (iterative)
double factorial = 1;
// The number is chosen for factor 30
double number=30;
while ( number!=0) {
factorial=factorial*number;
number--;

}
System.out.println(factorial);

-algorithm (recursion)
public int factorial (double number) {
if (number==0)
return 1;
else
return number * factorial(number-1);
}
System.out.println(factorial(40));
4. Based on the above, responds in his words: The recursive algorithm is faster
the iterative Justify your answer?
-The difference is that in the Iterative are necessarily used, cycles or loops for iterations or
turns.
For example, calculate the sum from a list. It takes a FOR statement, WHILE or REPEAT to
cover it.
In each iteration is accumulated sum. Therefore use of batteries variables, iterator, flags
(or flags) are made.
Recursive algorithms are those who call themselves. A value, or unknown, to calculate its
value needs to obtain it from itself but from a previous "iteration".
5. There are several types of recursion, write about them.
- Direct recursion: When the F code has a sentence involving F.
- Indirect or cross Recursion: When the function F involves a G function that invokes see a
H function, and so on, until the function it is involved F. For example the algorithm even or
odd.
- Recursion simple: One in whose function appears only a recursive call. It can be
transformed easily into iterative algorithms.
- Multiple Recursion: it occurs when there is more than one call itself within the body of
the function, resulting harder to transform iterative. For example Fibonacci algorithm.

- Recursion nested: In some of the arguments of the call is a new call itself.
- Infinite recursion: Iteration and recursion can occur infinitely. An infinite loop occurs if
the test or test loop then never becomes false. Actually, the infinite recursion means that
each call recursive, recursive call produces another and this in turn another recursive call,
and so forever. In practice, this function will run until the computer runs out of memory
available and an abnormal program termination occurs.

You might also like