What is the Big O of deque data structure in c++? And how it really implemented!
I didn't Found the answer anywhere.
What is the Big O of deque data structure in c++? And how it really implemented!
I didn't Found the answer anywhere.
From the CPPreference page on std::deque
:
The complexity (efficiency) of common operations on deques is as follows:
Random access - constant O(1)
Insertion or removal of elements at the end or beginning - constant O(1)
Insertion or removal of elements - linear O(n)
While I'm at it:
As opposed to std::vector, the elements of a deque are not stored contiguously: typical implementations use a sequence of individually allocated fixed-size arrays, with additional bookkeeping, which means indexed access to deque must perform two pointer dereferences, compared to vector's indexed access which performs only one.
If you want to read the nitty-gritty details, suggest you open your <deque>
header file and start reading. Be aware: STL code likes to use underscores and single-letter variable names a lot.
Referring to the document https://en.cppreference.com/w/cpp/container/deque
The complexity (efficiency) of common operations on deques is as follows:
Random access - constant O(1)
Insertion or removal of elements at the end or beginning - constant O(1)
Insertion or removal of elements - linear O(n)