Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Does IRR take into account the time value of money?

Answered: 1 week ago