Pairing Function

Author

Eric W. Weisstein
April 16, 2004

This notebook downloaded from http://mathworld.wolfram.com/notebooks/ComputerScience/PairingFunction.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/PairingFunction.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Examples

Hopfcroft-Ullman

PairingFunction1[i_,j_]:=(i+j-2)(i+j-1)/2+i

Table[PairingFunction1[i,j],{i,5,1,-1},{j,6}]//TableForm

Cantor

PairingFunction2[i_,j_]:=PairingFunction1[i+1,j+1]-1

Table[PairingFunction2[j,i],{i,5,0,-1},{j,0,6}]//TableForm