function tree = single_linkage ( x_num, x, x_dist )

  cluster_num = x_num;
  cluster_dist = x_dist;

  while ( 1 < cluster_num  )
%
%  Find the closest pair of clusters.
%
    dist_min = Inf;
    i1 = 0;
    j1 = 0;

    for i = 1 : cluster_num
      for j = 1 : i - 1
        if ( cluster_dist(i,j) < dist_min )
          dist_min = cluster_dist(i,j);
          i1 = i;
          j1 = j;
        end
      end
    end
%
%  Record ( i1, j1, dist_min )
%
    fprintf ( 1, '  I1 = %d  J1 = %d DIST_MIN = %f\n', i1, j1, dist_min );
%
%  Row and column J1 get updated.
%
    for j = 1 : cluster_num
      cluster_dist(j1,j) = min ( cluster_dist(j1,j), cluster_dist(i1,j) );
    end

    for i = 1 : cluster_num
      cluster_dist(i,j1) = min ( cluster_dist(i,j1), cluster_dist(i,i1) );
    end
%
%  Remove column I1.
%
    cluster(1:cluster_num,i1:cluster_num-1) = cluster(1:cluster_num,i1+1:cluster_num);
%
%  Remove row I1.
%
    cluster(i1:cluster_num-1,1:cluster_num-1) = cluster(i1+1:cluster_num,1:cluster_num-1);
%
%  Update the count
%
    cluster_num = cluster_num - 1;

  end

  return
end
