Question: a) Write a method that receives the root of a binary tree and a key as input and determines whether or not the key is

a) Write a method that receives the root of a binary tree and a key as input and determines whether or not the key is in the tree. Assume the following class is used to store tree nodes.

class TreeNode: def __init__(self, item, left=None, right=None): self.item = item self.left = left self.right = right

[20 points] Problem 2

a) Write a method that receives the root of a binary search tree and a key as input and determines whether or not the key is in the tree. Assume the following class is used to store tree nodes.

class TreeNode: def __init__(self, item, left=None, right=None): self.item = item self.left = left self.right = right

[20 points] Problem 3

a) Write a method that receives the root of a binary tree as input and returns the sum of all of all the values stored in the tree. Assume the following class is used to store tree nodes.

class TreeNode: def __init__(self, item, left=None, right=None): self.item = item self.left = left self.right = right

a) Write a method that receives the root of a balanced binary search tree and returns the sum of values of all nodes with value between min_valand max_val (inclusive).

Examples: 7 / \ 3 10 / \ / \ -1 5 9 12 min_val = 2, max_val = 10  3 + 5 + 7 + 9 + 10 = 34 min_val = 3, max_val = 8  3 + 5 + 7 = 15 min_val = 10, max_val = 20  10 + 12 = 22 min_val = 20, max_val = 30  0

Assume the following class is used to store tree nodes.

class TreeNode: def __init__(self, item, left=None, right=None): self.item = item self.left = left self.right = right

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!