Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python 3 Please Using Lists The goal of this lab is to practice writing code using Exceptions, Bounded Queues and Circular Queues. Q1) Implement

In python 3 Please

Using Lists

image text in transcribed

The goal of this lab is to practice writing code using Exceptions, Bounded Queues and Circular Queues. 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(Vdequeue() 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 100000 is: 1.8420054912567139 Seconds For Circular Queue, the total runtime of dequeing 190000 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

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions