Is there an algorithmic description of a bijection $\mathbb{N} \leftrightarrow \mathbb{N}^2$ with a traversal described below Is there some pattern/recurrence for every column and row in distributing numbers $a_1,a_2,a_3,…$ as the graphic shows?

The way shown of distributing $a_1,a_2,a_3,…$ continues down and to the right for ever.
For the first row ($1,2,9,10,25,26,…$), it seems to be $n^2$ for odd, and $(n-1)^2+1$ for even $n$th element of the row
For the first column ($1,4,5,16,17,…$), it seems to be $n^2$ for even, and $(n-1)^2+1$ for odd $n$th element of the column.
 A: The following function converts $(x,y)$ coordinates, where $+x$ is right and $+y$ is down and indices start from $1$, to the $i$ of the $a_i$ at that coordinate. The function may thus be said to be the underlying pattern for the indices.

*

*Determine the L-shaped "shell" the coordinate lies in, where shell $n$ consists of $a_{(n-1)^2+1}$ to $a_{n^2}$ inclusive. $(x,y)$ lies in shell $s=\max(x,y)$.

*The corner of shell $n$ is $a_{n^2-n+1}$. Let $d=|x-y|$ and $i=s^2-s+1$, then

*

*return $i-d$ if $s$ is odd and $x\le y$ or $s$ is even and $x\ge y$

*return $i+d$ if $s$ is odd and $x>y$ or $s$ is even and $x<y$
A: There exists a Wiki page devoted to "avatars" of the so-called "Cantor pairing function" ; one of them, called "elegant pairing" discovered by Szudzik has a strong similarity with the objective you want to achieve ; here is the very simple pseudo-code (close to the Matlab program I have written to display it) of the function $\mathbb{N}\to \mathbb{N}\times\mathbb{N}$.

 for z=0 to n^2-1 :
    r=floor(sqrt(z));
    s=z-r^2;
    if s<r
       x=s;y=r;
    else
       x=r;y=s-r;
    endif
    place number z at position (x,y).
 end;

(In the wiki page, they give as well the code for the reciprocal function $\mathbb{N}\times\mathbb{N} \to \mathbb{N}$).
I am almost convinced that this "elegant pairing" method can be adapted to generate your specific traversal.
