Question: Questions 7-9 deal with a queue data structure implemented via two stacks. 7 Let si be the main stack used to store data and s2

Questions 7-9 deal with a queue data structure implemented via two stacks. 7 Let si be the main stack used to store data and s2 be an auxiliary stack which can be used to relocate data from si temporarily to assist with queue operations. Suppose all elements of the queue are in si and the top of stack si corresponds to the front end of the queue. Note that both si and s2 can be used for implementing enqueue and dequeue, but after completing these operations stack s2 should be empty. 7.1 Present pseudocodes for enqueue (with the input parameter x) and dequeue (with the output parameter y). State the big-O complexity classes for enqueue and dequeue, with parameter n denoting the total number of elements in the queue. in the pseudocodes, use indentation in a clear way, follow the syntax of pushStack and popStack statements as in Question 6, additionally you can use the statements like While si is not empty While S2 is not empty IF S1 is empty then ERROR IF S2 is empty then ERROR IF S1 is empty then IF S2 is empty then IF Si is not empty then IF S2 is not empty then You can also assume that the size of each stack is sufficiently large to store all data (no need to check if adding an item into a stack exceeds its capacity). [6 marks] 7.2 Suppose we start with empty stacks si and S2. First we perform n enqueue operations and after that n de queue operations. What is the overall time complexity? [1 mark]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
