Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Why MACA is not able resolve the exposed terminal problem?

Answered: 1 week ago

Question

2. How do rituals and routines express organizational values?

Answered: 1 week ago