answersLogoWhite

0

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.

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

What are the advantages of the recursion in c plus plus?

Any problem that can be solved by dividing the problem into smaller problems of the same type is a good candidate for recursion. However, there are actually very few applications that cannot be resolved more efficiently with an iterative loop. It therefore pays to know when recursion is unavoidable and when it is optional. The main benefit to recursion is that each instance of the function maintains its own set of non-static local variables completely independently of all other instances. But if these variables are of no use to the function when a recursive call returns, then an iterative implementation would be more efficient. Function calls are expensive in terms of memory consumption and performance, so the fewer we make, the better. A classic example of recursive application is the quicksort algorithm. In simple terms, quicksort is a function that accepts a subset of data. The data is usually stored in an array and the function accepts the left and right index of the subset to be sorted. Initially this will be lower and upper bounds of the entire array, but if the indices indicate a subset with fewer than 2 items, the function immediately exits. This effectively defines the return path from the recursions. Assuming there are 2 or more items, the function selects one of the items (the pivot) and then sorts the array such that items less than the pivot are placed to its left, and items greater or equal to its right. This moves the pivot into its final position, but the items on either side may still be unsorted. Thus the function calls itself twice, once for each of these subsets, which gradually reduces the problem down into smaller and smaller subsets until a subset has fewer than 2 items, at which point the recursion unwinds to the previous instance. Recursion is required because when the first recursive call returns, the subset to the left of the pivot is guaranteed to be sorted, but the subset to the right is not. This means we must maintain local variables in order to determine the lower and upper bounds of that subset. Although quicksort is an elegant application of recursion, there is still room for improvement. Firstly, it is better to make a recursive call upon the smaller of the two subsets. The smaller the subset, the fewer recursions that will be incurred sorting it. Secondly, since the second recursion is also the last statement in the function, there is no need to maintain the local variables when it returns. Thus the second recursion can be implemented as a tail call. This effectively means we modify the existing local variables to suit and then recall the same instance (with a goto). This reduces the depth of recursion by one function call per recursion which will quickly add up to a significant boost in efficiency.


What is difference between filtering and sieving?

hi everybody, if u wanna know the answer u will find it right here basically filtering separates tiny solubles and sieving is the opposite. Thanx


What is the difference between dendritic and trellis drainage?

Dendritic drainage patterns are tree like while trellis drainage patterns are formed when tributaries meet at right angles so they look like squares or rectangles.


What does engine code P046 means?

P046 (E046) .................................. Right to Left Bank Fueling Difference Check for a leaky injector


Write a program to remove left recursion?

#include"stdio.h"#include"conio.h"int fabo(int);void main(){int result=0,a=1,b=1,c;printf("enter upto which you want to generate the series");scanf("%d",&c);result=fabo(c);printf("%d\n%d\n",a,b);printf("the fabonnaci series is %d\n",result);getch();}int fabo(int n){if (n==1);return 1;else if(n==2);return 1;elsereturn fabo(n-1)+fabo(n-2);}

Related Questions

What is the difference between wright And write?

Type your answer here... WHAT IS DIFFERENCE BETWEEN WRIGHT AND RIGHT


What is the exact meaning of recurrsion?

Recursion (n). See "Recursion (n)." Seriously, recursion is doing something over and over a certain number of times, such as a loop in a computer program, or "lather, rinse, repeat." Two wrongs don't make a right, but three rights will get you back on the freeway. ■


Is this grammar right?

If you mean: Is the sentence "Is this grammar right?" grammatically correct (or right), then yes, it is.


Is there a difference between right cylinder and cylinder?

yes ones on the right


Difference between fundamental rights and fundamental duty?

difference between duty and right difference between duty and right my answer is: duty is an obligation while right is freedom to exercise a duty like voting. there is a "moral" duty to vote but the right to ignore that duty [ obligation ] to your peril i might add


Is the correct grammar a cheque of or a cheque for?

cheque of is a right grammar!


What is the difference between a complete angle and right angle?

The difference is 270 degrees.


Is this sentence grammar right?

No. It should be "Is the grammar right in this sentence?"


What is a sentence with the word difference?

There is a type of puzzle named spot the difference


What the difference between a personal right and a political right?

The political intent and impact


What is the difference between the eastern right and the Western right Lent?

I wish I knew


What is the difference between a personal right and a political right?

The political intent and impact