Which path should I follow Iterative or recursive? | SoloLearn: Learn to code for FREE!

+7

Which path should I follow Iterative or recursive?

Hey guys!! Should I write a iterative version of program or should I write a recursive version of program.

c

5/28/2020 10:26:34 AM

SHIVANI SINGH

9 Answers

New Answer

+8

OK I got it!! Every recursive program can be modeled into an iterative program but recursive programs are more elegant and requires relatively less lines of code. And also recursive programs require more space(stacks) than iterative programs. So that's depend Bcz if I want my code to be more elegant and easy to understand then we should follow recursive path.And if I want to my code more efficient in case of space then we should follow the iterative path.

+3

Shivani Singh Rathore The fact is that recursion is rarely the most efficient approach to solving a problem, and iteration is almost always more efficient. This is because there is usually more overhead associated with making recursive calls due to the fact that the call stack is so heavily used during recursion 👇👇👇👇👇 https://stackoverflow.com/questions/15346774/are-recursive-methods-always-better-than-iterative-methods-in-java

+1

Iteration and recursion are key Computer Science techniques used in creating algorithms and developing software. In simple terms, an iterative function is one that loops to repeat some part of the code, and a recursive function is one that calls itself again to repeat the code.

+1

I think this much information is ok. But never stop until you are perfect so check all about it from here -- https://www.advanced-ict.info/programming/recursion.html Rock the code🤟🤟

+1

I think both has its own applications program by program because sometimes it is more efficient to write a program in iterative method and vice versa. These are mainly depend upon time and space complexity of a program.Moreover all recursive programs could be written in iterative way but vice versa is not true.

+1

Recursive but for simple codes you can use iterative....

+1

well its something related to Algorithms. its the matter of time complexity, usually recursive programs have BIG time complexities cause they calculate subproblems over and over so depend on the program each can be faster for different problems.

+1

If you are going to do Embedded programming then you should never use recursive functions. It will cause stack overflow

0