Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this task, you will compare the runtimes of the dequeue ( ) methods in the Bounded Queue and the Circular Queue. In the Bounded
In this task, you will compare the runtimes of the dequeue methods in the Bounded Queue and 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 ie to fill in the hole created by removing that first item For a Bounded Queue containing items, what is the bigO 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 items, what is the bigO time efficiency
of the dequeue?
Considering your answers to the above two questions, which queue's dequeue do you predict will run faster?
Download and save labefficiency.py and terminalplot.pySave in the same folder as your queue.py from Exercise In this file, both our Bounded and Circular Queues have been imported from queues.py This file also contains function definitions: have already been completed for you enqueueexperiment, averagedequeueexperiment, and main Read through
the comments of those functions to understand what they are doing.
Complete the function dequeueexperimentqueue so that it removes the first item in the
queue, and continues to do so until that queue is empty. Note that the queue is passed in as an
input to the function so you do NOT have to create it or fill it with data in this function. Use a
function from either the time or timeit modules to measure how long it takes to dequeue all of the
items in the queue, and return that time measurement.
Hint: there is an example of how to use time.time at the bottom of
labefficiency.py The time module returns times in seconds.
import time
start time.time
# The statements that you want to test
end time.time
timeinterval end start
Run labefficiency. This may take some time to run. This will run a number of experiments,
measuring the time it takes to dequeue all items from Bounded and Circular Queues of increasing
capacities. These times will be printed in a table for you to view. The data should also be plotted
for you, with time on the axis, and on the axis where is the number of dequeues made If
a plot is not displayed ie if you see a message that says "Not able to print graph.
Continuing..." plot the data from the table using a spreadsheet program. You can run more
experiments with larger queue capacities to get more values for your graph, but keep in mind that
doing so will increase the runtime of the overall program. Which has a more efficient dequeue
method: the Bounded Queue, or the Circular Queue?
terminalplot.py
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started