title: closest pair pseudo code example
body: <p>I have been reading Algorithm design manual. I have the same question as <a href="https://stackoverflow.com/questions/7216755/">What is the meaning of &quot;from distinct vertex chains&quot; in this nearest neighbor algorithm?</a> but I am not able to follow the answers there.</p>
  
  <blockquote>
    <p>A diﬀerent idea might be to repeatedly connect the closest pair of endpoints whose connection will not create a problem, such as premature termination of the cycle. Each vertex begins as its own single vertex chain. After merging everything together, we will end up with a single chain containing all the points in it. Connecting the ﬁnal two endpoints gives us a cycle. At any step during the execution of this closest-pair heuristic, we will have a set of single vertices and vertex-disjoint chains available to merge. In pseudocode:</p>
  </blockquote>
  
  <pre><code>ClosestPair(P)
      Let n be the number of points in set P.
      For i = 1  to n − 1 do
          d = ∞
          For each pair of endpoints (s, t) from distinct vertex chains
              if dist(s, t) ≤ d then sm = s, tm = t, and d = dist(s, t)
          Connect (sm, tm) by an edge
      Connect the two endpoints by an edge
  Please note that sm and tm should be sm and tm.
  </code></pre>
  
  <p>I am not able to follow above logic. Please demonstrate the computation for the simple example which is given in <a href="http://www.cs.sysu.edu.cn/~lxm/DSA/textbook/Skiena.-.TheAlgorithmDesignManual.pdf" rel="nofollow noreferrer">the book</a>: <code>-21, -5, -1, 0, 1, 3, and 11</code>. Show the computations step by step, so that one can follow above code easily.</p>