Question: 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

python3 import numpy as np Define class Queue that implements the ADT

(Abstract Data Type) Queue using a circular array. . You must use

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!