Calculating the number of steps required by this algorithm is not easy. In fact, at first glance, it might even be difficult to see that it always terminates. However, it does terminate because the distance between A and B only increases at each step. This distance cannot increase forever because we know that there are n(n - 1) pairs of points and therefore at most n(n - 1) different distances between A and B. In fact,  claims that the algorithm is optimal, i.e. requires at most some constant multiple of n steps, using the following argument:
Since this method goes around the boundary only in the direction of increasing distance, it avoids comparing the same pair of points twice.Do you agree with this? How many pairs of points are there? Note that we aren't questioning correctness here, just optimality. We will discuss correctness later.