Source: http://www.lix.polytechnique.fr/~hurand/Cours/Master1Algo/TD1.pdf