UNIT-5 RECURSION
1
, 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.
▪ Any function which calls itself is called recursive function and such
function calls are called recursive calls.
▪ Recursion cannot be applied to all problems, but it is more useful for the
tasks that can be defined in terms of a similar subtask.
▪ It is idea of representing problem a with smaller problems.
▪ When recursive function call itself, the memory for called function
allocated and different copy of the local variable is created for each
function call.
▪ But while using recursion, programmers need to be careful to define an
exit condition from the function, otherwise it will go into an infinite
loop.
1
, 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.
▪ Any function which calls itself is called recursive function and such
function calls are called recursive calls.
▪ Recursion cannot be applied to all problems, but it is more useful for the
tasks that can be defined in terms of a similar subtask.
▪ It is idea of representing problem a with smaller problems.
▪ When recursive function call itself, the memory for called function
allocated and different copy of the local variable is created for each
function call.
▪ But while using recursion, programmers need to be careful to define an
exit condition from the function, otherwise it will go into an infinite
loop.