i can understand simple recursion, such as:
def count(n): if n <= 0: return else: print n count(n-1) count(3) however, when faced more complicated code, such as, implementation of koch snowflake:
def koch(order, size): if order == 0: t.forward(size) else: koch(order-1, size/3) t.left(60) koch(order-1, size/3) t.right(120) koch(order-1, size/3) t.left(60) koch(order-1, size/3) koch(1, 100) i confused. not understand how follow these multiple recursive function calls.
i don't think it's easy visualize execution path in detail in head. drawing tree, nodes representing individual recursive calls, way visualize on paper. if each node bubble, can put information variable states, etc., in them. in situation there multiple recursive calls, each node have multiple trees under it, representing timeline.
Comments
Post a Comment