Source: https://www-fourier.ujf-grenoble.fr/~viva/teaching/algo/TP6.pdf