title: how does random access of an element in deque gives constant time complexity?
body: <p>Deque gives constant complexity for accessing any element( <a href="https://en.cppreference.com/w/cpp/container/deque" rel="nofollow noreferrer">cpp reference</a> ). 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).</p>
  <pre><code>vector&lt;int&gt; v1;
  deque&lt;int&gt; d1;
  for(int i =0; i &lt; 1000000;++i)
      v1.push_back(i);
  for( int j =0; j &lt; 1000000;++j)
      d1.push_back(j);
  cout &lt;&lt; *(&amp;v1[0] +90000) &lt;&lt; endl; // output 90000
  cout &lt;&lt; *(&amp;d1[0] +90000)&lt;&lt;endl;   // Output is not 90000
  </code></pre>