Implementing a matrix, which is more efficient - using an Array of Arrays (2D) or a 1D array?

前端 未结 6 932
难免孤独
难免孤独 2020-12-10 14:06

When implementing a Matrix construct using arrays, which would be more efficient? Using a 1D array, or an array of arrays (2D)?

I would think a 2D is more efficient

6条回答
  •  借酒劲吻你
    2020-12-10 14:53

    Depending on the language, there will be no difference. The real question is how the 2D matrix is allocated. Is it a single contiguous space of X*Y bytes, or is it allocated as Y independent arrays of X size. The latter is usually done when creating sparse matrices.

提交回复
热议问题