K-means Cluster Analysis. Basic Algorithm Definition 1: The basic k-means clustering algorithm is defined as follows: Step 1: Choose the number of clusters kStep 2: Make an initial selection of k centroidsStep 3: Assign each data element in S to its nearest centroid (in this way k clusters are formed one for each centroid, where each cluster consists of all the data elements assigned to that centroid)Step 4: For each cluster make a new selection of its centroidStep 5: Go back to step 3, repeating the process until the centroids don’t change (or some other convergence criterion is met)

From Wolfram MathWorld. The distance between two points is the length of the path connecting them.

In the plane, the distance between points and is given by the Pythagorean theorem, In Euclidean three-space, the distance between points is.