Question: You can design the algorithm in pseudo code We want to design a list-like data structure that supports the following operations on integers. ADDTOFRONT(e): Adds
You can design the algorithm in pseudo code

We want to design a list-like data structure that supports the following operations on integers. ADDTOFRONT(e): Adds a new element e at the front of the list. ADDToBack(e): Adds a new element e at the end of the list. REMOVEFROMFRONT(): Removes the first element from the list and returns it. REMOVEFROMBACK(): Removes the last element from the list and returns it. SETELEMENT(i, e): Sets the element of the i-th element of the list to e. Each operation should run in O(1) time. You can assume that we know that the list will never contain more than k elements (k is not a constant and should not show up in your running time). Example execution: ADD TOBACK(0) [0] ADDTOFRONT(-1) (-1,0] ADD TO FRONT(2) [2,-1,0] SETELEMENT(1,6) [2,6,0] REMOVEFROMBACK() [2,6], returns o REMOVEFROMFRONT() [6], returns 2 a) Design a data structure that supports the above operations in the required time. b) Briefly argue the correctness of your data structure and operations. c) Analyse the running time of your operations
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
