Question: python question The initialisation function and the __str__() function for a PriorityQueue class are shown below. This class uses a min binary heap (i.e. the

python question

The initialisation function and the __str__() function for a PriorityQueue class are shown below. This class uses a min binary heap (i.e. the smallest value at the root), stored in a Python list, to represent the priority queue. class PriorityQueue:

def __init__(self):

self.bin_heap = [0]

self.current_size = 0

def __str__(self):

return str(self.current_size) + " : " + str(self.bin_heap[1:])

A PriorityQueue object, pq, has been created and has had the following six values inserted, in this order: 30, 20, 15, 12, 13, 18 The code for performing these insertions is as follows:

pq = PriorityQueue()

pq.insert(30)

pq.insert(20)

pq.insert(15)

pq.insert(12)

pq.insert(13)

pq.insert(18)

What is the output after each of the following statement are executed, in the order shown below (note that in each question, the first part of the output string - the size of the priority queue - is already shown)?

a) printing the current priority queue print(pq) 6 :

b) then, continuing after (a), inserting the value 17 and printing the resulting priority queue: pq.insert(17) print(pq) 7 :

c) finally, continuing after (b), deleting the minimum value from the priority queue, and then printing the remaining values: pq.del_min() print(pq) 6 :

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!