Jumat, 22 April 2011

CURSIVE PROCEDURE and FUNCTION "PROSEDUR dan FUNGSI REKURSIF"

  Agus Nur Ikhsan       Jumat, 22 April 2011

RECURSIVE PROCEDURE and FUNCTION
Procedures and functions is a sub program that is very useful in programming, especially for large programs or projects. 
Benefits of using sub-programs include:

Procedures and functions is a sub program that is very useful in programming, especially for large programs or projects. 
Benefits of using sub-programs include:


1. 
increase readibility, which facilitate the reading program
2. increase modularity, that is something that big break into modules or parts that are smaller in accordance with its function, thus simplifying the checking, testing and localization errors.
3. enhance reusability, which is a sub-program can be used repeatedly by simply calling the sub program without writing the commands should be repeated.

Sub Recursive Program is a sub program that calls itself as long as the conditions met callings.

Given the nature of the sub is a recursive program over the sub-recursive program must have:
1) condition that causes him to stop calling (called the special conditions or special conditions)
2) calling themselves the sub program (ie if specific conditions are not met)

In general form of recursive sub-programs have a conditional statement:
if special conditions not met
then call the self-righteous with the appropriate parameters
else do the instruction to be executed when the special conditions met

Sub recursive programs are generally used for problems that have a completion step, patterned or irregular steps. 
If we have a problem and we know the solution algorithm, sometimes sub recursive program of choice when it allows us to use. The algorithmic (in terms of algorithms, that is, if we consider the memory usage, execution time of sub program) sub recursive programs are often inefficient.
Thus the recursive sub-programs typically have efficiencies in the writing of orders, but sometimes not efficient algorithmic. 
Even so many problems that are better suited solved by a recursive manner (eg in the search / searching, which will be discussed at the meetings that will come).

Examples of recursive sub-programs in the Pascal language.

1). 
A simple example
PROCEDURE TULIS_1 (many: integer; word: string);
begin
if a lot of> 1 then TULIS_1 (lot-1, word);
Writeln (word, lots: 5);
end;

OUTPUT (eg called by TULIS_1 (5, "Print to"))

Matter to 1
Matter to 2
Matter to 3
Prints to 4
Matter to 5

Compare the above procedure and its output with the procedure below!

PROCEDURE TULIS_2 (many: integer; word: string);
begin
Writeln (word, lots: 5);
if a lot of> 1 then TULIS_1 (lot-1, word);
end;

OUTPUT (eg called by TULIS_2 (5, "Print to"))

Matter to 5
Prints to 4
Matter to 3
Matter to 2
Matter to 1

Why different results?

2.) Sample applied
Mathematically, the multiplication of two positive integers a with b (written ab or axb) is essentially a summation of a tribe as much as b, ie a + a + a + .... 
+ A much bsuku. Eg 2 x 3 can be interpreted as 2 + 2 + 2 = 6, ie the sum of 2 of 3 tribes Given that a number when multiplied by the number 1 (one) will produce a number itself, then multiplication problems to put it in the form of summation over can be easily solved by computer.

logoblog

Thanks for reading CURSIVE PROCEDURE and FUNCTION "PROSEDUR dan FUNGSI REKURSIF"

Previous
« Prev Post

Tidak ada komentar:

Posting Komentar