(1) Let be the maximum number of iterations allowed, ;
be the initial centers, , and be the set of centers in the iteration ;
(2) Compute the value of ,
(3) Assign the elements to the clusters, according to
(4) Update the cluster centers, take ;
(5) If ; or , then stop. Otherwise, go to step (2);
(6) End.
Algorithm 1: KM algorithm.