Question: Question 1 : In Fixed Size Array, maximum number of elements is fixed. It will have the following signature. Class FixedSizeArray: def _ _ init
Question : In Fixed Size Array, maximum number of elements is fixed. It will have the following signature.
Class FixedSizeArray:
def initself N: N is the maximum number of items
self.data NoneN
self.length
self.capacity N
def insertAtself index, value: insert data item value at a particular position index
def removeself index: remove data item from a particular position index
def printArrayself: print the content of the array.
def lengthself: return the number of data items in the list.
Note: You cannot use the insert, append, or pop function in the python list. Only, way you can update the
content of the list is through an assignment operation on a certain index position. For example: self.datai
value or self.datai self.datai Use the following constructor for the Deque class, where n is the
maximum size of the deque object. The maximum size of the deque would be already known.
Question : Now, use your implemented FixedSizeArray class from question to develop a Dequeue class
that will offer all the functionalities of traditional dequeue data structure with the property that the data
items can be added and removed both from the front and back. Dequeue class will use an instance of
FixedSizeArray to store items with the following structure.
Class Deque:
def initself n:
self.array FixedSizeArrayn
self.first it can be something else too based on your implementation
self.last it can be something else too based on your implementation
This class needs to have the following functions implemented.
addfirste: Add element e to the front of deque.
addlaste: Add element e to the back of deque.
deletefirst: Remove and return the first element from deque; an error occurs if the deque is
empty.
deletelast: Remove and return the last element from deque; an error occurs if the deque is
empty.
first: Return but do not remove the first element of deque; an error occurs if the deque is
empty.
last: Return but do not remove the last deque element; an error occurs if the deque is empty.
isempty: Return True if deque does not contain any elements.
length: Return the number of elements in the deque.
printdeque: Prints all the items currently present in the deque from the first inserted item to
the last one. Note: this function does not remove any item from the internal list.
Question : Write codes to create an instance of the Deque class D Deque and perform the
following operations in this sequence with the Deque object D:
Ddeletelast
Daddlast
Daddfirst
Ddeletelast
Dprintdeque
Daddfirst
Daddfirst
Daddlast
Ddeletelast
Ddeletefirst
Dlength
Dprintdeque
Question : Find out the bigoh notations of your developed algorithms in the Stack and Deque class for
the following functions:
insertAtindex value
removeindex
addfirste
addlaste
deletefirst
deletelast
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
