Question: Q2 Implement the Bounded Queue and Circular Queue ADT as seen in class. The python implementations of these data structures are in the lecture slides.
Q2 Implement the Bounded Queue and Circular Queue ADT as seen in class. The python implementations of these data structures are in the lecture slides. Make sure you raise exceptions when-peek/dequeue0 if the queue is empty -enqueue() if the queue is ful 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 ist will be shifted left. This happen because we are using the pop (index) method in the list class to dequeue. Therefore, the dequeue in Bounded Queue is O(n). However in Circular Queue, the front most item is accessed in the list by using the subscription operator and the head is incremented by 1. Therefore, the dequeue in a Circular Queue is O(1) So in theory, dequeue in Circular Queue should be much faster than the dequeue in a Bounded Queue. Write your code to justify whether this hypothesis is true or false Here are the steps for this experiment . 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. Print the dequeue) runtime for each queue Please note: We need to enqueue many items in the Circular and Bounded Queue in order to get a reasonable run time for both queues. Here is the sample ou For Bounded Queue, the total runtime of dequeing 180000 is: 2. 2983570898876953 For Circular Queue, the total runtime of dequeing 100000 is: 0.11895871162414551
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
