QuantumAtlas

Quantum Algorithms Database

Quantum k-Means Clustering

A quantum version of the classical k-means clustering algorithm, grouping similar data points together using quantum distance estimation techniques.

Year

2013 (Lloyd, Mohseni, and Rebentrost); 2013 (Aïmeur, Brassard, and Gambs); 2019 (q-means)

Inventor(s)

Seth Lloyd, Masoud Mohseni, and Patrick Rebentrost; Esma Aïmeur, Gilles Brassard, and Sébastien Gambs; Iordanis Kerenidis and coauthors (q-means)

Speedup Type

Exponential Speedup

Difficulty

★★★★☆

Overview

The k-means algorithm groups data points into k clusters by repeatedly assigning each point to its nearest cluster center and then moving each center to the average of its points. It is one of the most widely used unsupervised learning methods. Quantum k-means replaces the expensive distance calculations and updates with quantum subroutines such as the SWAP test and amplitude estimation.

There are several versions. Lloyd, Mohseni, and Rebentrost proposed a version with a runtime that depends only logarithmically on the size and dimension of the data, assuming quantum access to the data. Aïmeur, Brassard, and Gambs proposed a version using Grover search for a quadratic speedup. Kerenidis and coauthors proposed q-means in 2019, which has a polylogarithmic runtime per iteration under data-access assumptions.

The problem it solves

Partitioning a dataset into clusters of similar items — one of the most common unsupervised machine learning tasks.

History and background

Lloyd, Mohseni, and Rebentrost described quantum algorithms for supervised and unsupervised machine learning in 2013, including nearest-centroid classification and clustering. In the same year, Aïmeur, Brassard, and Gambs published Quantum Speed-up for Unsupervised Learning in the journal Machine Learning, using Grover search to speed up clustering primitives. In 2015 Wiebe, Kapoor, and Svore extended quantum methods to nearest-neighbor learning.

The q-means algorithm by Kerenidis, Landman, Luongo, and Prakash was presented at NeurIPS 2019, along with simulations suggesting accuracy comparable to classical k-means on image data, with noise built in. In 2018, Ewin Tang gave classical sampling-based algorithms for supervised clustering, which cast doubt on exponential speedups under comparable data access. Small experimental demonstrations with a few qubits have been reported on photonic and superconducting devices.

How it works

Uses quantum subroutines like the SWAP test to estimate distances between data points and cluster centers, potentially reducing the work needed compared to classical distance calculations.

Classical k-means spends most of its time computing distances between N data points and k centroids in d dimensions. That is about N times k times d operations per iteration. If the data points and centroids are stored as quantum states, the distance between two of them can be estimated with the SWAP test using a number of operations that depends on the logarithm of d, not d itself.

For the update step, the new centroid of a cluster is the average of its points. A quantum computer can prepare a superposition over all points in the cluster and use amplitude estimation to estimate their mean coordinates, with a quadratic improvement in precision over sampling.

Grover-style versions work differently. They treat finding the point farthest from or nearest to a center as a search problem and use quantum minimum finding to speed it up, giving a square-root gain in the number of points.

Step by step

  1. Load the N data points into a quantum memory so that each can be prepared as a quantum state on demand, and choose k initial centroids.
  2. For each data point, estimate its distance to every centroid using the SWAP test or an inner-product estimation routine.
  3. Assign each point to its nearest centroid, using quantum minimum finding over the k estimated distances.
  4. Estimate the new centroid for each cluster by amplitude estimation, or by preparing a superposition of the cluster's points and measuring.
  5. Replace the centroids with the new estimates, with a tolerance that accounts for estimation error.
  6. Repeat until the centroids stop changing, and read out the final cluster centers or the cluster assignments.

A worked example

Suppose there are 1,000,000 data points in 128 dimensions and k = 10 clusters. Classical k-means needs about 1.3 billion distance component operations per iteration. A quantum version with data in a QRAM could estimate each point-to-centroid distance in a number of steps that grows only with the logarithm of 128, but it must repeat the SWAP test thousands of times for each estimate to reach useful precision.

The overall advantage depends on whether the cost of building the QRAM and the precision requirements are small compared with the classical work. For a one-time clustering of a fixed data set, the loading cost can erase the gain, which is why proposals emphasize repeated clustering tasks over the same loaded data.

Complexity and resources

ItemDetail
Classical k-means per iterationO(N k d) distance operations
q-means per iteration (Kerenidis et al.)Polylogarithmic in N and d, with polynomial dependence on k, the precision, and data-structure parameters
Grover-based versionQuadratic improvement in the number of points N
Dequantized classical algorithmPolylogarithmic in N for low-rank data with sampling access (Tang, 2018)
Data requirementQRAM or efficient state preparation, with a possible preprocessing cost linear in the data size

What hardware it needs

  • A fault-tolerant quantum computer with a large QRAM for the exponential-speedup versions.
  • Fast, repeated SWAP tests and amplitude estimation with high-fidelity gates.
  • A classical controller for the iteration loop and stopping criterion.

Applications

  • Clustering large data sets in marketing, genomics, and image analysis, if data access is cheap.
  • Compression and quantization of images or features.
  • Preprocessing for other machine learning models.
  • Clustering of quantum data, where states are already available.

Limitations and caveats

  • Loading classical data into quantum states removes much of the theoretical speedup.
  • Classical algorithms such as sampling-based methods and mini-batch k-means are already fast.
  • Distance estimation requires many repetitions for good precision, adding overhead.
  • No demonstration has outperformed classical clustering on real data.

Common misconceptions

  • Quantum k-means does not always give the same clusters as classical k-means. Estimation noise changes the results slightly.
  • It does not remove the need to choose k or to deal with poor initialization.
  • An exponential speedup claim depends entirely on the data access model.

How it compares

  • Classical k-means is simple, fast, and parallelizable.
  • Quantum PCA and quantum support vector machines share the same input assumptions.
  • Quantum anomaly detection uses similar distance and projection ideas.

Real-world impact

Like other early quantum ML proposals, theoretically promising but constrained by the practical challenge of efficiently loading real-world data into quantum states.

Why it matters

Clustering is among the most common machine learning tasks, so a quantum speedup would have broad effects. The q-means work also set a standard for stating assumptions and running noise-aware simulations in quantum machine learning papers.

The field's experience, with a claimed exponential gain followed by classical dequantization, is a good case study for how to judge claims in the area.

Frequently asked questions

What is quantum k-means?

A family of quantum algorithms that speed up the distance computation and centroid update steps of k-means clustering using the SWAP test, amplitude estimation, or Grover search.

Is quantum k-means exponentially faster?

Under strong data-access assumptions, the q-means runtime is polylogarithmic in the data size. Classical algorithms with comparable sampling access reach similar scaling for low-rank data.

What is q-means?

A 2019 quantum k-means algorithm by Kerenidis, Landman, Luongo, and Prakash that includes noise-aware analysis and simulations.

Can I run it on a quantum computer today?

Only on tiny data sets in demonstrations. Realistic data requires fault-tolerant hardware and quantum memory.

How does it use the SWAP test?

To estimate the distance between a data point and a centroid from the overlap of their quantum states.

Keep learning

This page is written for educational purposes. Complexity statements describe the best known results at the time of review (September 30, 2026), and research in this area moves quickly, so check recent papers before relying on a specific bound.

← Back to Algorithms Database