In my program, I have a set of points. For purposes of rescaling, I am searching for the two nodes that are furthest apart, and then computing a factor by which to multiply
The distance from A
to B
is the same as the distance from B
to A
. You can easily modify the algorithm to eliminate half of the computations this way. It'll still be O(n^2)
but will be twice as fast.
That is, instead of computing all off-diagonal elements of the distance matrix P x P
:
P = {A, B, C, D, ...}
+ A + B + C + D + ...
A | | * | * | * | ...
B | * | | * | * | ...
C | * | * | | * | ...
D | * | * | * | | ...
| | | | |
you can compute either the upper triangle:
+ A + B + C + D + ...
A | | * | * | * | ...
B | | | * | * | ...
C | | | | * | ...
D | | | | | ...
| | | | |
or the lower triangle:
+ A + B + C + D + ...
A | | | | | ...
B | * | | | | ...
C | * | * | | | ...
D | * | * | * | | ...
| | | | |