Iteration and Recursion
Iteration and Recursion
CC – 148/294
UNDER MAKAUT, WB
CONTINUOUS ASSESSMENT 1
Data Structure & Algorithm (ES)
PCC-CS301
Presented by
DEBMALYA DASH
14800321063
ECE 3rd SEM
AY : 2022-23
Table of Content
01 02 03 04 05 06
What is What is Recursion vs Example of Can Iteration and Reference
Iteration? Recursion? Iteration Iteration and recursion be used
Recursion interchangeably ?
What is Iteration?
The iteration can be defined as repeating the same process multiple times until a specific
condition satisfies. It is also known as looping.
Exit Controlled Loops : In this type of loop the test condition is tested at the end of the loop
body. Therefore, the loop body will execute at least once, irrespective of whether the test
condition is true or false. the do-while loop is exit controlled loop.
for (initialization expr; test expr; update expr)
{
Syntax of For loop : // body of the loop
// statements we want to execute
}
initialization expression;
while (test_expression)
{
Syntax of While loop : // statements
update_expression;
}
initialization expression;
do
{
// statements
Syntax of do-while loop :
update_expression;
} while (test_expression);
What is Recursion?
Recursion is the process of repeating items in a self-similar way. In programming languages, if a
program allows you to call a function inside the same function, then it is called a recursive call of
the function.
Working of Recursion :
void recurse()
{ recursive
... .. ... call
recurse();
... .. ...
}
int main()
{
... .. ...
recurse();
... .. ...
}
given number.
Declare i,
Program : Flowchart : fact=1, num
As we can see from the previous two example the same problem is done using both Iteration and
Recursion. Not only this problem any problems can be using both of this method.
The concept of Recursion and Iteration is to execute a set of instructions repeatedly. The
difference between them is that recursion is simply a method call in which the method being
called is the same as the one making the call while iteration is when a loop is repeatedly executed
until a certain condition is met. Under the hood, both recursion and iteration depends on a
condition so as to know when to stop but recursion is simply a process, always applied to a
function.
Reference
www.geeksforgeeks.org
https://stackoverflow.com
Let Us C Book by Yashavant Kanetkar