Question: all python BoundedQueue class: CircularQueue class: Exercise 2: In this task, you will compare the runtime of the dequeue() method in the Bounded Queue with

all python
BoundedQueue class:


CircularQueue class:



Exercise 2: In this task, you will compare the runtime of the dequeue() method in the Bounded Queue with the dequeue() method of the Circular Queue. In the Bounded Queue, the dequeue method removes the item at the front of the queue, and then shifts the remaining items in the list to the left (i.e. to fill in the hole created by removing that first item). For a Bounded Queue containing n items, what is the big-O time efficiency of the dequeue? In the Circular Queue, you just shift the head index when you dequeue an item no shifting of the actual data elements is required. For a Circular Queue containing n items, what is the big-O time efficiency of the dequeue? Considering your answers to the above two questions, which queue's dequeue do you predict will run faster? 1. Create a new file, lab6.py. In this file, import both the Bounded and Circular Queues from queues.py (downloaded in Exercise 1 above). 2. In a main function, create a Bounded Queue object and enqueue 50,000 items into it. For example, you can enqueue the integers 1 to 50,000. 3. In the same main function, create a Circular Queue object and enqueue the same 50,000 items into it. 4. Compute the time required to dequeue all items from the Bounded Queue, using the time module. The time module returns times in seconds. Hint on using the time module: import time start time.time () # The statement(s) that you want to test end time.time () time interval end start 5. Similarly, compute the time required to dequeue all items from the Circular Queue. 6. Print the dequeue() runtime for each queue to the screen, as shown in the sample output below. Sample Output For Bounded Queue, the total runtime of dequeuing 50,000 items is: 0.1325376033782959 seconds. For Circular Queue, the total runtime of dequeuing 50,000 items is: 0.042598724365234375 seconds. class BoundedQueue: def __init__(self, capacity): Constructor, which creates a new empty queue assert isinstance(capacity, int), ('Error: Type error: {}'.format(type(capacity))) assert capacity >= 0, ('Error: Illegal capacity: {}'.format(capacity)) self.__items = [] self.__capacity = capacity def enqueue(self, item): Adds a new item to the back of the queue, and returns nothing if len(self.__items) >= self.__capacity: raise Exception('Error: Queue is full') self.__items.append(item) def dequeue(self): Removes and returns the front-most item in the queue. Returns nothing if the queue is empty. if len(self.__items)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
