Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python 3, using lists please post screenshots class BoundedQueue: # Constructor, which creates a new empty queue: def __init__(self, capacity): assert isinstance(capacity, int), ('Error:

image text in transcribedIn python 3, using lists

please post screenshots

class BoundedQueue: # Constructor, which creates a new empty queue: def __init__(self, capacity): assert isinstance(capacity, int), ('Error: Type error: %s' % (type(capacity))) assert capacity >= 0, ('Error: Illegal capacity: %d' % (capacity)) self.__items = [] self.__capacity = capacity def enqueue(self, item): if len(self.__items) >= self.__capacity: raise Exception('Error: Queue is full') self.__items.append(item) # Removes and returns the front-most item in the queue. # Returns nothing if the queue is empty. def dequeue(self): if len(self.__items)

# Returns a string representation of the object # bounded queue: def __repr__(self): return str(self) + " Max=" + str(self.__capacity)

class CircularQueue: # Constructor, which creates a new empty queue: def __init__(self, capacity): if type(capacity) != int or capacity

Q1) Implement the Bounded Queue and Circular Queue ADT as seen in class The python implementations of these data structures are given in the lecture slides. Make sure you raise exceptions when peek(/dequeue() if the queue is empty enqueue() if the queue is full After completing the implantations, compare the runtime of dequeue() methods in Bounded Queue and Circular Queue. In bounded queue, once you dequeue an item, the remaining items in the list will be shifted left. Therefore, the dequeue in Bounded Queue is O(n). However, in circular queue, you just change the start pointer (index) when dequeue. Therefore, the dequeue in a Circular Queue is O(1). Thus, in theory, dequeue in Circular Queue should be much faster than the dequeue in a Bounded Queue. Write your code to test whether this hypothesis is true or false Here are the steps for this experiment: 1. Create a Circular Queue object and enqueue 100000 items in it. 2. Create a Bounded Queue object and enqueue 100000 items in it 3. Compute the time required to dequeue all items from the Circular Queue 4. Compute the time required to dequeue all items from the Bounded Queue Here is how to use the time module import time start- time.time) # The statement (s) that you want to test end-time.time) time interval-end - start 5. Finally, print the dequeue) runtime for each queue as shown in the sample output. Please note: We need to enqueue many items in the Circular and Bounded Queues in order to get a reasonable run time for both queues. Moreover, keep in mind that time can be different from computer to another and the time module gives you time in second. Here is a sample output For Bounded Queue, the total runtime of dequeing 10000e is: 1.8420054912567139 Seconds For Circular Queue, the total runtime of dequeing 10000e is: 0.04388284683227539 Seconds

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

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

ISBN: B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

What do you mean by dual mode operation?

Answered: 1 week ago

Question

Explain the difference between `==` and `===` in JavaScript.

Answered: 1 week ago