Question: In the lecture you learned about the data structures stacks and queues. The aim of this task is to deepen your understanding of both data
In the lecture you learned about the data structures stacks and queues. The aim of this task is to deepen your
understanding of both data structures.
a Let be a queue implemented on an initially empty array of size Represent the array after each of the
following operations: enqueue ; enqueue ; enqueue ; dequeue ; dequeue ; enqueue ;
enqueueQ: dequeue
Qb Let be a stack. which is implemented on an Arrav of size and initially contains the following letters:
Represent the array after each of the following operations: popS; popS; pushSX
pop;pop;push; pushS N
c Consider a data structure DoubleStack, which contains two stacks. This should be implemented here in an
array of size EN Neither stack should overflow as long as the total number of elements in both
stacks is at most To do this, implement the methods new, push push popl, pop Both push
and pop methods should run in constant time, ie The pop methods are supposed to return an
error symbol if the associated stack is empty. Justify your design.
d Design an algorithm that inverts a stack, ie reverses the order of the entries. You may only use stacks
in addition to the input stack as additional memory and no other data structures. Furthermore
the algorithm should not have a return value, but should perform the reversal in the passed
stack. Do not perform unnecessary copy operations. Justify your design
e Design an algorithm that inverts a stack, ie reverses the order of the entries. You may only use
queues in addition to the input stack as additional memory and no other data structures.
Furthermore, the algorithm should not have a return value, but should perform the reversal in
the passed stack. Do not perform unnecessary copy operations. Justify your design.
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
