Abstract
DBSCAN is a famous density-based clustering algorithm that can discover clusters with arbitrary shapes without the minimal requirements of domain knowledge to determine the input parameters. However, DBSCAN is not suitable for databases with different local-density clusters and is also a very time-consuming clustering algorithm. In this paper, we present a quantum mutual MinPts-nearest neighbor graph (MMNG)-based DBSCAN algorithm. The proposed algorithm performs better on databases with different local-density clusters. Furthermore, the proposed algorithm has a dramatic increase in speed compared to its classic counterpart.
Subject terms: Computer science, Information theory and computation
Introduction
Clustering, an important branch of unsupervised machine learning, is the process of partitioning a dataset into subsets of points called clusters, such that similar points are grouped in the same cluster and dissimilar points are put in different clusters. This procedure is widely used in many scientific fields, including bioinformatics1–4, image processing5–8, and social networks9,10.
DBSCAN11, a density-based clustering algorithm, is one of the most famous clustering algorithms. The distinguishing advantage of the DBSCAN algorithm is that it can be used to discover arbitrarily shaped clusters. Furthermore, it does not need the minimal requirements of domain knowledge to determine the input parameters, and can also exclude outliers from the clusters. However, DBSCAN has two dire drawbacks. First, DBSCAN has a low efficiency on databases with different local-density clusters; second, the algorithm is very time-consuming.
Quantum computing has attracted tremendous attention due to its parallel capability. In 1982, Feynman pointed out that quantum computers might achieve significant increase in speed over classical computers on certain specific problems12. Shor’s algorithm13 and Grover’s algorithm14 are two of the most popular quantum algorithms. Shor’s algorithm has an exponential increase in speed, and Grover’s algorithm has a quadratic increase in speed over their classical counterparts. With the rise of quantum computing, many researchers have also designed various quantum machine learning algorithms and quantum data mining algorithms, such as quantum linear regression15–17, quantum support vector machine18,19, quantum k-nearest neighbors classification20, quantum deep learning21, and quantum association rules mining22. Recently, tremendous advances have been made in constructing quantum computers. Krantz et al.23,24 introduced the central concepts and challenges of superconducting quantum circuits. Huang et al.25 provided experimental efforts toward large-scale superconducting quantum computers. Bruzewicz et al.26 concluded the basics of trapped-ion quantum computing and explored the outlook for trapped-ion quantum computing.
Inspired by quantum computing, we propose a quantum mutual -nearest neighbor graph (MMNG)-based DBSCAN algorithm. First, we design a quantum mutual -nearest neighbor graph algorithm that is devoted to dividing a database into subsets. After that, we quantize the original DBSCAN algorithm to cluster each subset.
Preliminaries
In this section, we provide the necessary background knowledge for this paper. First, we briefly introduce the basic definitions of the classical DBSCAN algorithm. Then, we review the fundamental concepts of Grover’s algorithm.
DBSCAN
The DBSCAN algorithm offers a new notion of “cluster” and “noise” in a database of points of some k-dimensional space . The whole set of definitions is given as follows.
Definition 1
(-neighborhood of a point) The -neighborhood of a point , denoted by , is defined by .
The -neighborhood, the fundamental definition of the algorithm, can be used to distinguish core points and noncore points. is the distance threshold. Core points are the points inside of any cluster, and noncore points are the points on the border of any cluster or the points belonging to none of the clusters. Let be a point in a database , where denotes the number of points within the -neighborhood of . Let be the threshold of the number of points; if , then is a core point; otherwise, is a noncore point.
Definition 2
(directly density-reachable) A point is directly density-reachable from a point if
and
Directly density-reachable is not always symmetric. When and are both core points, the direct density reachability is symmetric; when one is a core point and the other is a border point, the direct density reachability is asymmetric.
Definition 3
(density-reachable) A point is density-reachable from a point if there is a chain of points , , such that is directly density-reachable from .
Definition 4
(density-connected) A point is density-connected to a point if there is a point such that and are density-reachable from .
Definition 5
(cluster) Let be a database of points. A cluster is a nonempty subset of satisfying the following conditions:
: if and is density-reachable from then .
: is density-connected to .
In the database , not all the points belong to clusters. The points that do not belong to any cluster are defined as “noise” in the DBSCAN algorithm.
Definition 6
(noise) Let be the clusters of the database , . Then, we define the noise as the set of points in the database not belonging to any cluster , i.e., noise = .
Grover’s algorithm
Let us assume that we wish to search () solutions from an unstructured search space of elements. Rather than examining elements one by one, Grover’s algorithm checks the elements in parallel by assigning indexes to all of the elements and storing the indexes in a quantum register. With a series of unitary operations augmenting the success probability gradually, Grover’s algorithm can obtain the indexes of the target elements with a high probability.
The proposed algorithm
In this section, we design a quantum mutual -nearest neighbor graph algorithm and a quantum DBSCAN algorithm and present a quantum MMNG-based DBSCAN algorithm.
Quantum MMNG algorithm
Let be a database, and be some objects in , and be a positive integer. The relative concept will be introduced as follow.
Definition 7
(Mutual -nearest neighbor (MMN)): If is in the -nearest neighborhood of and is in the -nearest neighborhood of , then we call a mutual -nearest neighbor of ; similarly, is a mutual -nearest neighbor of .
Definition 8
(Mutual -nearest neighbor graph (MMNG)): The mutual -nearest neighbor graph can be constructed by connecting each point to its mutual -nearest neighbors.
Note that MMNG is an algorithm with high complexity. To speed up the MMNG, we intend to quantize the MMNG algorithm. Dürr et al.27 developed a quant_find_smallest_values algorithm for finding the closest neighbors of a point with high probability within time. Based on the quant_find_smallest_values, we propose a quantized MMNG algorithm, as shown in algorithm 1.
In this paper, algorithm 1 is used to obtain the subsets of database . After obtaining the subsets, we apply the quantum DBSCAN algorithm on each subset to obtain the eventual clusters and the noise set.
Quantum DBSCAN algorithm
We consider a database , which is composed of points, and each point has attributes. For each point in , it is necessary to calculate times to determine the -neighborhood of . Determining the -neighborhood is fairly time-consuming. To solve this problem, we intend to screen the points in the -neighborhood of with quantum search.
In our model, a quantum distance black box is proposed. The proposed black box can accept two types of inputs, as illustrated in Fig. 1. is a one-state input and the index of point ; is a superposition of inputs and includes the indexes of all the points. Evidently, this is feasible because one q-bit can be a pure state or a superposition of states. Furthermore, one query to this black box means asking for distances between the point and all the points s (when , ). After obtaining the distances, the black box compares them with the distance. Then, a selection function assigns a value of 1 when is smaller than or equal to the distance and a value of 0 otherwise. The selection function is shown in Eq. (1).
| 1 |
Figure 1.

The oracle to compute the distance between and all the possible s. is an ancillary register.
Meanwhile, a flipping operation is carried out in the black box. As depicted in Eq. (2), if , the ancillary register is flipped; if , the ancillary register remained unaltered. The symbol denotes module 2, also known as an exclusive-or.
| 2 |
Based on the aforementioned black box, we designed algorithm 2 (quant_find_-neighborhood as described below) as a subroutine of the quantum-based DBSCAN algorithm. Given a specific point , algorithm 2 is able to fix its -neighborhood.
Once the -neighborhoods are fixable quantum-mechanically, core points and noncore points become discernable according to the basic notions of the classic DBSCAN. If a point is a noncore point, we keep looking for a core point because there is no need to create a new cluster for a noncore point; however, if a point is a core point, we set up a new cluster and expand it. With the expanding methodology offered in the original DBSCAN algorithm, the quantum-based DBSCAN algorithm quant_DBSCAN(, , ) is presented hereafter, as shown in algorithm 3.
Quantum algorithm for MMNG-based DBSCAN
The proposed algorithm divides the database into subsets first and then applies the quantum DBSCAN algorithm to each subset. Note that different subsets have a different in our algorithm. For a specific subset, we select the average distance as the of the subset.
The algorithm analysis
In this section, we briefly analyze the complexity of our algorithm first and then present the success probability of our algorithm.
The complexity
Dürr et al.27 proved that the complexity of quant_find_smallest_values is . It is easy to see that the complexity of algorithm 1 is .
For algorithm 2, there are targets for each point. According to the original version of Grover’s algorithm, algorithm 2 needs to interrogate the oracle approximately times. It can easily be perceived that the smaller is, the more queries are needed. In the worst case scenario, when , the queries of the oracle are approximately times. In other words, the complexity of algorithm 2 is .
For algorithm 3, we need to calculate the -neighborhood of every point. This means that algorithm 3 needs to call algorithm 2 times. Thus, we can ensure that the complexity of algorithm 3 is smaller than , even though the s are different for different points.
In other words, the complexity of our proposed algorithm is approximately .
The success probability
Dürr et al.27 proved that quant_find_smallest_values is able to obtain nearest neighbors with a high probability. It is easy to infer that algorithm 1 can obtain subsets with a high probability.
It is noteworthy that s are different from point to point, which means that there are different numbers of targets when algorithm 2 is dealing with different points. As a result, the success probabilities are different when calculating different -neighborhoods. By referencing the former work, the success probability of algorithm 2 can be calculated via Eq. (3) after iterations.
| 3 |
We already know that . Usually, is far less than , and are numbers close to . As a result, it can be inferred that the success probability of algorithm 3 is high.
Our proposed method is a combination of algorithm 1 and algorithm 3, thus success probability of the proposed method is high.
Performance evaluation
To show the effectiveness of the proposed algorithm, performance evaluation based on two databases is conducted. To compare our algorithm with the classic DBSCAN method and the NaNG method, we use the two synthetic sample databases depicted in Fig. 2.
Figure 2.

Sample databases.
The experimental results on database 1 are shown in Fig. 3. A total of 399 objects are included in database 1. In the figure, the black squares represent the points that are detected as outliers. The experimental result of DBSCAN on database 1 is undesirable, and the accuracy is approximately 74.6%. The experimental result of NaNG is better than that of DBSCAN, with an accuracy of 90.73%. Our proposed method has the best performance on database 1, with an accuracy of approximately 95.74%.
Figure 3.

Clustering results of database 1.
The experimental results on database 2 are shown in Fig. 4. As shown in Fig. 4a, database 2 includes 320 objects and 8 clusters. As shown in Fig. 4b, the result of DBSCAN is tolerable with an accuracy of 92.5%. From the result shown in Fig. 4c, we can see that NaNG mistakenly combines two clusters into one. The accuracy of NaNG is 87.5%. As shown in Fig. 4d, the performance of the proposed method is the same as DBSCAN with an accuracy of 92.5%.
Figure 4.

Clustering results of database 2.
Conclusion
Inspired by the mutual neighbor method and quantum computing, in this work, we present a quantum MMNG-based DBSCAN. Compared to the original DBSCAN, the proposed method performs better on databases with different local-density clusters. Furthermore, the proposed method is dramatically faster than its classical counterpart.
Author contributions
X.X. and L.D. wrote the main manuscript text. T.Q. and J.L. analysed the performance of the algorithm. All authors reviewed the manuscript.
Funding
Funding was provided by National Natural Science Foundation of China(62066027).
Competing interests
The authors declare no competing interests.
Footnotes
Publisher's note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
These authors contributed equally: Xuming Xie and Longzhen Duan.
References
- 1.Li W, Godzik A. Cd-hit: A fast program for clustering and comparing large sets of protein or nucleotide sequences. Bioinformatics. 2006;22:1658–1659. doi: 10.1093/bioinformatics/btl158. [DOI] [PubMed] [Google Scholar]
- 2.King AD, Przlj N, Jurisica I. Protein complex prediction via cost-based clustering. Bioinformatics. 2004;20:3013–3020. doi: 10.1093/bioinformatics/bth351. [DOI] [PubMed] [Google Scholar]
- 3.Huang D, Sherman BT, Lempicki RA. Systematic and integrative analysis of large gene lists using david bioinformatics resources. Nat. Protoc. 2009;4:44–57. doi: 10.1038/nprot.2008.211. [DOI] [PubMed] [Google Scholar]
- 4.Rossant C, Kadir SN, Goodman DFM. Spike sorting for large, dense electrode arrays. Nat. Neurosci. 2016;19:634–641. doi: 10.1038/nn.4268. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 5.Moosmann F, Nowak E, Jurie F. Randomized clustering forests for image classification. IEEE Trans. Pattern Anal. Mach. Intell. 2008;30:1632–1646. doi: 10.1109/TPAMI.2007.70822. [DOI] [PubMed] [Google Scholar]
- 6.Ducournau A, Bretto A, Rital S, Laget B, et al. A reductive approach to hypergraph clustering: An application to image segmentation. Pattern Recognit. 2012;45:2788–2803. doi: 10.1016/j.patcog.2012.01.005. [DOI] [Google Scholar]
- 7.Chaira T. A novel intuitionistic fuzzy c means clustering algorithm and its application to medical images. Appl. Soft Comput. 2011;11:1711–1717. doi: 10.1016/j.asoc.2010.05.005. [DOI] [Google Scholar]
- 8.Zheng M, Bu J, Chen C, et al. Graph regularized sparse coding for image representation. IEEE Trans. Image Process. 2011;20:1327–1336. doi: 10.1109/TIP.2010.2090535. [DOI] [PubMed] [Google Scholar]
- 9.Chakrabarti S. Data mining for hypertext: A tutorial survey. ACM SIGKDD Explor. Newsl. 2000;1:1–11. doi: 10.1145/846183.846187. [DOI] [Google Scholar]
- 10.Chang M, Chen L, Hung L, et al. Exact algorithms for problems related to the densest k-set problem. Inf. Process. Lett. 2014;114:510–513. doi: 10.1016/j.ipl.2014.04.009. [DOI] [Google Scholar]
- 11.Martin, E., Hans-Peter, K., Jorg, S., et al. A density-based algorithm for discovering clusters in large spatial databases with noise. In Proceedings of the 2nd International Conference on Knowledge Discovering in Databases and Data Mining, 122–128 (1996).
- 12.Feynman RP. Simulating physics with computers. Int. J. Theor. Phys. 1982;21:467–488. doi: 10.1007/BF02650179. [DOI] [Google Scholar]
- 13.Shor PW. Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM J. Comput. 1997;26:1484–1509. doi: 10.1137/S0097539795293172. [DOI] [Google Scholar]
- 14.Grover, L. K. A fast quantum mechanical algorithm for database search. In Proceedings of the 28th Annual ACM Symposium on the Theory of Computing, 212–219 (1996).
- 15.Wiebe N, Braun D, Lloyd S. Quantum algorithm for data fitting. Phys. Rev. Lett. 2012;109:050505. doi: 10.1103/PhysRevLett.109.050505. [DOI] [PubMed] [Google Scholar]
- 16.Schuld M, Sinayskiy I, Petruccione F. Prediction by linear regression on a quantum computer. Phys. Rev. A. 2016;94:022342. doi: 10.1103/PhysRevA.94.022342. [DOI] [Google Scholar]
- 17.Wang G. Quantum algorithm for linear regression. Phys. Rev. A. 2017;96:012335. doi: 10.1103/PhysRevA.96.012335. [DOI] [Google Scholar]
- 18.Rebentrost P, Mohseni M, Lloyd S. Quantum support vector machine for big data classification. Phys. Rev. Lett. 2014;113:130503. doi: 10.1103/PhysRevLett.113.130503. [DOI] [PubMed] [Google Scholar]
- 19.Li Z, Liu X, Xu N. Experimental realization of a quantum support vector machine. Phys. Rev. Lett. 2015;114:140504. doi: 10.1103/PhysRevLett.114.140504. [DOI] [PubMed] [Google Scholar]
- 20.Ruan Y, Xue X, Liu H, Tan J, Li X. Quantum algorithm for k-nearest neighbors classification based on the metric of hamming distance. Int. J. Theor. Phys. 2017;56:3496–3507. doi: 10.1007/s10773-017-3514-4. [DOI] [Google Scholar]
- 21.Cheng S, Chen J, Wang L. Quantum entanglement: from quantum states of matter to deep learning. Physics. 2017;46:416–423. [Google Scholar]
- 22.Yu CH, Gao F, Wang QL, Wen QY. Quantum algorithm for association rules mining. Phys. Rev. A. 2016;94:042311. doi: 10.1103/PhysRevA.94.042311. [DOI] [Google Scholar]
- 23.Krantz P, Kjaergaard M, Yan F, et al. A quantum engineer’s guide to superconducting qubits. Appl. Phys. Rev. 2019;6:021318. doi: 10.1063/1.5089550. [DOI] [Google Scholar]
- 24.Kjaergaard M, Schwartz ME, Braumuller J, et al. Superconducting qubits: current state of play. Annu. Rev. Condens. Matter Phys. 2019;11:369–395. doi: 10.1146/annurev-conmatphys-031119-050605. [DOI] [Google Scholar]
- 25.Huang HL, et al. Superconducting quantum computing: a review. Sci. China Inf. Sci. 2020;63:1–32. [Google Scholar]
- 26.Bruzewicz CD, Chiaverini J, McConnell R, et al. Trapped-ion quantum computing: Progress and challenges. Appl. Phys. Rev. 2019;6:021314. doi: 10.1063/1.5088164. [DOI] [Google Scholar]
- 27.Dürr, C., Heiligman, M., Høyer, P., & Mhalla, M. Quantum query complexity of some graph problems. In Proceedings of the 31st International Conference on Automata, Languages and Programming, 481–493 (2004)
