Source: https://perso.liris.cnrs.fr/nathalie.guin/LIF3/Cours/Cours5-Tris.pdf