Recursive Algorithm getting stuck (because of Python Limits?)

Marc Floessel gildemere at hotmail.com
Mon Apr 28 10:16:09 EDT 2003


I am trying to execute a simple Tree Building algorithm.

"
nTreeBreadth = 7
nTreeDepth = 7


class Node:
    def __init__(self):
        self.childNodes = []
    
# Create a recursive Sub-Tree with <nChildren> until we reach the
final <nDepth>
def CreateSubTree (oRoot, nChildren, nDepth):
    for i in range(nChildren):
        oNewNode = Node()
        oRoot.childNodes.append(oNewNode)
        if (nDepth > 1):
            CreateSubTree (oNewNode, nChildren, (nDepth-1))

oRoot = Node() # Create the Root Node
CreateSubTree (oRoot, nTreeBreadth, nTreeDepth-1)
"

This works. However increasing the Depth or Breadth to 8 seems to
break Python. Python rises to about 100 MB memory consumption (as
indicated by the Windows Task Manager) and then seems to drop and rise
randomly. The algorithm never finishes. Am I breaking the stack? I
tried executing the code (with a Depth of 8) in Stackless Python, but
it didn't finish either, so it doesn't appear to be the stack. Are
there any other hard limits?




More information about the Python-list mailing list