0% found this document useful (0 votes)
8 views2 pages

Recursion

Recursion is a programming technique where a function calls itself or another function that eventually calls it back. This process involves the use of stacks to manage function calls, with activation records created to store local variables, parameters, and return addresses. An example of recursion is the factorial function, which demonstrates the base case and recursive case in its implementation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Recursion

Recursion is a programming technique where a function calls itself or another function that eventually calls it back. This process involves the use of stacks to manage function calls, with activation records created to store local variables, parameters, and return addresses. An example of recursion is the factorial function, which demonstrates the base case and recursive case in its implementation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Recursion

Some computer programming languages allow a module or function to call


itself. This technique is known as recursion. In recursion, a function α either
calls itself directly or calls a function β that in turn calls the original function α.
The function α is called recursive function.

Many programming languages implement recursion by means of stacks.


Generally, whenever a function (caller) calls another function (callee) or itself
as callee, the caller function transfers execution control to the callee. This
transfer process may also involve some data to be passed from the caller to the
callee.
This implies, the caller function has to suspend its execution temporarily and
resume later when the execution control returns from the callee function. Here,
the caller function needs to start exactly from the point of execution where it
puts itself on hold. It also needs the exact same data values it was working on.
For this purpose, an activation record (or stack frame) is created for the caller
function.

This activation record keeps the information about local variables, formal
parameters, return address and all information passed to the caller function.
int fact(int n)
{
if (n < = 1) // base case
return 1;
else
return n*fact(n-1);
}

You might also like