Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ther two Please put all answers in the space provided. Question 7 [Binary Search Tree Implementation: 15 marks]: Given the following code for the

imageimageimage

ther two Please put all answers in the space provided. Question 7 [Binary Search Tree Implementation: 15 marks]: Given the following code for the binary search implementation, answer the following questions: a) class BST: class Node: de f def init__(self, data): self.data = data self.left= None self.right None init self.root (self): None def sum_of_all_nodes (self): def depth_of_a_node (self, data): Write a python function that computes the sum of all the nodes in a binary search tree. For example, given tree below, the function would return 25. [8 marks] 2 5 10 def depth_of_a_node (self, data): a) Write a python function that computes the sum of all the nodes in a binary search tree. For example, given tree below, the function would return 25. [8 mark def sum_of_all_nodes (self): 1 2 5 10 DSA 456 Final Examination, Fall-2022-v1 b) Write a python function that find the depth of a given node of a binary search tree. This function takes data as a parameter and returns the depth of the node which contains the data. If the tree does not contain the data in any node, it returns -1. For example, given tree below, the function would return the depth to the node. returns 0 returns depth_of_a_node (7) 1 depth_of_a_node (2) returns 2 depth_of_a_node (1) depth_of_a_node (5) returns 2 depth_of_a_node (10) returns 1 depth_of_a_node (12) returns -1 2 def depth_of_a_node (self, data): (12 does not exist in the tree) 51 Page 13 of 13 10 [7 marks]

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_2

Step: 3

blur-text-image_3

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

Practical Introduction To Data Structures And Algorithm Analysis Java Edition

Authors: Clifford A. Shaffer

1st Edition

0136609112, 978-0136609117

More Books

Students also viewed these Programming questions

Question

=+b) Find an exponential (multiplicative) model for this series.

Answered: 1 week ago