What is the time complexity per iteration of the standard k-means algorithm?
Last updated
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.