A typical deque implementation is basically a vector of pointers to nodes of a fixed size.
Allocating a fixed-size node clearly has constant complexity, so it’s easy to handle - you simply amortize the cost of allocating one node by the number of elements in that node to get constant complexity for each.
The vector of the pointer part is what is (slightly) more interesting. When we select enough nodes of a fixed size so that the pointer vector is full, we need to increase the size of the vector. Like std::vector , we need to copy its contents to the newly selected vector, so its growth should correspond to a geometric (and not arithmetic) progression. This means that we have more pointers to copy, we make copies less and less, so the total time spent copying pointers remains constant.
As a side note: the "vector" part is usually treated as a circular buffer, so if you use your deque as a queue, constantly adding to one end and deleting from the other does not redistribute the vector - it just means moving the head and tail pointers, which track which of the pointers is “active” at a given time.
source share