Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

Students also viewed these Databases questions

Question

280,000 Write the number in scientific notation.

Answered: 1 week ago