Question

Write a few paragraphs that define recursion to someone who does not know what recursion is....

Write a few paragraphs that define recursion to someone who does not know what recursion is. Include an example of Scheme code in which recursion helped make the function more readable.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

                In program recursion is function called by it self directly or indirectly and the function which include recursion call it is called recursive function. Recursion is used in many data structure algorithms like Inorder/Preorder/Postorder traversals of tree, DFS of graphs, towers of hanoi problem etc. Recursion makes program more efficient. Recursion is a solution of problems which are created in iterative program.

Base condition is very important in recursive function.

what is base case?

Base case is stopping criteria/Stopping condition for recursive function.It is indicate at which condition recursive function call is over.If base case is not defined or not reached then stack overflow problem may arise.

In internal execution of recursive function stack will be used.

Advantages of recursive programming:

1.Recursive provides a simple and understandable way to write a code.

2.It reduce unnecessary function calling.

Disadvantages of recursive programming:

1.It very difficult to trace and it is always logical.

2.It use more processor time.

3. Recursion takes a lot of stack space, usually not considerable when the program is small and running on a PC.

Example:

write a c program to find the factorial of given positive number.

#include<stdio.h>

int fact(int n)

{

        if(n==0)        //Base case

              return 1;

        else

             return (n*fact(n-1));    //recursive function call

}

void main()

{

       int x,ans;

       printf("enter value of x:");

       scanf("%d",&x);

      ans=fact(x);    //main function call

     printf("factorial of %d is %d",x,ans);

}

Add a comment
Know the answer?
Add Answer to:
Write a few paragraphs that define recursion to someone who does not know what recursion is....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT