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


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 4 #This will create an empty binary heap 5 bhBinHeap() 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 (L9,5, 6,2,3]) 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 23 24 25 26 27 #Testing your function 28 print (getSmallerThan (bh,5)) 29 return listOfElements
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
