12 Apr 2012

What Is Recursive...???


what is it recursive???

 This time I will post material recursively, instead of raptor, or program, but the understanding and explanation of what it is recursive ... 
so that we can easily learn and understand about the famous recursive material is not easy, and also to think to understand and easily put it in a raptor or a program. 

Recursive is a tool / way to solve the problem in a function or procedure that calls itself.Definition according to Niclaus Wirth:"An object is said be recursive if it consist partially or is defines in terms of Itself"mathematical calculations (eg factorial function and the Fibonacci numbers)Factorial 

>>Factorial function of the positive integer n is defined as follows: 

n! = n. (n-1)! , If n> 1n! = 1, if n = 0, 1 


3! = 3. 2!3! = 3. 2. 1!3! = 3. 2. 13! = 6 

We can write the factorial function calculator as shown below: 

int Factorial (int n) 
   {if ((n == 0) | | (n == 1))return (1); 

else return 

      (n * factorial (n-1));} 

On line 3 of the above functions,checked the value of n is equal to 0 or 1,if yes, then the function returns 1 row {4},if not, the function returns the value of n * Factorial (n -1){Line 6}this is where the recursive process, notice of this factorial function calls itself, but with parameters (n-1). 

>>Fibonacci Numbers 

Other functions can be transformed into a recursive form of the Fibonacci calculations. 

Fibonacci numbers can be defined as follows: 

fn = fn-1 + fn-2 for n> 2f1 = 1f2 = 1 

Here is a sequence of Fibonacci numbers ranging from 

                     n = 11 1 2 3 5 8 13 21 34 

Fibonacci algorithm is used:
  • Function Fibonacci (input n: integer) integer -->
Declaration of Local

{No}DescriptionIf (n == 1 | | n == 2) Then

return (l)Else

return (Fibonacci (n-1) + Fibonacci (n-2))ENDIF 

For the size of n = 4, 

the Fibonacci calculations can be performed as follows: 

f4 = f2 + f3f4 = (f1 + f2) + f2f4 = (1 +1) +1f4 = 3 

Combination of:Function Combination (input n, r: integer) --> realDeclaration

If (n <r) Thenreturn (0)

  Elsereturn (Factorial (n) / factorial (r) * factorial (nr))



The permutation function (input n, r: integer) --> realDeclaration



       If (n <r) Thenreturn (0)

  Elsereturn (Factorial (n) / factorial (n-r))


There is a theory about Recursive. I hope we can be understand with it.. 

Motivation :  Learn More And Get More (Inayah 12042012)



Tidak ada komentar:

Posting Komentar