Respuesta :

In recursion a function calls itself again and again until a condition where it terminates. the termination condition is called as the base condition.

we use recursion in case where we can define a larger problem in smaller ones and add a base condition where it terminates as in the below example of, factorial we can calculate n! when we know factorial of (n-1). and the base case will be n=0. we return 1 for n=0 as 0!=1.


Also when a function is called from the main() function, the memory is allocated to it on a stack. A recursive function calls itself, the memory for called function is allocated on top of memory allocated to calling function and different copy of local variables is created for each function call.When the base case is reached, the function returns its value to the function by whom it is called and memory is de-allocated and the process continues.

it can be better explained by following example;

int fact(int n)        //a function  fact

{

   if (n < = 1) /*base case  this is the case which will take the control out of          the recursive calling*/

       return 1;

   else    

       return n*fact(n-1);       //here the function is calling itself

}

base case for n < = 1 is defined and larger value of number can be solved by converting to smaller one till base case is reached. i.e.  if (n < = 1)


the above examples clearly depicts the use of recursion and if we invoke the recursive function without accounting for a base case then it will go into an infinite loop and it will cause a stack overflow (every called function is pushed into the stack) as there is no base condition that will take the control out of the recursive calling and terminate the recursion.

Thus if we the base case is not defined, then stack overflow problem may occur in recursion.

Answer:

If you create and invoke a recursive function without accounting for a base case then program run out of the stack or have an invalid algorithm.

Further explanation:

Recursion: Recursion is a method in which function call itself directly or indirectly. Some problems which can be easily solve by recursion are Tree Traversals, Tower of Hanoi(TOH), Preorder/Postorder/Inorder, DFS of graphs etc.

Condition for Recursion:

In recursion, the base condition is defined and the larger problem is defined in terms of base condition.

The example of recursion is shown in below program:

int factorial(int num){

if(n==0) return 1;

else return (num* factorial(n-1));

}

Therefore, without creating or invoking a base case recursion is not possible.

Learn more:

1. A company that allows you to license software monthly to use online is an example of ? brainly.com/question/10410011  

2. Prediction accuracy of a neural network depends on _______________ and ______________. brainly.com/question/10599832  

3. The shape of our galaxy was determined ‘on the inside looking out' by surveying the milky way using ____________ telescopes. brainly.com/question/7866623  

4. List 3 characteristics of the ideal encryption scheme. brainly.com/question/3000161  

Answer details:

  • Grade: Middle School
  • Subject: C Language
  • Chapter: Recursion

Keyword:

Recursion, create, invoke, recursive function, accounting, base case, wrong, factorial, out of stack, algorithm