On 8/31/10 2:11 PM, Ed Leafe wrote:
> On Aug 31, 2010, at 4:27 PM, Paul McNett wrote:
>
>> Well, there could be infinite recursion, which I guess would then be a kind 
>> of
>> infinite loop.
>
>       Yes, which is an example of misusing it. Recursion is for finite, 
> tree-like structures. No algorithm handles infinite loops particular well, 
> for that matter.

I agree, by the way, with using recursion for tree traversal. But you may have 
to put 
checks in your recursive function to catch possible infinite recursion:

obj
   .id = 23
   .parent_id = 21
   .child_ids = (42, 64, 921)

obj
   .id = 42
   .parent_id = 23
   .child_ids = (23, 42)

Obviously, objects in a tree should never be children of themselves, etc., but 
maybe 
something erroneously set it up that way and now we need to deal.

Depending on your needs you may not need to do the check, but just catch your 
programming language's MaximumRecursionDepthExceeded exception and ignore or 
log the 
failing node.

The recursive function may not expect an infinitely recursive case, yet one may 
still 
come to it in the tree data. So in some sense your function will at least have 
to 
deal with the possibility of infinitely-recursive cases.

Obviously, you are aware of all this, but it wouldn't be fair to blame the 
programmer 
of the recursive function of misusing recursion if an infinite-loop-infested 
tree 
were thrown at it one day.

Recursion is awesome. Powerful and simple. But once you add checks in them to 
deal 
with edge-cases, recursive functions can get unwieldy pretty quickly. With 
great 
power comes great responsibility I guess!

Paul

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to