Why does the order of the loops affect performance when iterating over a 2D array?
As others have said, the issue is the store to the memory location in the array: x[i][j]. Here’s a bit of insight why: You have a 2-dimensional array, but memory in the computer is inherently 1-dimensional. So while you imagine your array like this: 0,0 | 0,1 | 0,2 | 0,3 —-+—–+—–+—- 1,0 | 1,1 … Read more