title: Representing a 2D array as a 1D array
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/732684/implementing-a-matrix-which-is-more-efficient-using-an-array-of-arrays-2d-or">Implementing a matrix, which is more efficient - using an Array of Arrays (2D) or a 1D array?</a><br>
    <a href="https://stackoverflow.com/questions/1242705/performance-of-2-dimensional-array-vs-1-dimensional-array">Performance of 2-dimensional array vs 1-dimensional array</a>  </p>
  </blockquote>
  
  <p>I was looking at one of my buddy's molecular dynamics code bases the other day and he had represented some 2D data as a 1D array.  So rather than having to use two indexes he only has to keep track of one but a little math is done to figure out what position it would be in if it were 2D.  So in the case of this 2D array:</p>
  
  <pre><code>two_D = [[0, 1, 2],
           [3, 4, 5]]
  </code></pre>
  
  <p>It would be represented as:</p>
  
  <pre><code>one_D = [0, 1, 2, 3, 4, 5]
  </code></pre>
  
  <p>If he needed to know what was in position (1,1) of the 2D array he would do some simple algebra and get 4.</p>
  
  <p>Is there any performance boost gained by using a 1D array rather than a 2D array.  The data in the arrays can be called millions of times during the computation.</p>
  
  <p>I hope the explanation of the data structure is clear...if not let me know and I'll try to explain it better.</p>
  
  <p>Thank you :)</p>
  
  <p><strong>EDIT</strong>
  The language is C</p>