def height(t):
''' (Tree) -> int
Return 1 + the number of nodes in longest path in Tree t.
>>> tree = Tree(23)
>>> height(Tree)
1
>>> tree = descendents_from_list(Tree(11), [2, 3, 4, 5, 6], 3)
>>> height(tree)
3
'''
num = 1
for i in t.children:
if i.children:
num += height(i)
return num
For the above function with t.value and t.children, I need to figure out how to find the height WITHOUT using a list. Like I need to find a way to recursively go further down the tree without keeping track of parent trees.
I've tried it, but I can't figure it out. Can someone please help me out with this??