0
$\begingroup$

I am trying to read an algorithm for computing minimum distance between each pair of points from the book: Algorithm Design

Algorithm Design

Description of Algorithm

It considers the points in a line. If the points are in a line why we need to sort them? We can start from the beginning and compute the distances from starting pint to all the points on the right.

Some body please guide me why we need sorting?

$\endgroup$
1
$\begingroup$

Suppose the points are $[4,1,10,11]$. The distance from the starting point (whether you interpret that as $4$ or $1$) to each other point does not give you the nearest pair of points.

In this problem, the input is an array containing numbers, not in sorted order.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.