arXiv:2610.33739cs.LGOct 2026

Manuscript Offprint

arXiv:2610.33739

A quantum k-nearest neighbors implementation using magnitude-aware comparisons

Christopher Rector, Jiangwen Sun

Abstract

Much attention has recently been devoted to the k-nearest neighbors (KNN) algorithm as a case study for quantum computing algorithms. Several algorithms have devised methods to compute a similarity metric to solve Quantum KNN (QKNN). This paper presents a practical quantum encoding technique that enables Euclidean distance calculation between vectors with different L2 norms by appending a single component to each vector, then uses it in the QKNN problem. It is arguably simpler to understand and implement than comparable methods and uses fewer qubits. Further, an implementation of this algorithm is provided and is used to benchmark it against a recent Euclidean-distance QKNN method on standard labeled datasets. In addition to demonstrating proper formulation, the results show marked improvement over similar implementations during simulation with realistic noise due to the use of fewer qubits and thus more coherent circuits.

Keywords: Quantum Computing, Machine Learning, NISQ, Data Science

1 Introduction

Machine learning is a popular solution to many otherwise challenging problems spanning various disciplines. A nascent subset of these solutions use quantum computers as an alternate execution medium for well-known machine learning algorithms. Since Shor's solutions [1][1] to the factoring, discrete-log, and period-finding problems, researchers have proposed several algorithms that could achieve quantum supremacy.

[2] over traditional computers. Quantum computing has shown promising improvements to classical algorithms, including proofs of quadratic [3] and exponential [1] computational speedups. This potential for speeding up classical algorithms provides an impetus to re-invent these algorithms, which were designed for classical computers, into implementations that can be executed on quantum computers. The field of machine learning has not been excluded - significant progress has been made in methods ranging from quantum annealing [4] to convolutional neural networks [5].

Recent advancements in Quantum Machine Learning (QML) include theoretical or practical implementations of quantum Support Vector Machines (SVMs) [6, 7], k-means [8, 9], and Quantum K-Nearest Neighbors (QKNN) [10]. The K-Nearest Neighbors (KNN) algorithm [11], in which test samples are iteratively assigned labels based on their similarity to pre-labeled training samples, has seen significant efforts toward developing a competitive quantum variant. A detailed review will follow in Section 2, but some outstanding issues remain to be addressed in the present literature. QKNN implementations use many metrics to evaluate similarity, including cosine similarity [12–14], Mahalanobis distance [15], and fidelity [16]. Euclidean distance has also been used [17]. Wiebe et al. [10] compute it coherently for normalized vectors, Schuld et al. [18] and Berti et al. [19] estimate it with an interference circuit on unit-norm inputs, Lloyd et al. [20] recover it for unnormalized vectors whose norms are supplied separately, and Zardini et al. [21] append norm-dependent components that roughly double the dimension of each encoded vector. These approaches either discard the magnitudes of the vectors, need the norms as separate inputs, or substantially enlarge the encoded vectors. This report shares the same professional sentiment as Zardini et al. [21] that few published algorithms are practical in the near term.

This report presents a novel approach to QKNN that addresses these concerns and can be implemented on quantum computers without the use of oracles or other such abstractions. It encodes real-valued vectors with different L2L2 norms by appending a single component to each vector, so that meaningful magnitude comparisons between the original vectors can be retrieved by measuring the quantum state. It improves on previous implementations that use Euclidean distance comparisons by using a much less complicated encoding technique and fewer qubits.

In brief, Section 2 presents relevant background information; Section 3 presents a novel algorithm based on a new quantum encoding technique, along with its basic implementation; Section 4 describes the experimental setup and results; Section 5 provides closing remarks and potential future work.

References (40)