title: Efficient algorithm for finding spheres farthest apart in large collection
body: <p>I've got a collection of 10000 - 100000 spheres, and I need to find the ones farthest apart. </p>
  
  <p>One simple way to do this is to simply compare all the spheres to each other and store the biggest distance, but this feels like a real resource hog of an algorithm.</p>
  
  <p>The Spheres are stored in the following way:</p>
  
  <pre><code>Sphere (float x, float y, float z, float radius);
  </code></pre>
  
  <p>The method Sphere::distanceTo(Sphere &amp;s) returns the distance between the two center points of the spheres.</p>
  
  <p>Example:</p>
  
  <pre><code>Sphere *spheres;
  float biggestDistance;
  
  for (int i = 0; i &lt; nOfSpheres; i++) {
      for (int j = 0; j &lt; nOfSpheres; j++) {
          if (spheres[i].distanceTo(spheres[j]) &gt; biggestDistance) {
              biggestDistance = spheres[i].distanceTo(spheres[j]) &gt; biggestDistance;
          }
      }
  }
  </code></pre>
  
  <p>What I'm looking for is an algorithm that somehow loops through all the possible combinations in a smarter way, if there is any.</p>
  
  <p>The project is written in C++ (which it has to be), so any solutions that <em>only</em> work in languages other than C/C++ are of less interest.</p>