ther two Please put all answers in the space provided. Question 7 [Binary Search Tree Implementation:...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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] 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]
Expert Answer:
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Posted Date:
Students also viewed these programming questions
-
Figure P2.36 shows the acceleration as a function of time for an object. (a) If the object starts from rest at t - 0, what is the velocity of the object as a function of time? (b) If the object...
-
In Exercises 514, an objective function and a system of linear inequalities representing constraints are given. a. Graph the system of inequalities representing the constraints. b. Find the value of...
-
Examples using activity-based costing generally show that traditional costing systems ________ high-volume, less complex products and ________ low-volume, complex products undercost; overcost...
-
In the table for Problem 8-14, if 2020 is the base year, what is the price index for 2019? (Round decimal fractions to the nearest tenth)
-
German brothels recently began offering a monthly subscription service for multiple purchasers. If you wished to reduce the incidence of prostitution, would you consider this pricing plan to be a...
-
Flow of a viscous fluid over a flat plate surface results in the development of a region of reduced velocity adjacent to the wetted surface as depicted in Fig. P5.25. This region of reduced flow is...
-
As Baldwin Company controller, you are responsible for informing the board of directors about its financial activities. At the board meeting, you present the following information. After the meeting,...
-
In my management accounting book, there are 5 steps to budgeting. I just want to connect in real life work scenarios as there are not many examples in the book and just one big case in a big...
-
What are some of the arguments for and against using the term industrial relations to describe union management relationships?
-
Treasury Bond Quote by using 32nd to determine the bid and asked price. The bond maturity 2025, July 30, Bid price : 130.35 Asked Price : 130. 30 What is the bid and asked quoting price and provide...
-
Given the following information on two fixed-rate fully amortized mortgages and consider the refinancing decision of the old loan at the end of Year 10. Old Loan New Loan Loan Amount 4,000,000 ...
-
Suppose a pendulum is Z meters long. The time, t, in seconds that it takes to swing back and forth once is given by t = 2.01 L. If a pendulum is 9.61 meters long, how long does it take to swing back...
-
Rewrite as a logarithmic equation. 1 0 ^ y = 3
-
Initial margin requirement is 50%. A customer is buying 100 shares on margin at $50 per share. What is minimum cash required in account to complete transaction?
-
Write the equation of the line that passes through the points (-9, -4) and (-5,-1). Put your answer in fully simplified point-slope form, unless it is a vertical or horizontal line.
-
Increasing the price of your product will increase your firm's revenue per unit, but reduce the number of units you can sell. On the other hand, reducing the price of your product will reduce revenue...
-
DC has unused FTC carryover from 2017 in the separate category for GC income as the result of income generated by a foreign branch. The income was foreign source general category income. In 2018 the...
-
Using the disk drive specifications given in Exercise 8.8, calculate the time required to read a 10MB file assuming Data from in Exercise 8.8 A typical disk drive from 2004 has the following...
-
Consider the design for a spelling checker program meant to run on a home computer. The spelling checker should be able to handle quickly a document of less than twenty pages. Assume that the...
-
Write a recursive function named printRange that, given the pointer to the root to a BST, a low key value, and a high key value, prints in sorted order all records whose key values fall between the...
-
1. Describe the bases of power held by Dr. Jamie Thompson. Describe the bases of power held by Dr. Elizabeth Clarke. 2. What activities and people have contributed to Jaime Thompsons power? What...
-
What is the current in the wire in Figure Q22.1? 1.0 VR + 1.0-1.0V + FIGURE Q22.1
-
Electroplating uses electrolysis to coat one metal with another. In a copper-plating bath, copper ions with a charge of +2e move through the electrolyte from the copper anode to the cathode the metal...
Study smarter with the SolutionInn App