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

Quick Overview

Asks for the time complexity of one iteration of standard k-means in terms of points, clusters and dimensions. Tests the cost of the assignment and update steps, total runtime over iterations, memory use, and common ways to speed the algorithm up.

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

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

What is the time complexity per iteration of the standard k-means algorithm? Give the cost in terms of the number of points $n$, the number of clusters $k$ and the dimensionality $d$, and say which step of Lloyd's algorithm accounts for it. ```hint Count the distances Split one iteration into its two steps and count how many point-to-centroid distances the first step computes. ``` ### What a Strong Answer Covers - The per-iteration cost and which step dominates it - The cost of the centroid update step - Total runtime over many iterations, and why implementations cap the iteration count - Memory use - Practical ways to reduce the cost ### Follow-up Questions - How does the cost change for sparse, high-dimensional data such as TF-IDF vectors? - How does Elkan's algorithm skip distance computations, and when does it stop helping? - What does mini-batch k-means give up in exchange for its lower cost per step? - How would you run k-means on a billion points that do not fit on one machine?

Overview: Asks for the time complexity of one iteration of standard k-means in terms of points, clusters and dimensions. Tests the cost of the assignment and update steps, total runtime over iterations, memory use, and common ways to speed the algorithm up.

General logo
General
Nov 25, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

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

Give the cost in terms of the number of points nn, the number of clusters kk and the dimensionality dd, and say which step of Lloyd's algorithm accounts for it.

What a Strong Answer Covers Guidance

  • The per-iteration cost and which step dominates it
  • The cost of the centroid update step
  • Total runtime over many iterations, and why implementations cap the iteration count
  • Memory use
  • Practical ways to reduce the cost

Follow-up Questions Guidance

  • How does the cost change for sparse, high-dimensional data such as TF-IDF vectors?
  • How does Elkan's algorithm skip distance computations, and when does it stop helping?
  • What does mini-batch k-means give up in exchange for its lower cost per step?
  • How would you run k-means on a billion points that do not fit on one machine?