Is recursive ever required to solve a problem What other app
Is recursive ever required to solve a problem? What other approach can be used to solve a problem that is repetitive in nature? Explain in detail.
Solution
No, always recursive is not required to solve a problem. In recursive procedure, the variables are stored in stack where pop and push operations are done. So this recursive procedure can be written as iterative procedure also. But still some problems cannot written as a iterative procedure.
The other approach for recursive approach is tail recursive approach. In recursive approach the last statement will use previous iteration statement result. In tail recursion the last statement will not use or depend on previous statement result.
void display(int n)
{
if (n < 0) return;
print(n)
// calling recursively by tail-recursive
display(n-1);
}
