Algorithm 1.2.1