Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python3 import numpy as np Define class Queue that implements the ADT (Abstract Data Type) Queue using a circular array. . You must use a

python3

import numpy as np

image text in transcribed

image text in transcribed

Define class Queue that implements the ADT (Abstract Data Type) Queue using a circular array. . You must use a np.array for this question: Somewhere in your constructor you must have a line that looks like self.data-np.array...... . . . You must observe the FIFO convention. When implementing a queue, we have to worry about running time for its basic operations: dequeue and enqueue. Both of them must run in Theta(1) Unfortunately, a regular array does not give you desired complexity. Let me explain why: We will assume that front (index) points to the front of a queue, and rear (index) points to the end of a queue, to the next available location Front always stays at 0, and we move rear when we add elements Issue1: Each time when we delete an element from front, we have shift everything to the left: Theta (n) Rear always stays at 0, and we move front when we remove elements. Issue2: Each time we add an element to rear, we have shift everything to the right: Theta(n) Now we move both front and rear to the right when we add/remove an element. This will ensure that the running time is Theta(1) Issue3: Space. Each time we move front and rear to the right, space on the left is not used anymore (Never can get to indices 0, 1, 2): Solution: Wrap front and rear around when reaching the end of the array

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

For the given a n , calculate S 5 . an = 4n+ 1

Answered: 1 week ago

Question

LO2 Compare three types of individual incentives.

Answered: 1 week ago