Source: https://stph.scenari-community.org/bdd/alg1.pdf