Computer Science, asked by Monya3394, 11 months ago

Suppose we add this function foo() to the class Tree that implements search trees. For a name mytree with a value of type Tree, what would mytree.foo() compute?
def foo(self): if self.isempty(): return(0) elif self.isleaf(): return(self.value) else: return(self.value + max(self.left.foo(),self.right.foo())) Options:
The sum of the elements in the tree The maximum sum across all root to leaf paths in the tree The length of the longest root to leaf path in the tree The number of root to leaf paths in the tree.

Answers

Answered by Anonymous
2

foo(self): if self.isempty(): return(0) elif self.isleaf(): return(self.value) else: return(self.value + max(self.left.foo(),self.right.foo()))

.....

The length of the longest root to leaf path in the tree

Similar questions