answersLogoWhite

0

Recursive algorithms work in an opposite direction as compared to normal algorithms or loops.

First the recursion occurs then it back tracks, both of these steps combine to give what a loop does in one single step. But values may change in both the steps, thus complicating the algorithm.

For eg:

int fact(int n) for(i=1;i<=3;i++)

{ {

if(n!=1) fact=fact*i;

return(n*(n-1)); }

else return fact;

return 1;

}

Here suppose you take n as 3, then first n decreases to 1 after that for each value returned, it multiplies with the previous returned value. Hence giving the answer 6. But in case of for loop it works linearly...

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

What is analysis of recursive program?

1) Recursive algorithms 2) Basic Principle 3) Analysis


Difference between function and recursive variable?

A function can map for sets with infinite elements. Recursive variables, being 'algorithms of algorithms', are restricted to finite elements.


The efficiency of using recursive function rather than using ordinary function?

For some algorithms recursive functions are faster, and there are some problems that can only be solved through recursive means as iterative approaches are computationally infeasible.


Which one is advantageous recrsion or iteration?

Depends... I teach algorithms and advice my students to choose whichever they find simpler to implement. Sometimes recursion is more intuitive than iteration and viceversa. All that is recursive can be done iterative and the other way around. The only problem you would have with recursion is having a stack overflow (if you call the recursive method too many times).


What is the most efficient way to implement a factorial algorithm in a programming language?

The most efficient way to implement a factorial algorithm in a programming language is to use an iterative approach rather than a recursive one. This involves using a loop to multiply the numbers from 1 to the given input number to calculate the factorial. This method is more memory-efficient and faster than using recursion.


What has the author Anatolii Ivanovich Mal'tsev written?

Anatolii Ivanovich Mal'tsev has written: 'Algorithms and recursive functions'


What has the author Simon M Kaplan written?

Simon M. Kaplan has written: 'Specification and verification of context conditions for programming languages' -- subject(s): Programming languages (Electronic computers), Semantics 'Verification of recursive programs' -- subject(s): Automatic theorem proving, Recursive programming


How can you solve the tower of hanoi?

1. Write mathematical analysis for recursive algorithms. Solve Tower of Hanoi Problem and analyze it.


Is it necessary to have a base case in all recursive algorithms?

Yes, it is necessary to have a base case in all recursive algorithms. The base case serves as a termination condition that prevents infinite recursion, allowing the algorithm to eventually return a result. Without a base case, the recursive calls would continue indefinitely, leading to a stack overflow error. Thus, the base case is essential for ensuring that the recursion can conclude and produce a meaningful output.


Can heap implement recursion?

Heap is a data-structure, it cannot implement anything. On the other hand, it is true that: 1. Recursive routines might use heap. 2. You can use dynamic memory allocation (heap), to implement a stack; and use the stack to implement recursion.


What has the author G McCusker written?

G. McCusker has written: 'Games and full abstraction for a functional metalanguage with recursive types' -- subject(s): Recursive functions, Functional programming languages, Game theory


What has the author Richard H Day written?

Richard H. Day has written: 'Recursive programming and production response'