Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please design the data structure in pseudo code We want to design a list-like data structure that supports the following operations on integers. ADDTOFRONT(e): Adds
Please design the data structure 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 operationsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started