Understanding the algorithm