Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python please The purpose of this laboratory is for you to demonstrate understanding of Binary Search Trees. The BinarySearchTree class definition is given as follows:

image text in transcribedimage text in transcribedpython please

The purpose of this laboratory is for you to demonstrate understanding of Binary Search Trees. The BinarySearchTree class definition is given as follows: class BinarySearchTree: def __init__(self, data, left=None, right=None): self.__data = data self._left = left self.__right = right def get_left(self): return self._left def get_right(self): return self._right def set_left(self, left): self. __left = left def set_right(self, right): self._right = right def set_data(self, data): self.__data = data def get_data(self): return self._data The print_tree() function is given as follows: def print_tree (tree, level): print(''* (level*4) + str(tree.get_data())) if tree.get_left() != None: print('(L)', end = '') print_tree(tree.get_left(), level + 1) if tree.get_right() != None: print('(R)', end = "") print_tree(tree.get_right(), level + 1) You will use the following binary search trees: 1 . tree1 = 27 14 35 10 19 31 42 . tree 2 = 10 14 . tree3 = 13 D P ( F K U tree4 = A E G NR Y An implementation of the BinarySearchTree ADT is shown in the answer box for this question. Extend the BinarySearch Tree class by adding the method search(self, value) which takes a value as a parameter. This method should search for the parameter value in the binary search tree. If the value is found, the method should return the found object, and None otherwise. Note: submit the entire class definition. For example: Test Result 9 None node = treel. search (9) if not isinstance(node, BinarySearchTree) : print('The search method must return an object of BinarySearchTree') print(node.get_data()) print(tree1. search(0)) tree = BinarySearchTree (15) print(tree. search(99)) print(tree. search(299)) None None Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) Reset answer 1 class BinarySearchTree: def _init__(self, data, left=None, right=None): self.__data data self.-_left = left self.__right = right def get_left(self): return self.__left def get_right(self): return self.__right def set_left(self, left): self. left = 'left def set_right(self, right): self.__right = right def set_data(self, data): self.__data data def get_data(self): return self.__data WISS WRFBorovorurawne

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago