Question: CODING IN PYTHON COMPLETE THE GIVEN CODE Give an algorithm to find all nodes less than some value, X, in a binary heap. Your algorithm

CODING IN PYTHON

COMPLETE THE GIVEN CODE

CODING IN PYTHON COMPLETE THE GIVEN CODE Give an algorithm to findall nodes less than some value, X, in a binary heap. Your

Give an algorithm to find all nodes less than some value, X, in a binary heap. Your algorithm should run in O(K), where K is the number of nodes output. Implement your algorithm in the pr5.py file. 1 #We will use a binary heap class that is given to you. This class contains the necessary functions for a binary heap to function 2 from binHeap import BinHeap 3 4 #This will create an empty binary heap 5 bh - BinHeap() 6 #Now let's build our binary heap with the following elements 7 bh.buildHeap([9,5,6,2,3]) #Let's test deleting the minimum element. 10 print (bh.delMin) 11 print(bh.delMin)) 12 print (bh.delMin()) 13 print (bh.delMin)) 14 print (bh.delMin) 15 16 17 #Now let's add the elements back 18 bh.buildHeap([9,5,6,2,31) 19 20 #TODO : Write a function that will return all elements smaller than a threshold t from the binary heap bh 21 def getSmallerThan (binaryHeap, t): listofElements-list() #implement your function here 2 4 25 2 6 27 #Testing your function 28 print(getSmallerThan (bh,5)) return listofElemen

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