7 Replies - 7373 Views - Last Post: 22 April 2010 - 11:05 AM Rate Topic: -----

#1 Guest_mountaingoat*


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  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • 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.
Was This Post Helpful? 1
  • +
  • -

#3 singularity  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • 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!!
Was This Post Helpful? 0
  • +
  • -

#4 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • 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

Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10440
  • View blog
  • Posts: 38,668
  • Joined: 27-December 08

Re: recursion vs. iterations

Posted 22 April 2010 - 07:29 AM

You may find gabehabe's tutorial on recursion helpful.
Was This Post Helpful? 0
  • +
  • -

#6 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5795
  • View blog
  • Posts: 12,628
  • Joined: 16-October 07

Re: recursion vs. iterations

Posted 22 April 2010 - 09:14 AM

View Postsingularity, 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.

View Postsingularity, 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.
Was This Post Helpful? 1
  • +
  • -

#7 singularity  Icon User is offline

  • D.I.C Head
  • member icon

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

Re: recursion vs. iterations

Posted 22 April 2010 - 10:10 AM

View Postbaavgai, 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
Was This Post Helpful? 0
  • +
  • -

#8 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • 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 :P

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

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1