subject

Procedure TreeSearch (x, K) i if (x = NIL) or (K = x. key) then 2 return (x); 3 else if (K < x. key) then 4 | TreeSearch (x. left, K); 5 else 6 TreeSearch (x. right, K); 7 endConsider a binary search tree where each tree node v has a field v. sum which stores the sum of all the keys in the subtree rooted at v.

We wish to add an operation SumLE(K) to this binary search tree which returns the sum of all the keys in the tree whose values are less than or equal to K.

(a) Describe an algorithm, SumLE(K), which returns the sum of all the keys in the tree whose values are less than or equal to K. Give pseudo-code for your algorithm. Your algorithm should take the same time as operation TreeSearch from slide 7.12.

(b) Explain why your algorithm is correct, i. e., why it returns the sum of all the keys whose values are less than or equal to K.

(c) Analyze the running time of your algorithm in terms of the size n and height h of the binary search tree.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:50
What is a rush associated with alcohol?
Answers: 1
question
Computers and Technology, 22.06.2019 11:30
Write a function so that the main program below can be replaced by the simpler code that calls function original main program: miles_per_hour = float( minutes_traveled = float( hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('miles: %f' % miles_traveled) sample output with inputs: 70.0 100.0 miles: 116.666667
Answers: 3
question
Computers and Technology, 22.06.2019 20:00
Which type of file can be used to import data into a spreadsheet?
Answers: 1
question
Computers and Technology, 22.06.2019 23:00
Which factor is the most important when choosing a website host? whether customers will make secure transactions the number of email accounts provided the purpose of the website the quality of the host control panel
Answers: 3
You know the right answer?
Procedure TreeSearch (x, K) i if (x = NIL) or (K = x. key) then 2 return (x); 3 else if (K < x. k...
Questions
question
Mathematics, 12.04.2021 22:00
question
English, 12.04.2021 22:00
question
World Languages, 12.04.2021 22:00
question
Mathematics, 12.04.2021 22:00
question
Social Studies, 12.04.2021 22:00
Questions on the website: 13722360