Skip to main content
Scientific Reports logoLink to Scientific Reports
. 2024 Dec 4;14:30169. doi: 10.1038/s41598-024-81701-7

Quantum search algorithm on weighted databases

Yifan Sun 1,, Lian-Ao Wu 2,3,4,
PMCID: PMC11615299  PMID: 39627371

Abstract

The Grover algorithm is a crucial solution for addressing unstructured search problems and has emerged as an essential quantum subroutine in various complex algorithms. By using a different approach with previous studies, this research extensively investigates Grover’s search methodology within non-uniformly distributed databases, a scenario frequently encountered in practical applications. Our analysis reveals that the behavior of the Grover evolution differs significantly when applied to non-uniform databases compared to uniform or ‘unstructured databases’. Based on the property of differential equation, it is observed that the search process facilitated by this evolution does not consistently result in a speed-up, and we have identified specific criteria for such situations. Furthermore, we have extended this investigation to databases characterized by coherent states, confirming the speed-up achieved through Grover evolution via rigorous numerical verification. In conclusion, our study provides an enhancement to the original Grover algorithm, offering insights to optimize implementation strategies and broaden its range of applications.

Subject terms: Physics, Quantum physics, Quantum information

Introduction

The Grover algorithm, conceived by L. K. Grover in 19971, marked a significant advancement in the field of quantum computing2, particularly in addressing the challenge of query complexity. In the classical paradigm, searching an unstructured database typically necessitates n steps, where n is the size of the database. Grover’s groundbreaking algorithm, however, revolutionizes this approach by reducing the required steps to merely Inline graphic. This quantum search algorithm has emerged as a cornerstone in the development of quantum computational routines, celebrated for its ability to significantly amplify the amplitude of the quantum state that encodes the desired information. The versatility and applicative potential of the Grover algorithm have been demonstrated across a spectrum of challenging problems. For instance, it has provided innovative solutions to the satisfiability problem3, as well as in the burgeoning field of quantum machine learning4. Further applications include tackling constrained polynomial binary optimization5 and enhancing quantum amplitude estimation techniques6, showcasing a clear computational superiority over traditional methods. Recent explorations have extended the utility of the Grover algorithm7 to the domain of adiabatic quantum computing810, underscoring its adaptability and relevance in the rapidly evolving landscape of quantum research. This paper specifically delves into the algorithm’s seminal application in database searching, highlighting its transformative impact and ongoing significance in the quest for efficient quantum computing solutions. Through this focus, we aim to illuminate the enduring value and broad applicability of Grover’s algorithm1,11,12, from its initial proposal to its current and potential future contributions to quantum computing and beyond.

The search problem unfolds as follows: within a given database, each element is distinctly indexed. When the database is of finite size, locating a specific element necessitates iterative queries to its index. Typically, the query count scales with the database size. Grover’s seminal work explored this quandary in the realm of quantum computing. Through specific evolution operators, the amplitude of the basis state housing the target data can be boosted to unity. The steps required for such enhancement scale proportionally to the square root of the database size, ensuring a guaranteed quadratic acceleration. This concept has been integrated into numerous platforms1315, with additional advancements showcased in recent proposals1619.

The initial discourse on the search dilemma predominantly centers on managing unstructured databases, following a conventional approach in theoretical computational discussions that remains detached from specific physical contexts. However, as we transcend the limits imposed by current computing platforms and strive for advancements, particularly in the evolution of novel computing architectures, data encoding states may not uniformly distribute. Thus, delving into the potential enhancements of the Grover search algorithm in such scenarios presents an opportunity to broaden its utility and applicability significantly.

Moving forward, we conduct an analysis of the aforementioned issue. The database under scrutiny is comprehensive, characterized by distributions spanning various types. Similar topics have been discussed before20,21, in which a general form of the Grover evolution is given. Different from the previous method, we analysis the necessary steps for executing the search operation by using the asymptotic differential equation of the algorithm. By using the property of differential equation, we methodically identify the prerequisites for achieving acceleration through Grover evolution. Subsequently, we showcase two illustrative examples to elucidate our observations: the first example validates the harmony between our theory and Grover’s established results, while the second one exemplifies that employing the Grover search on a database governed by coherent state probabilities leads to acceleration compared to conventional methods. It indicates our algorithms can be carried out in non-universal quantum computation like linear optical system used in implementing Boson sampling. The initial state can be prepared as weak coherent states depending on cutting of N. This is followed by an elaborate exposition of our overarching methodology.

Grover search on weighted databases

Consider a database Inline graphic, with integer M. An arbitrary element Inline graphic in the database is a real number, which represents a certain characteristic of objects. In the original version of search problems, all Inline graphics are distinct to each other. A example of the problem could be as follows. One could consider the above database as a collection of the length data of many pencils, and Inline graphic represents the length of the nth pencil. If the length of pencils are measured precisely enough, there will be no pencils with the same lengths. Hence, the search for the series number of the pencil with a particular length in the database could be the described by the search problem of this kind. However, in practice, some characters of the objects do not need to be handled at an extremely high precision. Going back to the pencil example, if one re-perform the statics and categorize the lengths of the pencils into several length intervals, there would be more than one pencil in one interval. Furthermore, if the pencils whose lengths fall into one length interval are numbered identically, a natural target under this case could be finding the series number of a demanded length interval. This goes into the problem of what we called the weighted database search. Formally, suppose that there are N distinguished types of elements in a database, denoted by Inline graphic. Therefore, the database can be given by Inline graphic, where Inline graphic represent the proportions of distinct characteristics Inline graphic in the total database. An illustration of the search problem on the databases is given by Fig. 1.

Fig. 1.

Fig. 1

An illustration of the search problem on unstructured database (a) and weighted database (b). “0” and “1” mark the ordinary and the target data sample respectively. The widths of the squares of the samples represent the proportions.

To search for a certain characteristics in Inline graphic, Inline graphic by using classical algorithms, the required number of steps s is proportional to the reciprocal number of its proportion. Therefore, in general, s satisfies

graphic file with name M12.gif 1

To perform the same task by using Grover evolution22, one can consider the following state

graphic file with name M13.gif 2

Inline graphic is a set of orthonormal basis and Inline graphic is a superposition of them. P(n) is the complex amplitude of the basis state Inline graphic, yielding that Inline graphic, and Inline graphic. Notice that Eq. (2) can represent a state whose amplitudes of each basis state can be arbitrary. In the usual consideration of quantum computing, it is not always easy to prepare a state according to the distribution of given database. It is known that, for instance, the quantum state for encoding unstructured database, as considered by Grover, can be efficiently prepared by Hadamard gates on qubits. Also, the database distributed like a coherent state, which is an exponential distribution modified by several factors, can be prepared by displacements on harmonic oscillators in a continues-variable quantum computing setup. We will discuss the two cases later. In a general sense, a quantum computer could be any of quantum systems that can be well controlled. Hence, the initial state of the system, such as its ground states, might be not distributed uniformly in its natural basis. This could also be applied for searching the database with the same or close distribution, as indicated by Eq. (2). Because our aim in this work is discussing the Grover search based on Eq. (2) in a general sense, we do not go further into the preparation strategy of states with other distribution. We would like to discuss them broadly in our future investigation.

According to the idea of Grover search, the amplitude of the target state can be amplified by repetitive evolution so that the search can be completed by only one step. Then, the total step number of performing the search equals to the repeat number of the evolution operators. Suppose that the target state is Inline graphic, the basic two operators for evolution are defined by

graphic file with name M20.gif 3

The amplification operator required by Grover search is defined by Inline graphic. Suppose that after performing G for t times on Inline graphic, the whole state evolves to Inline graphic. Then, the step number for searching Inline graphic is given by t.

The next key problem is to compare the step numbers of the two methods, validating whether a speed-up exists. For such purpose, we analyze the above evolution under G as follows. Applying G once to the state Inline graphic, one has

graphic file with name M26.gif 4

Furthermore, if G is applied for r times, a recurrence relation can be obtained,

graphic file with name M27.gif 5

where

graphic file with name M28.gif 6

For sufficient large r, the amplification leads to that Inline graphic and Inline graphic. This asymptotic behavior can be seen by approximating Inline graphic with a continuous function Inline graphic with real variable x, such that Inline graphic. Apply the approximation Inline graphic, and the same for Inline graphic. Thereafter, two partial differential equations can be obtained, shown by

graphic file with name M36.gif 7

Substitute the second equation to the first equation, one has

graphic file with name M37.gif 8

Notice that such equation is a standard second-order partial differential equation. Its solution has been discussed thoroughly. In general, the solution of can be given by

graphic file with name M38.gif 9

where Inline graphic with Inline graphic. Inline graphic and Inline graphic are constants depending on initial conditions. Inline graphic and Inline graphic are the real and imaginary part of complex Inline graphic when Inline graphic. In our case, Inline graphic so that Inline graphic. The case when Inline graphic means that state Inline graphic can be searched with one step, which is trivial and is not considered here. Thus, the solution to Eq. (8) is

graphic file with name M51.gif 10

where Inline graphic. The dynamics given by Eq. (10) is a damping oscillation. The period of the oscillation is Inline graphic. It indicates that in the time of T, there is a moment when Inline graphic takes its maximum, approaching to be one. Therefore, the steps number for the search is in the order of T. The speedup of the Grover search under the condition can be verified by comparing the order of T and s. More strictly, one has the condition

graphic file with name M55.gif 11

The condition given by Eq. (11) indicates a global speed up over the classical treatment. Notice that we omit the constant factor Inline graphic because it does not affect the order. If one limits the problem to searching the kth element in the database, the condition can be loosen to

graphic file with name M57.gif 12

Then, because |P(k)| is not zero generally,

graphic file with name M58.gif 13

Such a condition indicates a local speed up over the classical treatment, which is only effective for searching one element. Obviously, the inequality holds when Inline graphic. It is easy to satisfy such condition when N is sufficiently large.

In what follows, we provide two specific examples of the above general analysis. In the first example, we show that the original unstructured search by Grover’s idea can be obtained from our consideration. In the second, we show the results when the distribution of database is that of a coherent state. We also check the effectiveness of the contentious form given by Eq. (7) in the two examples.

Two examples

I. Back to unstructured search. The case of unstructured search can be easily obtained by setting Inline graphic. The solutions of Eq. (6) and the approximation in this example are compared in Fig. 2, when Inline graphic. The amplitude of Inline graphic and Inline graphic are obtained by solving Eq. (6) step-by-step under the condition Inline graphic and Inline graphic. The approximation Inline graphic and Inline graphic are obtained by using the 3rd equation of Eqs. (9) under the condition Inline graphic and Inline graphic. From the plots, it can be seen that the locations of the maximum of Inline graphic and Inline graphic are nearly the same with those of Inline graphic and Inline graphic. Hence, the approximation is valid.

Fig. 2.

Fig. 2

The plot of (a) the amplitude Inline graphic and (b) Inline graphic obtained by solving Eq. (6) when Inline graphic. The plot of the approximation Inline graphic and Inline graphic obtained by solving Eq. (7) are shown in (c) and (d).

Then, the scale of the step number for the search problem can be estimated by

graphic file with name M79.gif 14

When N is big enough, one has Inline graphic. Therefore, the step number for Grover search is in the order of Inline graphic. It worth mentioning that, in such a case, because Inline graphic for big N, the factor Inline graphic is close to one. It guarantees Inline graphic finally approaches to one.

The classical search algorithm on the unstructured database is basically checking each elements in the database one by one. Because the probability of finding one element is 1/N, the step number for the searching by classical treatment is in the order of N. Hence, a quadratic speedup can be observed by comparing the order of the two step numbers.

II. Grover search by using coherent state. In this part, we consider the case when the distribution of database Inline graphic satisfies (or partially satisfies) the distribution of the coherent state. The coherent state in the particle number basis can be expressed by

graphic file with name M91.gif 15

where Inline graphic is a complex number. Such a state is a natural state in optical amplification cavity. Notice that there are infinite basis states in the coherent state. Therefore, for finite databases, one can consider encoding them into parts of the state (15). Define the N-dimensional database state Inline graphic,

graphic file with name M94.gif 16

where Inline graphic is the normalization factor, given by

graphic file with name M96.gif 17

Thus, for a target state Inline graphic in the database, one has,

graphic file with name M98.gif 18

Notice that, when Inline graphic is large enough, Inline graphic slowly varies with k. Thus, the case will go back to the unstructured database, as shown in the first part of this section. When Inline graphic is not large enough, the magnitude of |P(k)| is given by Inline graphic and Inline graphic. We numerically provide several cases shown in Fig. 3. The solutions of Eq. (6) and the approximation in this example are compared in Fig. 4. The searching target is the basis state when Inline graphic, and the rest parameters are set to be the same with those for Fig. 3. The amplitude of Inline graphic (Inline graphic) and its approximation Inline graphic (Inline graphic) are obtained by the same method of the first example. The initial conditions are also the same. From the plots, it can be seen that the locations of the maximum of Inline graphic and Inline graphic are also approximately the same with those of Inline graphic and Inline graphic. The major difference lies in the damping of Inline graphic and Inline graphic, resulted from the factor Inline graphic. In the finite cases, one could just neglecting the factor for the estimation of the locations of the maximum. Because such a factor has no affection on the locations. Further, as in the first example, it can be seen that the factor approaches to one when |P(k)| is small enough. Such a condition is better met if the database is large. Therefore, the method can be used to estimate the scale of step number when the size of database goes to infinity.

Fig. 3.

Fig. 3

The probability distribution of Inline graphic when Inline graphic. We take Inline graphic and Inline graphic. The cases of other Inline graphic and N are similar.

Fig. 4.

Fig. 4

The plot of (a) the amplitude Inline graphic and (b) Inline graphic obtained by solving Eq. (6) when P(k) is given by Eq. (18). The plot of the approximation Inline graphic and Inline graphic obtained by solving Eq. (7) are shown in (c) and (d). We set the target state to be the one when Inline graphic, and the other parameter setup is the same with the plot in Fig. 3.

By substituting the probability distribution to Inline graphic, the order of the step number can be estimated by the magnitude of Inline graphic. The step number of the classical treatment is obtained by Inline graphic when searching for Inline graphic. In order to show a clear comparison, we firstly compare the reciprocal of the step numbers of the two cases, and the results is shown in Fig. 5. In fact, reciprocal of the step number in classical search for Inline graphic is just its probability Inline graphic. Extended from the classical concepts, the reciprocal of the step number in Grover search, which is Inline graphic, represents an effective probability of “searching for Inline graphic”. The comparison between the two reciprocals are equivalent to the comparison of the step number, but with an inverse trend. The smaller step number indicates a larger reciprocal, and vice versa. From the results, we can see that in general, the Grover evolution is a better strategy over the classical treatment. An exception occurs in Fig. 5a, when searching for the first element. This is because Inline graphic is relatively small in such a case. We secondly compare the natural logarithm of the step numbers of the cases, and the results are shown in Fig. 6. By Fig. 6, a clear advance in steps number can be observed, and the exception also occurs in (a). The results in Figs. 5 and 6 indicate that the Grover search on a database distributed in the probability given by the coherent state is able to show an advance over the classical methods. According to our conditions in the second section, such an advance belongs to the local speedup.

Fig. 5.

Fig. 5

The comparison of the reciprocals of step numbers when searching a basis state Inline graphic (Inline graphic) by classical and Grover treatments. The y-axis represents the reciprocal of the step numbers. The value of Inline graphic is 0.8 in (a), 1.6 in (b), 2.4 in (c), and 3.2 in (d).

Fig. 6.

Fig. 6

The comparison of the natural logarithm of step numbers when searching a basis state Inline graphic (Inline graphic) by classical and Grover treatments. The y-axis represents the natural logarithm of the step numbers. The value of Inline graphic is also 0.8 in (a), 1.6 in (b), 2.4 in (c), and 3.2 in (d).

Conclusion

By using the property of differential equation, we investigate the application of Grover’s algorithm for weighted database searches, a prevalent scenario in practical settings. We calculate the requisite steps for the Grover search and contrast these calculations with classical methodologies. Our analysis differs from the previous method, by considering the asymptotic behaviour of the Grover evolution. This allows us to introduce the tools for analysing differential equations, so that performance of the Grover search on unstructured database can be well assessed. Through detailed analysis, we pinpoint the specific conditions conducive to acceleration through Grover’s algorithm. To illustrate our discoveries, we showcase two compelling examples. The first example validates our theoretical framework by aligning closely with Grover’s seminal outcomes. In the second example, we demonstrate how implementing Grover’s search on a database governed by a probability distribution resembling a coherent state yields significant speed enhancements compared to traditional methods. Meanwhile, we specify that the approximation strategy are effective in the samples, by comparing the results with the explicit solutions of the difference Eq. (6). These results represent a significant advancement of analysing Grover algorithm, enriching its implementation strategies and broadening its scope of potential applications.

Acknowledgements

This work was funded by MCIN/AEI /10.13039/501100011033 (No. PID2021-126273NB-I00), by “ERDF A way of making Europe”, and by the Basque Government through Grant No. IT1470-22. We also acknowledge the support by National Natural Science Foundation of China (No.11904022). This project has also received support from the Spanish Ministry for Digital Transformation and of Civil Service of the Spanish Government through the QUANTUM ENIA project call - Quantum Spain, EU through the Recovery, Transformation and Resilience Plan-NextGenerationEU within the framework of the Digital Spain 2026.

Author contributions

The idea is initialized by L.-A.W. The theoretical derivation is performed by Y.S. All authors reviewed the manuscript.

Data availibility

The datasets used and/or analysed during the current study available from the corresponding author on reasonable request.

Footnotes

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Contributor Information

Yifan Sun, Email: yfsun@bit.edu.cn.

Lian-Ao Wu, Email: lianao.wu@ehu.es.

References

  • 1.Grover, L. K. Quantum mechanics helps in searching for a needle in a haystack. Phys. Rev. Lett.79, 325 (1997). [Google Scholar]
  • 2.Feynman, R. P. Simulating physics with computers. Int. J. Theor. Phys.21, 467 (1982). [Google Scholar]
  • 3.Karp, R. M. Reducibility Among Combinatorial Problems, in Complexity of Computer Computations 85–103 (Springer, Berlin, 1972). [Google Scholar]
  • 4.Wiebe, N., Kapoor, A., & Svore, K. Quantum perceptron models. arXiv:1602.04799.
  • 5.Gilliam, A., Woerner, S. & Gonciulea, C. Grover adaptive search for constrained polynomial binary optimization. Quantum5, 428 (2021). [Google Scholar]
  • 6.Brassard, G., Hoyer, P., Mosca, M. & Tapp, A. Quantum amplitude amplification and estimation. AMS Contemp. Math.305, 53 (2002). [Google Scholar]
  • 7.Ren, F.-H., Wang, Z.-M. & Wu, L.-A. Accelerated adiabatic quantum search algorithm via pulse control in a non-Markovian environment. Phys. Rev. A102, 062603 (2020). [Google Scholar]
  • 8.Wu, L.-A., Byrd, M. S. & Lidar, D. A. Polynomial-time simulation of pairing models on a quantum computer. Phys. Rev. Lett.89, 057904 (2002). [DOI] [PubMed] [Google Scholar]
  • 9.Pyshkin, P. V., Luo, D.-W., Jing, J., You, J. Q. & Wu, L.-A. Expedited holonomic quantum computation via net zero-energy-cost control in decoherence-free subspace. Sci. Rep.6, 37781 (2016). [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 10.Sun, Y., Zhang, J.-Y., Byrd, M. S. & Wu, L.-A. Trotterized adiabatic quantum simulation and its application to a simple all-optical system. New J. Phys.22, 053012 (2020). [Google Scholar]
  • 11.Tezuka, H., Nakaji, K., Satoh, T. & Yamamoto, N. Grover search revisited: Application to image pattern matching. Phys. Rev. A105, 032440 (2022). [Google Scholar]
  • 12.Reitzner, D. & Hillery, M. Grover search under localized dephasing. Phys. Rev. A99, 012339 (2019). [Google Scholar]
  • 13.Brickman, K.-A. et al. Implementation of Grover’s quantum search algorithm in a scalable system. Phys. Rev. A72, 050306(R) (2005). [Google Scholar]
  • 14.Figgatt, C. et al. Complete 3-qubit Grover search on a programmable quantum computer. Nat. Commun.8, 1918 (2017). [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 15.Vemula, D. R., Konar, D., Satheesan, D., Kalidasu, S. M., & Cangi, A. A scalable 5,6-qubit Grover’s quantum search algorithm. arXiv: 2205.00117.
  • 16.Gustiani, C. & DiVincenzo, D. P. Blind three-qubit exact Grover search on a nitrogen-vacancy-center platform. Phys. Rev. A104, 062422 (2021). [Google Scholar]
  • 17.Pan, N., Chen, T., Sun, H. & Zhang, X. Electric-circuit realization of fast quantum search. Research2021, 9793071 (2021). [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 18.Ji, T., Pan, N., Chen, T. & Zhang, X. Fast quantum search of multiple vertices based on electric circuits. Quantum Inf. Proc.21, 172 (2022). [Google Scholar]
  • 19.Ji, T., Pan, N., Chen, T. & Zhang, X. Quantum search of many vertices on the joined complete graph. Chin. Phys. B.31, 070504 (2022). [Google Scholar]
  • 20.Biham, E., Biham, O., Biron, D., Grass, M. & Lidar, D. A. Grover’s quantum search algorithm for an arbitrary initial amplitude distribution. Phys. Rev. A60, 2742 (1999). [Google Scholar]
  • 21.Biham, E. et al. Analysis of generalized Grover quantum search algorithms using recursion equations. Phys. Rev. A63, 012310 (2000). [Google Scholar]
  • 22.Nielsen, M. A. & Chuang, I. L. Quantum Computation and Quantum Information (Cambridge University Press, Cambridge, 2000). [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Data Availability Statement

The datasets used and/or analysed during the current study available from the corresponding author on reasonable request.


Articles from Scientific Reports are provided here courtesy of Nature Publishing Group

RESOURCES