Complete the k-means algorithm