943,614 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 854
  • Java RSS
Dec 9th, 2008
0

Recursion Help

Expand Post »
Alsalamu Alikum,

So, It's my first time to study and work on recursion functions, and it was said in the lecture that it is better than the iterative function because
Quote ...
they are shorter, more elegant, more readable, naturally developing and it's code is easier to understand.It comes with more cost in memory space and execution speed. and however the performance penalty is negligible and it's worth the extra clarity.
and I've asked my TA in the collage and he said that there is no a real programmer who doesn't deal with recursive functions.

But I've worked on some programs made by the prof. , and in each one I found that the iterative function is simpler in the idea, more readable and easier in understanding.
So would anyone tell me more about recursion and it' advantages and disadvantages.

It's my first post , so sorry for talking so much.and thanks in advance
Similar Threads
Reputation Points: 17
Solved Threads: 1
Newbie Poster
eng.M4AH is offline Offline
8 posts
since Dec 2008
Dec 10th, 2008
0

Re: Recursion Help

Don't you think Googling it and finding it out for yourself would be a better and more learning oriented approach ?
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Dec 10th, 2008
0

Re: Recursion Help

I would argue that the majority of code people write is iterative rather than recursive. Because recursion has more overhead in terms of memory and speed, iterative approaches are generally preferred unless the recursive version is much simpler to understand and implement. I'd say the biggest downside to recursion is that function calls require stack space which is usually very limited, and if you try to recurse too deeply you will stack overflow and crash your program (try recursing a million times and you'll see).

I find recursion simpler to understand when it's applied to some sorting algorithms (mergesort, quicksort), and tree structures (you will see these in a data structures course). Of course, when you first start learning recursion, almost every problem will seem easier to understand iteratively. Once you gain more experience with recursion it will become easier to understand.
Reputation Points: 33
Solved Threads: 18
Junior Poster in Training
mahlerfive is offline Offline
77 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Tokenizing null pointer error
Next Thread in Java Forum Timeline: MySQL rollback problem.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC