Self function

Arnaud Delobelle arnodel at
Mon May 4 23:31:29 CEST 2009

bearophileHUGS at 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

def visit(node):
    print 'visiting', node
    if node.right is None:
        return visit(node.left)
    if node.left is not None:
    return visit(node.right)


More information about the Python-list mailing list