Question: 1 . Consider the binary tree class presented in the lectures. class BinaryTree: class _ Node: def _ _ init _ _ ( self ,

1. Consider the binary tree class presented in the lectures. class BinaryTree: class _Node: def __init__(self,value,left=None,right=None): self._value=value self._left=left self._right=right def __init__(self): self._root=None def add_root(self,val): self._root=self._Node(val) def isEmpty(self): return self._root==None def attach(self,t1, t2): if t1!=None: self._root._left=t1._root if t2!=None: self._root._right=t2._root a) Draw the binary tree b constructed as a result of running the following main function. def main(): b=BinaryTree() b.add_root(5) b1=BinaryTree() b1.add_root(10) b2=BinaryTree() b2.add_root(20) b.attach(b1,b2) b3=BinaryTree() b3.add_root(50) b2.attach(b3,None) b) Implement the recursive method search as per the documentation below. What is the time, extra space, and total space cost of your method? Do not count the stack frame space. def sea
rch(self,val): Search for value val in binary tree Pre: object is a BinaryTree Post: object is not modified Return: True if val exists in object, False otherwise c) Implement the recursive helper method rec_find_smallest as per the documentation. #return the smallest value in a BinaryTree #pre: object is a BinaryTree instance whose elements are numeric #post: object has not been modified #return value: smallest value in object's elements or None if tree is empty def find_smallest(self): least=self.rec_find_smallest(self._root) print("smallest value in tree is:", least)

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 Programming Questions!