On 20.5.2011 3:38, Pascal J. Bourguignon wrote:
t...@sevak.isi.edu (Thomas A. Russ) writes:

"Pascal J. Bourguignon"<p...@informatimago.com>  writes:

t...@sevak.isi.edu (Thomas A. Russ) writes:

This will only work if there is a backpointer to the parent.

No, you don't need backpointers; some cases have been mentionned in the
other answer, but in general:

     (defun parent (tree node)
        (if (member node (children tree))
           tree
           (some (lambda (child) (parent child node)) (children tree))))

Yes, the question wasn't about time complexity.

  :-p

Um, this is a recursive function.  Inside PARENT, there is another call
to PARENT.

Feel free to derecursive it.


In the general case, to derecursive a function necessitates programming a stack, among other things.............

Antti "Andy" Ylikoski

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to