What is the time complexity per iteration of the standard k-means algorithm?

Last updated 11 November 2026

  • Each iteration costs O(n·k·d) for n points, k clusters, d dimensions. The assignment step (every point to every centroid) dominates, while the update step is O(nd).

  • Total runtime is O(n·k·d·i) for i iterations. i is usually small, but worst case is superpolynomial, so implementations cap max_iter.

  • Speedups: Elkan's algorithm (triangle inequality skips distances) and mini-batch k-means at O(b·k·d) per step.

  • https://buildml.substack.com/p/data-science-inteview-guide-part
  • https://www.geeksforgeeks.org/r-language/k-means-clustering-in-r-programming/
  • https://medium.com/@jeongeun3.24lee/ct-k-means-clustering-10-d43fb89ab275
All Clustering interview questions