in a pseudo code the algorithm is the following