Question arises from considering cache oblivious algorithms.

What is the optimal way arrange the numbers $1$ to $k^2$ in a grid, to minimize to average difference between any two neighbouring squares? What about minimizing the expected maximum difference between two squares, chosen uniformly? [Joining the edges of the grid to form a torus]

We can do better than just filling in row by row, for instance the Morton layout (for $k = 2^n$), as illustrated below for $k = 16$

$\begin{array}{cccccccc} 1& 2& 5& 6& 17& 18& 21& 22\\\\ 3& 4& 7& 8& 19& 20& 23& 24\\\\ 9& 10& 13& 14& 25& 26& 29& 30\\\\ 11& 12& 15& 16& 27& 28& 31& 32\\\\ 33& 34& 37& 38& 49& 50& 53& 54\\\\ 35& 36& 39& 40& 51& 52& 55& 56\\\\ 41& 42& 45& 46& 57& 58& 61& 62\\\\ 43& 44& 47& 48& 59& 60& 63& 64\end{array}$

Is there a better layout? I'm sure someone must have thought about this before, but can't seem to find anything relevant.