Deque gives constant complexity for accessing any element( cpp reference ). In Vector, it's always constant complexity(the address of the first element in vector + no of elements * size of each element) but how does it work for Deque? Deque elements are not contiguous in memory, so how does it enable O(1) time complexity to access any element? When I ran the following program, in the case of Vector, it gives correct output, but for Deque, it gives some arbitrary numbers (agreed to not give the correct result because elements are not contiguous).
vector<int> v1;
deque<int> d1;
for(int i =0; i < 1000000;++i)
v1.push_back(i);
for( int j =0; j < 1000000;++j)
d1.push_back(j);
cout << *(&v1[0] +90000) << endl; // output 90000
cout << *(&d1[0] +90000)<<endl; // Output is not 90000