Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following is the BinaryTree class. You can assume this class is available and you should not include it in your answer. class BinaryTree: def

The following is the BinaryTree class. You can assume this class is available and you should not include it in your answer.

class BinaryTree: def __init__(self, data): self.data = data self.left = None self.right = None def insert_left(self, new_data): if self.left == None: self.left = BinaryTree(new_data) else: t = BinaryTree(new_data) t.left = self.left self.left = t def insert_right(self, new_data): if self.right == None: self.right = BinaryTree(new_data) else: t = BinaryTree(new_data) t.right = self.right self.right = t def set_left(self, tree): self.left = tree def set_right(self, tree): self.right = tree def get_left(self): return self.left def get_right(self): return self.right def set_data(self, data): self.data = data def get_data(self): return self.data

Define the get_total_smaller(b_tree, maximum) function which takes two parameters: A BinaryTree object and an integer, maximum. The function returns the total of all of the data values in the tree which are smaller than the maximum parameter. For example, consider the following binary search tree:

image text in transcribed

For example, given the tree above, the following code

my_tree = ... #creates the tree above print("1.", get_total_smaller(my_tree, 10)) print("2.", get_total_smaller(my_tree, 8)) print("3.", get_total_smaller(my_tree, 4)) print("4.", get_total_smaller(my_tree, 20))

The following code:

1. 13 2. 5 3. 0 4. 36 
The function header is: 
def get_total_smaller(bs_tree, maximum):

For example:

Test Result
my_tree = create_a_tree1() print("1.", get_total_smaller(my_tree, 10)) print("2.", get_total_smaller(my_tree, 8)) 
1. 13 2. 5 
my_tree = create_a_tree1() print("3.", get_total_smaller(my_tree, 5)) print("4.", get_total_smaller(my_tree, 20))
3. 0 4. 36 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions