Recursive calls and stack

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Feb 14 01:45:30 EST 2007


En Wed, 14 Feb 2007 03:09:37 -0300, jm.suresh at no.spam.gmail.com  
<jm.suresh at gmail.com> escribió:

> Hi,
>  I have a program which literately finds the object that overlapping a
> point. The horizontal and vertical search are called recursively from
> inside each other.
>  Is this way of implementation fill the stack space with the local
> variables inside each call. If this is not good, is there a better way
> to implement? Or python itself will understand that the calls happen
> in the last line, so local variables need not be pushed into the
> stack?

I'm afraid not, the calls will be stacked until some object is found.
Python does not do "tail recursion optimization" (at least, I'm not aware  
of that). But even if it could do that, in this case you have recursive  
calls between two functions, and that's a bit harder.

Going back to your original problem, maybe you can use some known  
algorithms from computational geometry; start with  
http://www.faqs.org/faqs/graphics/algorithms-faq/

-- 
Gabriel Genellina




More information about the Python-list mailing list