Re: Java Questions Again: What's So Great About Recursion

  • From: "black ares" <matematicianu2003@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 8 Apr 2011 10:40:25 +0300

Hello,
A metod is not good only because it solve a class of problems,
but even for introducing an easier way to do things.
By easier I mean a lot of things, starting from the written code up to more 
elegant algorithms.

How ever, a loop is able to go forward until a condition is no longer valid, 
but there it stops.
Recursion ofer you the ability to go back if a condition is no longer valid, 
return until that condition becomes valid again and from there to continue, 
with another set of data, to go forward until the condition becomes again 
invalid.

Also the recursion allows you to go forward until a condition is no longer 
valid like loops, but also allows you to do some things on the way back to the 
start point.

For example, think to the following problem:

I have a City and in that city there are paths to go from a point to another.
How can I get the set of points available starting from a starting-point.
Try to do a recursive algorithm and after this try do do an iterative one and 
see which is easier to implement, to code and to write.

The recursion is good when you don't know from the begining how many levels you 
must go or when the number of levels change dinamically.

how ever, you must learn about it because, some time, you will get to a point 
where iterative solution does not exists and you will remember to use recursion.
For example, in my career, I had to implement sort of "counters".
But the number of the digit of the counter was a configurable parameter.
So from the begining I didn't know how many digits that counter will have.
To do a counter, the simple variant when you know the number of the digits is 
to do as many fors as number of the digits.
But when you don't know the number of the digits from the begining?



  ----- Original Message ----- 
  From: Homme, James 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Thursday, April 07, 2011 7:51 PM
  Subject: Java Questions Again: What's So Great About Recursion


  Hi,

  It's probably my ignorance coming out to bite me again, but I just was 
reading about recursion in my Java book and thinking that it isn't all that 
useful because you can do the same stuff with a loop. Maybe the book examples 
are so simple that I just don't see it's usefulness. They were even saying that 
recursion eats up more memory than loops do, so I'm wondering why I learned it 
in the first place, other than to know how it works and that it exists. 

   

  Please help.

   

  Thanks.

   

  Jim

   

  Jim Homme,

  Usability Services,

  Phone: 412-544-1810. Skype: jim.homme

  Highmark recipients,  Read my accessibility blog. Discuss accessibility here. 
Accessibility Wiki: Breaking news and accessibility advice

   



------------------------------------------------------------------------------
  This e-mail and any attachments to it are confidential and are intended 
solely for use of the individual or entity to whom they are addressed. If you 
have received this e-mail in error, please notify the sender immediately and 
then delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.

Other related posts: