answersLogoWhite

0


Best Answer

Read the part in your programming manual/text book about recursion.

The short answer while easy does not tell you anything about the power or dangers of recursion. It is the power and dangers of recursion that is important because once understood you can use recursion to good effect without running out of stack space.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of recursion function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When a function call by itself?

Recursion.


What is the difference between left recursion and right recursion in a grammar?

Recursion is what it's called when a function calls itself. When a function calls itself immediately before returning, it's called tail recursion. Tail recursion can be more efficiently written as iteration. In fact a good compiler will recognize tail recursion and compile it as iteration. There is no such thing as left or right recursion in C programming.


Explain the term Recursion with example?

Recursion is when a function (procedure) calls itself. Example: int Fib (int n) { if ((n==1)(n==0))return 1; else return Fib(n-1) + Fib(n-2); }


What happens if recursion function is declared inline?

An inline function replaces the call to the function by the body of the function, thus reducing the overhead of saving the context in stack. This is good for functions which are small in size and called occasionally. A recursive function calls an instance of itself and thus can be a deeply nested. Different compilers handle this differently. Some will inline it up to a certain depth and then call a non-inlined instance for further recursion; others will not inline the function at all and generate a normal function call.


What do you mean by base case recursive case binding time runtime stack and tail recursion?

These terms are found in Recursion.1.Base Case:it is the case in recursion where the answer is known,or we can say the termination condition for a recursion to unwind back.For example to find Factorial of num using recursion: int Fact(int num){ if(num==1 num==0)//base casereturn 1;else // recursive case: return num*Fact(num-1);} 2.Recursive case:It is the case whcih brings us to the closer answer. Run Time Stack:It is a system stack us to save the frame stack of a function every recursion or every call.This frame stack consists of the return address,local variables and return value if any. Tail Recursion:The case where the function consist of single recursive call and it is the last statement to be executed.A tail Recursion can be replace by iteration. The above function consists of tail recursion case.where as the below function does not. void binary(int start,int end,int el){int mid;if(end>start){mid=(start+end)/2;if(el==ar[mid])return mid;else{if(el>ar[mid])binary(mid+1,end,ele);elsebinary(start,mid-11,ele);

Related questions

What is direct recursion?

When a function calls itself it is called as direct recursion. A function calls other functions which eventually call the original function is called as indirect recursion.


How many types of recursion are there in c language?

Recursion in c language is a method where the function calls itself, within or outside the scope. Using Recursion, complicated problems can be divided into smaller parts so that solving them becomes more manageable. The recursion technique is available in Java, JavaScript, and C++.serves the same purpose. The type of Recursion in C • Direct Recursion • Indirect Recursion. Direct Recursion Recursion can call the function n-number of times. In the case of direct Recursion, the function calls itself inside the same position or in the local scope Direct Recursion problems are the Fibonacci series, a program to print 50 natural numbers. Indirect Recursion In the case of Indirect Recursion, a function X calls function Y, and function Y calls any function Z. Under certain conditions, function Z calls function A. In this case, function A is indirectly related to function Z. Indirect Recursion is also known as mutual Recursion, as more than one function runs a program. It is a two-step recursive function call process for making a recursive function call. Below mentioned are also type of Recursion: Tail Recursion No Tail/Head Recursion Linear Recursion Tree Recursion Tail Recursion A function is said to be tail recursion if it calls itself and also calls the last or the previous statement executed in the process. Head Recursion A function is said to be Head Recursion if it calls itself and also calls the first or the beginning statement executed in the process. Linear Recursion A function is said to be a linear recursive function if it makes a single call to itself each time the procedure executes itself and grows linearly depending on the size of the problem. Tree Recursion Tree Recursion is different from linear Recursion. Rather than making only one call to itself, that function makes more than one recursive call to the process within the recursive function. Following are the steps to solve the recursive problem in C: Step 1: Create a function and assign the work a part should do. Step 2: Select the subproblem and assume that the function already works on the problem. Step 3: Get the answer to the subproblem and use it to resolve the main issue. Step 4: The 90% of the problem defined is solved.


When a function call by itself?

Recursion.


What is the difference between left recursion and right recursion in a grammar?

Recursion is what it's called when a function calls itself. When a function calls itself immediately before returning, it's called tail recursion. Tail recursion can be more efficiently written as iteration. In fact a good compiler will recognize tail recursion and compile it as iteration. There is no such thing as left or right recursion in C programming.


Bring out the difference between recursion and iteration?

Recursion is repeatedly calling the function....---- whereas Iteration is nothing but just looping until condition doesn't satisfy.....


What is mine by recursion?

Recursion means that, calling from a function to same function.. it is very important in programing language if you feel tough then you can't get the answers show some interest then you should get very good knowledge on it then you become a good programer


Explain the term Recursion with example?

Recursion is when a function (procedure) calls itself. Example: int Fib (int n) { if ((n==1)(n==0))return 1; else return Fib(n-1) + Fib(n-2); }


What is a Flow chart for finding factorial of a given number using recursion function?

no answer....pls post


What is funcation?

Read the part in your programming manual/text book about recursion. The short answer while easy does not tell you anything about the power or dangers of recursion. It is the power and dangers of recursion that is important because once understood you can use recursion to good effect without running out of stack space.


What are the merits and demerits of recursion?

Ans: Merits of recursion are: Mathematical functions, such as Fibonacci series generation can be easily implemented using recursion as compared to iteration technique. Demerits of recursion are: Many programming languages do not support recursion; hence, recursive mathematical function is implemented using iterative methods. Even though mathematical functions can be easily implemented using recursion, it is always at the cost of execution time and memory space. The recursive programs take considerably more storage and take more time during processing.


What are demerits of recursion?

Demerits of recursion are: Many programming languages do not support recursion; hence, recursive mathematical function is implemented using iterative methods. Even though mathematical functions can be easily implemented using recursion, it is always at the cost of execution time and memory space. The recursive programs take considerably more storage and take more time during processing.


Can a recursion have a shorter time to execute than an iteration?

Generally no. Every time a function is called, the current CPU register state must be saved, so the current function's local arguments and the return address, as well as the arguments to the called function, need to be pushed onto the call stack before a jump is made to that function. When entered, its arguments are popped off the stack in reverse order and the interesting part of the function is executed. when the function returns, the return address is popped and execution jumps to that address. For small functions it can actually take more time to call and return from the function than it does to execute the function itself. AMD claims any function with less than 50 instructions should be inline expanded. Unfortunately recursive functions where the depth of recursion is variable cannot be inline expanded, or can only be partially expanded up to a predetermined maximum depth. Most texts on optimization suggest trading iteration for recursion. Highly optimized versions of most popular recursive sorts (merge, quick), have had their recursions replaced with local stacks that are more efficient than the call stack. If you have found code that executes faster using recursion, keep in mind that compilers are very evolved at this point and may very well have recognized the recursion and replaced it with an iterative sequence, particularly when the recursion is a tail recursion (where the recursion becomes redundant because there is no need to save the state of the current instance before returning to the previous instance), or some 'built in' that may be superior to your version. It's even possible your processor recognizes the pattern and is able to accelerate the repeated calls.