|
|
|
|
|
by panda88888
2474 days ago
|
|
My question is that each move is a set of push/pop. DEQ based on fixed array has linear complexity for either push (left aligned) or pop (right aligned). One way to have constant push AND pop is to allow for the left and right element to not be aligned to the initial fixed array memory allocation. For example, for a full DEQ, in order to perform a push, I would have to: 1. Pop the last element 2. Move all element to the right by 1 3. Push the item into position 0 This would be a linear operation. Unless the address of the starting and ending element can change, I don’t think it’s possible to get both push and pop to less than linear time. Edit: I was wrong--key is circular buffer |
|