Source: https://www.irif.fr/~francoisl/IREM/tri.pdf