Page 1 of 1

Reputation:

# recursion vs. iterations

Posted 22 April 2010 - 05:46 AM

how would you explain/ contrast the two?
Is This A Good Question/Topic? 0

## Replies To: recursion vs. iterations

### #2 DaneAU

• Great::Southern::Land

Reputation: 286
• Posts: 1,620
• Joined: 15-May 08

## Re: recursion vs. iterations

Posted 22 April 2010 - 06:20 AM

Use examples, code using iterations and then code using recursion, it will highlight the differences between each methodology.

### #3 singularity

Reputation: 17
• Posts: 184
• Joined: 17-October 08

## Re: recursion vs. iterations

Posted 22 April 2010 - 07:09 AM

Doing Iterarions is sweet and doing recursion is pain, but infact technically it is otherwise!!

### #4 sarmanu

• D.I.C Lover

Reputation: 967
• Posts: 2,362
• Joined: 04-December 09

## Re: recursion vs. iterations

Posted 22 April 2010 - 07:23 AM

Recursive algorithms are often faster than iterative ones. Not always, but generally, they are.
Recursive algorithms are oftern shorter than iterative algorithms. Again, this depends on the complexity of the algorithms, but generally, they are shorter.
Recursivity is confusing for most of the people. When I learned this chapter, I found recursion indeed difficult & confusing. And when I thought that I master recursion, there came double recursion, which of course, confused me pretty much. But now I find it easy (because I worked a lot to understand it), and I often choose recursion instead of iteration.
Overall, try to understand recursion. It is an elegant method to solve complex problems.

This post has been edited by sarmanu: 22 April 2010 - 07:29 AM

### #5 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12297
• Posts: 45,395
• Joined: 27-December 08

## Re: recursion vs. iterations

Posted 22 April 2010 - 07:29 AM

You may find gabehabe's tutorial on recursion helpful.

### #6 baavgai

• Dreaming Coder

Reputation: 7160
• Posts: 14,924
• Joined: 16-October 07

## Re: recursion vs. iterations

Posted 22 April 2010 - 09:14 AM

singularity, on 22 April 2010 - 08:09 AM, said:

Doing Iterarions is sweet and doing recursion is pain

That quite depends on the job. I wouldn't want to search a file system, traverse a tree, or write even the most rudimentary computer AI without it.

singularity, on 22 April 2010 - 08:09 AM, said:

but infact technically it is otherwise!!

No sure what this means. Recursion can involve significant over head, to the point that you may have to take an elegant implementation and make it iterative. This usually entails at least some kind of custom stack and a lot more code.

### #7 singularity

Reputation: 17
• Posts: 184
• Joined: 17-October 08

## Re: recursion vs. iterations

Posted 22 April 2010 - 10:10 AM

baavgai, on 22 April 2010 - 08:14 AM, said:

No sure what this means. Recursion can involve significant over head, to the point that you may have to take an elegant implementation and make it iterative. This usually entails at least some kind of custom stack and a lot more code.

Right baavgai Agreed:

Quote

Q: Then why use recursion??
A: It makes the code beautiful – recursion is a beauty of programming. Sometimes it is much simpler to write the recursive version.

Recursion vs Iteration

### #8 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

## Re: recursion vs. iterations

Posted 22 April 2010 - 11:05 AM

I love recursion, i find it much more amusing than iteration, and i am way better at it than baavgai

This post has been edited by mostyfriedman: 22 April 2010 - 11:12 AM