Self function
Arnaud Delobelle
arnodel at googlemail.com
Mon May 4 17:31:29 EDT 2009
bearophileHUGS at lycos.com writes:
> Aahz:
>> When have you ever had a binary tree a thousand levels deep?
>
> Yesterday.
>
>
>>Consider how big 2**1000 is...<
>
> You are thinking just about complete binary trees.
> But consider that a topology like a single linked list (every node has
> 1 child, and they are chained) is a true binary tree still.
In that case the following would not grow the stack, given tail-call
optimization:
def visit(node):
print 'visiting', node
if node.right is None:
return visit(node.left)
if node.left is not None:
visit(node.left)
return visit(node.right)
--
Arnaud
More information about the Python-list
mailing list