×

# Recursion Vs Looping

 0 I recently heard from my friend that recursion is more efficient than the normal method of iteration. But being a newbie with my limited knowledge i cant believe that. Is that the real fact? Can any one please help me out? This question is marked "community wiki". asked 19 Nov '13, 22:29 3★bipin2 3.1k●25●46●71 accept rate: 8%

 2 @bipin2 Recursion is easy to implement but Looping way (Iterative Approach) is always better to use. There are several reasons 1 is Recursion may cause Stack Overflow problem If you have not implemented it correctly , Forgot to use base cases and termination cases for recursion code. And more , it is very difficult to debug if you have several Recursive calls in you code. So always prefer iterative approach while coding .. for some algorithm iterative is also difficult to implement so we can't say exactly that which is better.. answered 19 Nov '13, 23:01 2.3k●18●30●69 accept rate: 1%
 1 Hi, Iteration is generally more efficient except in the cases of functional programming languages such as LISP. But undoubtedly, most of the problems are easier to solve by recursion, hence recursion techniques are used mostly where efficiency is a secondary issue. answered 19 Nov '13, 23:04 156●3●4 accept rate: 16% thanks bro!!! (19 Nov '13, 23:24) bipin23★
 1 Successive recursive function calls use stack to execute them. In the case of recursion, all the recursive function calls are stored on the stack to return control back to the caller functions poping the recursive calls, therefore making recursion slower than looping, because of these overheads. But there are some algorithms that will be very difficult to implement if not done recursively, like many tree traversal algorithms, graph traversals like dfs, bfs, etc. So, the bottom line is that recursion makes problem solving easy in many complex algorithms, which makes the overheads involved in recursive function call not that important when comparing them with the complexity of the problem itself. answered 19 Nov '13, 23:20 1.8k●4●9●33 accept rate: 14%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×348
×191

question asked: 19 Nov '13, 22:29

question was seen: 1,082 times

last updated: 19 Nov '13, 23:24