Recursive Algorithms:
A recursive function is a function that is defined in terms of itself. Similarly, an algorithm is said to be recursive if the same algorithm is invoked in the body. An algorithm that calls itself is direct recursive. Algorithm A is said to be indirect recursive if it calls another algorithm which in tern calls A. These recursive mechanisms are extremely powerful, but even more importantly; many times they can express an otherwise complex process very clearly.
The following algorithm is Recursive function for sum:
Algorithm RSum (a, n)
{
if (N<=0) then return 0.0;
else return RSum(a, n-1) + a[n];
}
No comments:
Post a Comment