Working mechanics of the k-means algorithm