Recursion

Recursion

Recursion is one of the most powerful tools in the programming language, but is one of the most threatening topics.

Recursion is defined as defining anything in terms of itself. In recursion a function calls itself.

Types of recursion

Recursion is of two types depending on whether a function calls itself from within itself, or whether two functions call one another mutually. The former is called direct recursion and later is called the indirect recursion.

Direct recursion

int abc()
{
statements;
statements;
abc();
}

Indirect recursion

int abc()
{
statements;
statements;
xyz();
}
int xyz()
{
statements;
statements;
abc();
}

S.no

Iteration

Recursion

1.

It is a process of executing a statement or a set of statement repeatedly, until some specified condition is true.

Recursion is the technique of defining anything in terms of itself.

2.

Iteration involves four(4) clear cut steps initialization, condition, execution and updation.

There must be an exclusive if statement inside the recursive function, specifying stopping condition.

3.

Any recursive problem can be solved iteratively.

Not all problems have recursive solution.

4.

Iterative counterpart of a problem is more efficient in terms of memory utilization and execution speed.

Recursion is generally a worse option to go for simple problem, or problems not recursive in nature.

C Language Programming Tutorial

C Language Tutorial Home     Introduction to C Language     Tokens     If Condition      goto statement and Labelname     Switch Statements     For loop     While Loop     Do while loop     break and continue     Functions     Recursion     Inbuild Functions     Storage Classes     Preprocessor     Arrays     Pointers     Structures and Unions     File Handling     Projects

Number Of Visitors

0238185