Recursive and Iterative
1. Recursive Definition
May imply that a recursive process that can call itself. slightly deviate from the opinion there is little understanding about Recursive one of which is by definition in the Microsoft Bookshelf, is the ability of a recursive routine to call itself. Recursive definition is actually contained in the procedures and functions. The difference is that the recursive call to itself can be, but the procedures and functions must be called by the caller procedures and functions. Recursive programming is an important technique and some programming languages support the existence of this recursive process. In procedures and functions, the call to itself could mean an iterative process that can not be known when it will end.
The simplest example of this recursive process is a process to calculate the factorial of a positive integer and seek Fibbonacci sequence of an integer.
1. Factorial value can be written recursively as
0 ! = 1
N ! = N x (N-1) !
programming which can be written as:
Faktorial (0) = 1 (1)
Faktorial (N) = N * Faktorial (N-1) (2)
Equation (2) above is an example of the relationship rekurens (recurrence relation), which means that the value of a function with certain arguments can be calculated from the same function with a smaller argument. Equation (1) is not recursive, called the initial or base value. Every recursive function has at least one initial value, otherwise the function can not be calculated explicitly.
2. Fibonacci numbers are defined as follows
1 1 2 3 5 8 13 21 34 55 89 …
of the sequence can be seen that the number N (N> 2) in a row can be sought from the two previous numbers closest to the number N, the number to a-(N-1) and the number-(N-2), so that it can formulated as
Fibbonacci(1) = 1 (1)
Fibbonacci(2) = 1 (2)
Fibbonacci(N) = Fibbonacci(N-1) + Fibbonacci(N-2) (3)
By equation (1) and (2) is the basis and the equation (3) is its rekurens.
Rekursif Versus Iteratif
In some situations, solving recursively or iteratively has advantages and disadvantages that can be mutually compared. It is quite difficult to determine which is the simplest, clearest, most efficient and most easily compared to the other. Arguably iterative and recursive way the election was a programmer and fun context dependent problems will be solved in accordance with the relevant abilities.
2. recursive function
In the previous discussions, it has been discussed about the function. “What are the benefits of using Recursion Function”.
|Recursive loop is one method of programming in which the instructions contained in a function that calls a function that sendri, or more commonly referred calls itself.
||Recursive loop is one method of programming in which the instructions contained in a function that calls a function that sendri, or more commonly referred calls itself.
Excess recursive loop
- It’s easy to do looping with a wide range in terms of looping in a large scale
- Can do the loop with the restriction function
|Excess loop iterative
- Easy to understand and easy to do debuging when there is one iteration
- Can do a nested loop or so-called nested looping
- The loop is short lived and occurs in conditions that have been adjusted
- Rarely overflow because of the restrictions and conditions clear looping
|Weakness of the recursive loop
- Can not do a nested loop or nested loops
- Usually makes it difficult to understand the function, only suitable for certain problems
- Require a larger stack, because every time the function was called, local variables and formal parameters will be placed into the stack and there will Kalaya no longer enough to cause a stack (Stack Overum)
- The process is somewhat convoluted because there pemangilan repetitive functions and data calls dit
|Weakness of iterative looping
- Can not use the restriction of the function
- teration with a broad restriction would make it difficult in making itself looping program
Differences and Similarities Recursive and Iterative:
– Same-as a form of looping.
– Do check conditions before repeating.
– Iterative use the FOR, WHILE, DO-WHILE IF while the recursive use only.
– Iterative can be run on a program that consists of procedures (There is no function) while
is a recursive function