Write the pseudocode for a k-means clustering algorithm from scratch. What is the mathematical guarantee of its convergence?