Next Article in Journal
Digital Twin-Based Smart Feeding System Design for Machine Tools
Previous Article in Journal
MIVNDN: Ultra-Short-Term Wind Power Prediction Method with MSDBO-ICEEMDAN-VMD-Nons-DCTransformer Net
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Finding All Solutions with Grover’s Algorithm by Integrating Estimation and Discovery

by
Sihyung Lee
1,* and
Seung Yeob Nam
2
1
School of Computer Science and Engineering, Kyungpook National University, Daegu 41566, Republic of Korea
2
Department of Information & Communication Engineering, Yeungnam University, Gyeongsan 38541, Republic of Korea
*
Author to whom correspondence should be addressed.
Electronics 2024, 13(23), 4830; https://doi.org/10.3390/electronics13234830
Submission received: 2 November 2024 / Revised: 28 November 2024 / Accepted: 5 December 2024 / Published: 6 December 2024
(This article belongs to the Section Computer Science & Engineering)

Abstract

:
Grover’s algorithm leverages quantum computing to efficiently locate solutions in unstructured search spaces, outperforming classical approaches. Since Grover’s algorithm requires prior knowledge of the number of solutions (M) within a search space of size N, previous studies assume M is estimated beforehand and focus on identifying all solutions. Here, we propose a two-step process that integrates both the estimation of M and the discovery of the solutions, optimizing the interactions between the two steps. To enhance efficiency, the estimation step captures as many solutions as possible, leaving the discovery step to focus on the remaining ones. To ensure accuracy, the discovery step continues searching until the probability of finding additional solutions becomes sufficiently low. We implemented and evaluated our methods, showing that over 80% of solutions were found during the estimation phase, allowing the discovery phase to conclude earlier, while identifying over 99% of solutions on average. In theory, the process requires N M × log(M) Grover’s iterations in the worst case, but in practice, it typically terminates after iterations proportional to N . We expect that our methods will be applicable to various search problems and inspire further research on efficiently finding all solutions.

1. Introduction

Grover’s algorithm [1] provides an efficient method for solving general search problems using quantum computers. In a search space containing N items with no clues about the solution’s location, a classical computer would need to examine N/2 items on average to find the solution. The process of determining whether an item is the solution is referred to as “calling the oracle function”, where the oracle represents the logical conditions that verify a solution. In contrast, Grover’s algorithm requires oracle calls proportional to N . To accomplish this, Grover’s algorithm represents the search space using n = ⎡log2(N)⎤ qubits, initializing them in an equal superposition, so that the probability of measuring each element is 1/N. The algorithm then prepares a quantum circuit known as Grover’s iterator, with the oracle, designed according to the search objective as its major component. This circuit is applied repeatedly to the qubits, increasing the probability of measuring the solution to above 90%. The optimal number of repetitions that maximizes this probability is shown to be ⎣ π /4 × N ⎦ [2], which explains why the algorithm requires oracle calls proportional to N .
Grover’s algorithm can be applied not only when a single solution exists but also when multiple solutions are present. Specifically, when there are M(≥1) solutions, by adjusting the number of repetitions to ⎣ π /4 × N / M ⎦ [2], the algorithm can find one of the M solutions with high probability. This optimal number of repetitions requires prior knowledge of the solution count M. Consequently, various studies have proposed methods to estimate M [3,4,5,6], with a seminal work being Quantum Counting [7]. Building on these works, assuming M is known beforehand, other studies have developed methods to construct Grover’s iterator for various search objectives [8,9,10,11,12,13,14,15,16,17,18,19,20,21] with the goal of finding one among multiple solutions. Additionally, given that M is known and Grover’s iterator is set for a particular search objective, some studies have proposed methods to find all M solutions in general search problems [22,23]. Finding all possible solutions, as opposed to one solution, provides a more comprehensive view of the search space and solutions, and we list examples of uses cases in Table 1.
Our work also introduces methods to identify all M solutions rather than stopping at a single one. While existing studies either estimate M or find solutions based on that estimate, we present a comprehensive process for uncovering all solutions: (Step 1) a method to estimate M and (Step 2) a method to discover all M solutions based on this estimate. In particular, we propose optimizations to improve the efficiency of the entire process by ensuring that Steps 1 and 2 streamline each other.
Integrating the two steps involves several challenges. Table 2 outlines these challenges and our solutions. First, accurately estimating the solution count M is essential, as the optimal number of Grover’s iterations depends on M. Second, we must discover all M solutions without missing any, based on the estimated M. Lastly, we aim to perform both steps efficiently, minimizing delays. To achieve this, we designed the two steps to complement each other. Specifically, we find as many solutions as possible during the estimation of M (Step 1) so that the subsequent step (Step 2) only needs to find the remaining solutions. Furthermore, we continue the search until the probability of remaining solutions becomes sufficiently low, considering the possibility that M may have been slightly under- or overestimated in Step 1. Overall, we show that these two steps find most solutions with oracle calls proportional to N in practice, with the worst-case N M × log(M) being rare.
We list our main contributions as follows:
  • We propose an integrated process that combines estimating M and finding all M solutions, optimizing these steps together. The initial step of estimating M can also be used independently (e.g., for finding one or a subset of solutions).
  • We implemented the proposed methods and demonstrated their effectiveness across various search space sizes, from N = 23 to 210. Our results show that the first step estimates M more quickly than an existing method while maintaining the same level of accuracy. Additionally, we demonstrated that the combined steps take oracle calls proportional to N M × log(M) in the worst case, but typically find nearly all solutions with oracle calls proportional to N .
  • We have made our implementation publicly available, enabling researchers to reuse and extend our work (https://github.com/sihyunglee26/Find-All-Solutions-24 (accessed on 1 November 2024)).
The rest of the paper is organized as follows: Section 2 provides background information on Grover’s algorithm and reviews related works. Section 3 details our proposed methods. Section 4 evaluates the speed and accuracy of our methods compared to related work. Finally, Section 5 concludes the paper and outlines future directions. Key terms used in the paper are summarized in Table 3.

2. Background and Related Work

In this section, we review related works by grouping them into three categories. First, in Section 2.1, we discuss the fundamental studies on Grover’s algorithm, including its purpose and the steps it comprises. Second, in Section 2.2, we present existing studies on estimating the number of solutions, a necessary step before applying Grover’s algorithm. Lastly, in Section 2.3, we describe previous research that utilizes Grover’s algorithm in scenarios where multiple solutions exist. Readers already familiar with Grover’s algorithm may prefer to begin with Section 2.2.

2.1. Fundamentals of Grover’s Algorithm

Grover’s algorithm [1] is designed to find a target item that satisfies a given condition within an unstructured search space. ‘Unstructured’ means that there are no clear hints (or one cannot easily find hints) about which item is more likely to be the target. In such cases, if the search space contains N items, a classical computer must search through N/2 items on average, requiring oracle calls proportional to N. The oracle, in this context, refers to the logical conditions used to verify a solution. Grover’s algorithm, however, reduces the number of oracle calls to N by leveraging the capabilities of a quantum computer.
Grover’s algorithm consists of four stages, as shown in Figure 1. In stage 0, the algorithm maps the N items in the search space to n = ⎡log2(N)⎤ qubits. For example, N = 8 items are mapped to n = 3 qubits, where ‘000’ through ‘111’ represent each of the 8 items, respectively. In stage 1, the algorithm transforms the n qubits into an equal superposition, giving each item an equal probability of being measured. This stage is denoted as Hn, as n Hadamard operators are used to create the superposition. In stage 2 (denoted by G), the algorithm applies Grover’s iterator to the n qubits, amplifying the probability of the target item and reducing that of the other items. Grover’s iterator is applied repeatedly until the probability of the target item is sufficiently high (typically over 90%). In stage 3 (denoted by M), the algorithm measures the qubits, which are highly likely to be the target item, given the operations performed in stage 2. By repeating the procedure several times, one can pinpoint the target item with a high level of certainty.
Stage 2 of Grover’s algorithm, known as Grover’s iterator, is further divided into two substages: the oracle and the amplification (represented by pink and yellow boxes in Figure 1, respectively). The oracle selectively inverts the sign of items that meet the target condition. The amplification flips the amplitude of the items around their collective mean value. The combination of these two operations results in magnifying the amplitude of the target item while decreasing that of the others.
Figure 2 shows an example when N = 8 and the target item is ‘100’. The target item is shown in pink, and the others are in gray. Before applying stage 2, the 8 items have an equal amplitude of 1 / 2 2 (Figure 2a). Note that the probability of an item is the square of its amplitude, so each item has an equal probability of 1/8, summing up to 1. The first application of the oracle flips the amplitude of the target item (Figure 2b), and the subsequent application of the amplification flips the items around their collective mean, 3 / 8 2 , amplifying the target compared to the others (Figure 2c). The second application of the oracle again flips the target item’s sign (Figure 2d), and the amplification flips the items around their mean, this time 1 / 16 2 , further magnifying the amplitude of the target item (Figure 2e). Since the probability of the target item is now over 94.53%, stage 3 is highly likely to measure this target.
Existing research demonstrates how to implement both the oracle and the amplification process using quantum operators for various search problems. For the oracle, previous studies provide implementations for a wide range of applications: finding an interpretation that satisfies a Boolean formula (Boolean satisfiability problems) [8], finding a key to decrypt an encrypted message [9,10], detecting patterns in graphs [11] and images [12], solving Hamiltonian-cycle [14], k-coloring [15], list-coloring [16], chromatic number [17], vertex-cover [18], exact-cover [19], and dominating-set [20] problems, identifying pure Nash equilibria in graphical games [21], and discovering materials that meet specific chemical properties [13]. Additionally, Seidel et al. present a general method for encoding search problems into an oracle [24]. Many of these studies focus on constructing a compact implementation of the oracle with fewer gates and shallower circuits. This is important because the efficiency of Grover’s algorithm largely depends on the complexity of the oracle, which must be repeatedly applied. Furthermore, on current quantum hardware, error rates tend to increase with the number of gates and the depth of circuits.
For the amplification, previous studies present methods for implementing it on various quantum hardware and simulators for arbitrary sizes of search spaces [25,26,27]. In our experiments, described in Section 4, we utilize the method implemented with IBM’s Qiskit library [27].
Grover’s iterator (i.e., Stage 2 of Grover’s algorithm) must be applied one or more times depending on the size of the search space. The correct number of iterations maximizes the probability of identifying the target item, while an incorrect number reduces this probability. Previous studies have shown that this probability follows the square of a sine function, meaning that it oscillates as the number of iterations increases [28]. The minimum number of iterations that maximizes the probability is given by ⎣ π /4 × N ⎦ [2]. For example, when N = 8, as illustrated in Figure 2, the optimal number of iterations is ⎣ π /4 × 8 ⎦ = 2. Thus, the first iteration leads to a target probability of ( 5 / 4 2 )2 = 78.12% (Figure 2c), and the second iteration further increases the probability to the maximum of ( 11 / 8 2 )2 = 94.53% (Figure 2e). Adding another iteration would then decrease the probability.
The equation ⎣ π /4 × N ⎦ assumes that a single target exists in the search space. However, when multiple items simultaneously meet the target criteria, the number of required iterations changes. Specifically, when there are M target items, the optimal number of iterations is ⎣ π /4 × N / M ⎦ [2]. For instance, if N = 8 and M = 2 then ⎣ π /4 × 8 / 2 ⎦ = 1 iteration maximizes the probability of measuring a target, differing from the single-target scenario.
Therefore, knowing the number of target items M is essential for correctly computing the optimal number of Grover’s iterations and efficiently finding the targets. This necessity has led to studies aimed at estimating M, which are discussed in the next subsection (Section 2.2).

2.2. Estimating the Number of Solutions

Quantum Counting [7] is a seminal technique for estimating the number of target items, M. This method is similar to Grover’s algorithm in that it initializes qubits into an equal superposition and repeatedly applies Grover’s iterators. However, Quantum Counting applies Grover’s iterators a number of times proportional to a power of two and then measures the resulting phase shifts using the inverse Quantum Fourier Transform (QFT) [29]. Since the amount of phase shifts is related to M, the measurement with inverse QFT is used to estimate M.
Subsequent works on estimating M build upon Quantum Counting but offer improvements mainly in two aspects. Some methods replace QFT with simpler circuits [3,4] as QFT becomes increasingly complex to implement with larger search spaces. Other approaches modify the implementation of Quantum Counting to reduce errors in current quantum hardware, such as by minimizing the use of operators that cause error-prone entanglement [5,6]. While these advancements reduce implementation costs and errors, they do not significantly speed up Quantum Counting, leaving the time complexity largely unchanged.
Our proposed methods differ from previous works in two key ways. First, none of the prior methods design the estimation process with the goal of using the result to find all target items. In contrast, our approach links the estimation process with the subsequent task of finding all target items, thereby streamlining the entire procedure. Specifically, we identify a substantial subset of target items while estimating M, allowing us to quickly find the remaining targets afterward. Second, our methods improve the speed of quantum-counting-based estimation techniques. In our evaluation (Section 4.1), we demonstrate that our methods estimate M with fewer Grover’s iterations than Quantum Counting (e.g., 226 vs. 1270 Grover’s iterations when N = 512) while maintaining the same level of accuracy.

2.3. Applications of Grover’s Algorithm for Multiple Solutions

Many previous studies utilizing Grover’s algorithm address cases where multiple targets exist. Specifically, they assume that the number of targets, M, is known beforehand and focus on finding one among these M targets. Some works demonstrate the process of preparing oracles for multiple targets in various application domains, including Boolean satisfiability problems [8], cryptanalysis [9,10], graph analysis [11], pattern recognition [12], and materials discovery [13]. Other studies improve the efficiency of searching for targets by exploiting parallelism, such as by dividing the search process into multiple sub-jobs that run in parallel and then combining their results [28,30]. In summary, these previous works aim to efficiently find one target among many, given that the number of target M is known. However, they do not explain how to efficiently find all targets or optimize the search in conjunction with the estimation of M. In contrast, our proposed methods aim to find all M targets while also devising a method to estimate M, such that this estimation process helps to more efficiently find all targets.
Other research proposes methods to find one among many targets without knowing or estimating M [31,32,33]. These works repeatedly apply Grover’s iterator, similar to the original Grover’s algorithm, but they leverage additional qubits and circuits to determine whether the probability of finding targets is sufficiently high; if so, they stop the iterations and measure the qubits to obtain a target with high probability. However, these methods also aim to identify one target and do not describe how to extend their approach to efficiently find all targets. Consequently, using these methods to find all targets would require Mlog(M) repetitions on average, as described in the coupon collector’s problem [34], because the same target may be collected multiple times. In contrast, our proposed methods require fewer iterations. This efficiency is achieved by identifying a substantial subset of the targets during the estimation of M, so only the remaining targets need to be found during the search. Additionally, our estimation process is lightweight compared to the search process and thus does not add significant overhead.
Some studies attempt to discover all targets in their experiments [18,19,20]. They assume that M is known beforehand by using estimation methods like Quantum Counting [7]. Based on this estimated value, M ^ , the methods run a large number of shots of Grover’s algorithm (e.g., 8000 shots for M ^ = 2) plot a histogram of the measured values, and select the most frequently measured M ^ values. Although these experiments correctly found all solutions, the studies do not explain how to choose the optimal number of shots to minimize the effort needed to discover all targets. Additionally, the studies do not address cases where M ^ deviates from the actual M value, assuming instead that M ^ is correctly estimated. In contrast, our proposed methods design both the estimation and discovery steps with consideration of their interactions and efficiency. Our estimation method identifies a significant portion of the targets, allowing the discovery step to finish quickly by searching for the remaining targets. Furthermore, our discovery method accounts for a slight deviation between M ^ and the actual M and includes a mechanism to continue searching until the probability of remaining solutions is sufficiently low.
Lastly, some studies propose methods for finding all solutions to general search problems [22,23]. These methods assume that M is correctly estimated beforehand. Based on this estimate, they find all M solutions by repeatedly applying Grover’s algorithm. Specifically, once a solution is found, they modify the oracle to prevent the discovered solution from being measured again. Our approach differs from these methods in two key ways. First, we integrate the two steps—estimating M and discovering the M solutions—and optimize them together. A significant portion of the solutions is discovered during the estimation step, allowing the discovery step to conclude quickly by identifying the remaining solutions. We also account for the possibility that M may be slightly under- or overestimated and design the discovery step to accurately find most solutions even when the estimate is imperfect. Second, we avoid modifying the oracle, as such modifications require additional gates and stages, which increase the overall complexity [3]. Since Grover’s algorithm repeatedly calls the oracle, increasing its complexity would not improve performance as intended. Additionally, on current quantum hardware, using more gates and stages raises error rates [17]. Therefore, instead of modifying the oracle, we enhance the discovery step by maximizing the number of solutions found during the estimation step.

3. Proposed Methods for Finding All Solutions

3.1. Overview of Proposed Methods

In this section, we describe our proposed methods for finding all M solutions using Grover’s algorithm. The methods comprise two steps, as illustrated in Figure 3. In Step 1, we estimate M, which represents the number of solutions in the search space. Then, in Step 2, considering the estimated value of M from Step 1, we utilize Grover’s algorithm to find all M solutions. The number of oracle calls required for Steps 1 and 2 is proportional to N and N × M × log(M), respectively. Therefore, our proposed methods overall require oracle calls proportional to N × M × log(M). In the following subsections, we delve into the details of Step 1 (Section 3.2) and Step 2 (Section 3.3).
In our proposed methods, we assume that M N , meaning that the number of solutions is significantly less than the size of the search space and not comparable to it. If M were greater than N , making it comparable to N (i.e., solutions that occur frequently within the search space), our methods based on quantum computing would not outperform those based on classical computing. For instance, if M = N/2, Grover’s algorithm would need to be applied at least N/2 times (since each application and measurement isolates one of the M solutions), requiring our methods to take time proportional to N or more. Conversely, to identify all M = N/2 solutions on a classical computer, we would need to examine at least N/2 and at most N items, resulting in a time complexity proportional to N. Therefore, under such conditions, utilizing a quantum computer does not offer a clear advantage over a classical computer. In summary, for the reasons mentioned above, we assume that M N in the subsequent subsections.

3.2. Step 1: Estimation of Solution Count, M

We estimate M by utilizing Grover’s algorithm, as follows. As outlined in Section 2.1, Grover’s algorithm begins by initializing n = ⎡log2(N)⎤ qubits into an equal superposition, ensuring that each of N items has an equal probability of being measured. The algorithm then repeatedly applies Grover’s iterator to the n qubits, gradually increasing the probability of measuring one of the M solutions. Specifically, when Grover’s iterator is applied j times then the probability of measuring one of M solutions follows the square of a sine function, as shown in (1) [28]:
P ( j ) = sin 2   ( ( 2 j + 1 )   ×   sin 1 ( M / N ) ) .
In (1), sin−1( M / N ) can be approximated by M / N , since we assume that M is much smaller than N (i.e., M ≤ N ). Consequently, Equation (1) simplifies into (2):
P ( j ) = sin 2   ( ( 2 j + 1 )   ×   M / N ) .
Under this approximation, the probability P(j) approaches 1 when the number of Grover’s iterations j equals π /4 × N / M [2].
We estimate M by utilizing the relationship between P(j) and M, as shown in (2). Specifically, we initially estimate P(j) by executing Grover’s algorithm and repeatedly measuring the qubits. Subsequently, we use this estimated value of P(j) and insert it into (2) to infer M. This procedure is summarized in Algorithm 1. The function ‘estimate_solution_count()’ (lines 17–39) estimates M, given N, n, and the oracle function for the target application. The algorithm begins by initializing n qubits into an equal superposition (line 24), setting the stage for Grover’s iterator. It then applies a single iteration (i.e., j = 1) of Grover’s iterator (line 25) and measures the qubits (line 26). This process is repeated until a number of measurements proportional to N is collected (lines 23–26). Upon completion of these measurements, we count the number of solutions among the measurements (lines 28–31) and estimate P(j = 1) based on the ratio of solutions found in the measurements (line 34). Inserting this estimated value into (2), along with j = 1, yields (3):
P ( j = 1 ) ^ = sin 2   ( ( 2 + 1 )   ×   M / N ) .
Solving (3) for M, we derive Equation (4):
M = N / 9   ×   ( sin 1 ( P ( j = 1 ) ^ ) ) 2 .
Thus, M is estimated using Equation (4) (line 35), and the function returns both the estimated value and the solutions found so far (line 39).
Algorithm 1. Algorithm for estimating solution count M
01 # Amber: Keyword, Green: Variable, Blue: Function
02 #
03 # N: Number of items to search for
04 # n: Number of qubits used to represent N items, ⎡log2(N)⎤
05 #  We assume that n > 1 (i.e., N > 2).
06 # M: Number of solutions among N items
07 #  We assume that M  N .
08 # oracle: Oracle function of target application
09 # G: Grover’s iterator for target application
10 # R: Set of measurements collected by executing Grover’s circuit
11 # S: Set of solutions that have been found so far (i.e., SR)
12 # success_count: Number of measurements where solutions are found
13 # k: Constant that determines the number of measurements (i.e., k N )
14 #  We used k = 10 in our experiments.
15 
16 # Estimate M with Grover’s iterator
17  function estimate_solution_count (N, n, oracle)
18  # Initialize circuits and variables
19  create a Grover’s iterator, G, based on n and oracle
20   R = {}, S = {}, success_count = 0
21
22  # Collect k N measurements with Grover’s iterator
23  repeat k N times:
24    initialize n qubits into an equal superposition
25    apply one iteration of G on n qubits
26    measure n qubits and store the result in R
27
28  for each measurement m in R:
29    if oracle (m) == True: # If m belongs to the solutions
30     S = S  {m}
31     success_count += 1
32
33  # Estimate the number of solutions with the measurements
34   P ( 1 ) ^ = success_count/k N # Estimated value of P(1)
35   M ^ = N/9 × (sin−1( P ( 1 ) ^ ))2 # Estimated value of M
36   M ^ = max( M ^ , |S|) # M ^ must be ≥the number of found solutions
37
38  # Return the estimated value of M and found solutions
39   return  M ^ , S
For example, let us assume that N = 1024, and we collect 10 × N = 320 measurements using the algorithm outlined inAlgorithm 1. If, among these measurements, 22 are solutions (i.e., success_count = 22), the estimated probability P ( j = 1 ) ^ = 22/320. Inserting this value into (4), we obtain the estimated value of M as 1024/9 × (sin−1 ( 22 / 320 ))2 = 8.0083598, which suggests that M is likely to be 8.
In our proposed algorithm, we estimate M by collecting a number of measurements proportional to N (lines 23–26). We take this approach because M can assume any value within the range [0, N ], given our assumption that M N . Therefore, to estimate M accurately by distinguishing among the N different potential values that M could take, we require at least N samples. In our experiments, as detailed in Section 4, we collected 10 × N samples (i.e., k = 10), which enabled us to estimate M with an average error of less than 1 for N ranging from 23 to 29.
The number of Grover’s iterations required for Step 1 is proportional to N . This is because the number of measurements we take is proportional to N , with each measurement necessitating a single iteration of Grover’s iterator (line 25) and one query of the oracle (line 29). In essence, by employing only a single iteration of Grover’s iterator rather than multiple iterations, we aim to minimize the total number of iterations required in Step 1. Furthermore, we record the solutions identified in Step 1 (line 30) and pass them to Step 2 (line 39), so that Step 2 only needs to discover the remaining solutions. In Appendix A, we derive the expected proportion of distinct solutions found in Step 1.
The proposed estimation step may resemble random sampling, where k × N samples are taken without using Grover’s algorithm. However, unlike random sampling, our method achieves a higher probability of measuring a target (as shown in (3)) compared to the random sampling probability of M/N. This is due to the application of a single iteration of Grover’s iterator prior to sampling (line 25). While one iteration does not fully maximize the target probability, it does provide an increase. In particular, the probability described in Equation (2) (i.e., P(j) = sin2 ((2j + 1) × M / N )) can be approximated as (2j + 1)2 × M/N, given that M ≤ N and j is chosen such that (2j + 1) × M / N remains small. Therefore, when a single iteration is applied prior to sampling (i.e., j = 1), the probability becomes (2 + 1)2 × M/N = 9 × M/N, resulting in a ninefold increase compared to the probability associated with random sampling. Consequently, the proposed estimation step captures more targets than random sampling, thereby reducing the workload for the subsequent discovery step.
The choice of j, the number of Grover’s iterations applied before measurement, can be determined based on the following guidelines. As analyzed in Appendix A, the expected proportion of solutions discovered in Step 1 is proportional to (2j + 1)2/ N . Consequently, as the size of search space N increases, j can be adjusted accordingly to maintain the desired proportion of solutions. However, increasing j comes at the cost of a higher total number of Grover’s iterations, calculated as k × j × N . In our experiment presented in Section 4.2, we selected j = 1, as this minimum value was sufficient to capture a substantial proportion of solutions (over 80%) for N = 23 to N = 210. For larger values of N, the proportion diminishes gradually, requiring an increase in j to slow down the rate of decrease (e.g., j = 2 for N = 214 and j = 3 for N = 216).

3.3. Step 2: Search for All M Solutions

Based on the estimated value of M obtained in Step 1, we proceed to identify all M solutions using the algorithm presented in Algorithm 2. Grover’s algorithm is applied (lines 31–32) to maximize the probability of finding one of the solutions, followed by measuring the qubits (line 33). If the oracle reveals that the measured item is one of the solutions and the item has not yet been discovered (line 34), the item is stored (line 35), and fail_count is reset to 0 (line 36), indicating the discovery of a new solution. Conversely, if the oracle shows that the measured item is not one of the remaining solutions, fail_count is incremented by 1 (line 38), signifying another unsuccessful attempt to find a new solution. This process is repeated until no new solutions are found for more than max_fail_count consecutive attempts (lines 30–38), leading us to conclude with high confidence that no further solutions exist. Finally, the function returns all the solutions found thus far (line 41).
Algorithm 2. Algorithm for finding all M solutions
01 # Amber: Keyword, Green: Variable, Blue: Function
02 #
03 # N: Number of items to search for
04 # n: Number of qubits used to represent N items, ⎡log2(N)⎤
05 #  We assume that n > 1 (i.e., N > 2).
06 # M ^ : Number of solutions estimated in Step 1
07 # S: Set of solutions that have been found so far. This set begins with
08 #  solutions found in Step 1
09 # oracle: Oracle function of target application
10 # G: Grover’s iterator for target application
11 # fail_count: Number of consecutive measurements where no new
12 #   solutions are measured
13 # max_fail_count: Threshold for fail_count. If fail_count exceeds
14 #    max_fail_count, we conclude that no new solution remains and
15 #    thus halt the algorithm.
16
17 # Find all M solutions with Grover’s iterator
18  function find_all_solutions (N, n, M ^ , S, oracle)
19  # If Step 1 estimated that M = 0, there is no need to find solutions
20   if  M ^ == 0: return S
21  
22  # Initialize circuits and variables
23   M ^ = ⎣ M ^ + 0.5⎦ # Round M ^ to the nearest integer
24   create a Grover’s iterator, G, based on n and oracle
25   fail_count = 0
26   max_fail_count = determine_max_fail_count (S, M ^ )
27  
28  # Collect measurements with Grover’s iterator
29  #  until no new solution remains
30  while fail_count < max_fail_count:
31   initialize n qubits into an equal superposition
32   apply ⎣π/4 × N / M ^ ⎦ iteration of G on n qubits
33   measure n qubits and store results in m
34   if oracle (m) == True and m S:   # If m is a new solution
35    S = S  {m}
36     fail_count = 0
37     max_fail_count = determine_max_fail_count (S, M ^ )
38   else: fail_count += 1
39
40  # Return the found solutions
41  return S
42  
43 function determine_max_fail_count (S, M ^ )
44  if |S| == 0: return 10
45  else:
46   if |S|/ M ^ == 1: return ⎡ln(0.1)/ln( M ^ /( M ^ + 1))⎤
47   else: return ⎡ln(0.1)/ln(|S|/ M ^ )⎤
We set max_fail_count to ⎡ln(0.1)/ln(|S|/ M ^ )⎤ (line 47), which allowed us to successfully identify most of the solutions. This equation is derived as follows. Assuming that Grover’s algorithm has successfully maximized the probability of measuring one of the solutions to nearly 100%, the probability of a failed attempt (i.e., measuring an already-discovered solution rather than a new one) is |S|/M, where |S| is the number of already-discovered solutions and M is the total number of solutions. The probability of fail_count consecutive failed attempts is therefore (|S|/M)fail_count. If this probability becomes sufficiently low, i.e., (|S|/M)fail_count ≤ 0.1 (10%), we reject the hypothesis that any uncovered solutions remain and conclude that no more new solutions are present. By taking the natural logarithm on both sides of the inequality and solving for fail_count, we obtain fail_count ≥ ln(0.1)/ln(|S|/M). Since fail_count must be an integer, we establish the termination condition as fail_count ≥ ⎡ln(0.1)/ln(|S|/M)⎤. Finally, by replacing the unknown M with the estimated value M ^ , we set max_fail_count to ⎡ln(0.1)/ln(|S|/ M ^ )⎤.
We recalculate max_fail_count when a new solution is discovered (line 37), as the new solution is added to the set S, altering |S| and thus affecting max_fail_count. In recalculating max_fail_count, we also consider two boundary conditions. First, because the logarithm function is undefined for an input of zero, if |S| happens to be 0, we bypass the logarithm calculation and instead set max_fail_count to 10 (line 44)—If any solutions exist and M has been correctly estimated in Step 1, they would be measured with a probability exceeding 90% upon applying Grover’s algorithm, as demonstrated by Equation (1), within ten consecutive shots. Second, if |S|/ M ^ approaches 1 as more solutions are found, ln(|S|/ M ^ ) tends towards zero, leading to a division-by-zero error. To prevent this, we use M ^ /( M ^ + 1) instead of 1 (line 46).
As mentioned in Section 3.2, M ^ could be slightly under- or overestimated. Even so, the proposed algorithm is designed to discover most of the solutions for the following reasons. The number of Grover’s iterations, ⎣ π /4 × ( N / M ^ ) ⎦, might slightly deviate from the optimal value, ⎣ π /4 × ( N / M ) ⎦, but we observed that the probability of measuring one of the solutions is still amplified to above 50%. Therefore, each measurement is likely to identify a solution, and if not, the subsequent few measurements will. Finally, if more than max_fail_count consecutive measurements fail to identify any new solution, the likelihood of any remaining solutions drops to nearly zero, allowing us to safely terminate the algorithm.
The average number of Grover’s iterations required for Step 2 is proportional to N M × log(M) for the following reasons. To compute the time complexity of Step 2 independently of Step 1, we assume that no solutions are found in Step 1, meaning that Step 2 must identify all M solutions. Finding all solutions would require more than M repetitions of Grover’s algorithm on average, as the same solution may be collected multiple times. This average is known to be Mlog(M), as described in the coupon collector’s problem [34]. Since each repetition of Grover’s algorithm requires π /4 × ( N / M ) iterations, Mlog(M) repetitions require π /4 × ( N / M ) × Mlog(M) = π /4 × N M × log(M) iterations. By omitting constants, we derive N M × log(M). However, in practice, we observed that Step 2 usually requires fewer Grover’s iterations than N M × log(M), as many solutions are already discovered in Step 1. This is demonstrated in the evaluation (Section 4.2).
For Step 2, one might consider modifying the oracle each time a new solution is discovered so that already-discovered solutions are no longer measured. This approach could potentially reduce the number of Grover’s algorithm repetitions, as each repetition would then identify a distinct solution, allowing all solutions to be found in M repetitions—fewer than the Mlog(M) repetitions required without modifying the oracle. However, we chose not to modify the oracle for the following reasons. First, modifying the oracle to unmark already-discovered solutions adds additional gates and stages, thereby increasing its complexity [3]. As a result, each repetition of Grover’s algorithm would involve an increasingly complex oracle, meaning fewer repetitions would not necessarily result in a shorter running time. Second, current quantum hardware often yields incorrect results as quantum circuits become deeper [17]. Consequently, each repetition may not reliably yield a new solution, potentially increasing the total number of repetitions needed.
We summarize Steps 1 and 2 as follows. Step 1 estimates the number of solutions M and requires Grover’s iterations proportional to N . Step 2, using M ^ estimated in Step 1, discovers all M solutions and, on average, requires Grover’s iterations proportional to N M × log(M). Thus, the entire process, encompassing both Steps 1 and 2, finds all solutions with Grover’s iterations proportional to N M × log(M) in the average case. However, as demonstrated in our evaluation (Section 4), this scenario rarely occurs, and the process is typically completed sooner. This is because many solutions are found in Step 1, leaving Step 2 to identify only the remaining solutions.
The proposed algorithms execute multiple shots of Grover’s circuit, with each shot submitted as a separate job to a quantum machine. We assume that an option exists to run multiple jobs exclusively until the algorithms are complete. However, if such an option is unavailable and the machine must be continuously shared by multiple users, our jobs may need to queue for scheduling alongside other jobs, potentially causing delays in executing all the required shots. To address this, we suggest the following approach. For Step 1, all k × N shots can be submitted as a single job (Algorithm 1, lines 23–26), as the subsequent estimation steps (lines 28–35) can be performed after all k × N measurements are collected. For Step 2, we can submit each job with enough shots to determine when to terminate the algorithm (i.e., max_fail_count shots). After processing the collected measurements, we can decide whether to terminate or continue the algorithm. For example, if the algorithm requires ten consecutive non-solutions to conclude, we can submit ten shots in a single job, identify any new solutions among the measurements, decide whether to terminate, and, if necessary, recalculate max_fail_count and repeat the process.

4. Evaluation

We implemented our proposed methods as described in Section 3 and evaluated their accuracy and efficiency. In Section 4.1, we focus on Step 1, assessing its ability to estimate the solution count both accurately and efficiently compared to a previous method. In Section 4.2, we investigate whether Step 2 can reliably discover all solutions without missing any. We also assess the efficiency of the overall search process.

4.1. Evaluation of Step 1: Accuracy and Efficiency in Estimating Solution Count

We evaluated the accuracy and efficiency of Step 1 in estimating the solution count compared to an existing approach, Quantum Counting [7]. Quantum Counting is a seminal work in estimating the number of solutions, and its implementations are widely available [35,36]. This method applies Grover’s algorithm to induce phase shifts in qubits and then uses the Quantum Fourier Transform [29] to estimate the magnitude of these phase shifts. Since the magnitude of the phase shifts correlates with the number of solutions, M can be inferred from the measured phase shifts. Although several other methods have been proposed to estimate the solution count [3,4,5,6], they primarily focus on alternative implementations tailored to current quantum hardware. These methods generally exhibit performance comparable to Quantum Counting in terms of the required number of Grover’s iterations and estimation accuracy. Consequently, we present results using Quantum Counting as a representative benchmark.
To compare our method and Quantum Counting, we assessed two metrics: (i) the amount of error in estimating solution counts and (ii) the number of Grover’s iterations required to estimate solution counts. The first metric demonstrates the accuracy of the methods by measuring the absolute differences between the estimated M values and the actual M values. The second metric measures the efficiency of the methods, as both our method and Quantum Counting utilize Grover’s iterations.
We measured the first metric, the amount of error, as follows. We ran both methods in an equal setting in terms of time complexity (i.e., we had the methods estimate the solution count by performing nearly the same number of Grover’s iterations) and compared the accuracy of their estimation results. This approach was chosen because, in both estimation methods, Grover’s iterations play a major role in the estimation process, and increasing the number of these iterations results in more accurate estimations. Therefore, using the same number of Grover’s iterations provides a fair basis for comparing the accuracy of the two methods.
As discussed in Section 3.2, our estimation method requires 10 × N Grover’s iterations. Therefore, we configured Quantum Counting to use a nearly identical number of Grover’s iterations and then measured the accuracy of their estimation results. In Quantum Counting, the number of Grover’s iterations is determined by the number of counting qubits. These counting qubits are ancilla qubits that are used in addition to the n qubits and that assist in counting the number of solutions. More counting qubits require more Grover’s iterations and increase the accuracy of the estimation.
With t counting qubits, Quantum Counting requires 2t − 1 Grover’s iterations, as depicted in Figure 4. Figure 4a shows the implementation of Quantum Counting for arbitrary n and t, and Figure 4b illustrates an example for n = 4 and t = 3. In stage 1, the n data qubits and t counting qubits are placed into an equal superposition using Hadamard operators. Then, from stages 2 to t + 1, Grover’s iterations are applied 2i−1 times (denoted by G2i−1), conditioned on each of the i-th counting qubit, totaling 20 + 21 +…+ 2t−1 = 2t − 1 Grover’s iterations. In stage t + 2, an inverse Quantum Fourier Transform (denoted by QFT†) is applied to the counting qubits, and in the final stage, a measurement (denoted by M) is performed on these qubits. The process across the t + 3 stages is repeated multiple times to collect a set of measurements. Among these measurements, the most frequently appearing value is used to estimate the solution count. Typically, tens of repetitions produce a reliable estimation, and thus, Quantum Counting requires at least 10 × (2t − 1) Grover’s iterations. To ensure that 10 × (2t − 1), Grover’s iterations are equivalent to the 10 × N Grover’s iterations performed in our method, we selected t = ⎡log2( N + 1)⎤.
We implemented both our method and Quantum Counting using Python and the Qiskit library [37]. We applied these methods to estimate the solution count across different search space sizes. In particular, we varied the size of the search space, N, from 23 to 29. For search spaces smaller than 23, all solutions can be found by simply iterating over each item, eliminating the need for a sophisticated algorithm. For search spaces larger than 29, the Qiskit-based quantum simulator required prohibitively long simulation times, often on the order of hours. This was particularly true for simulating Quantum Counting, which requires additional counting qubits along with the data qubits.
For each N ranging from 23 to 29, we varied the solution count, M, from 0 to N , under the assumption that M N , as explained in Section 3.1. For each combination of (N, M), we conducted 100 trials and gathered the estimated values. In each trial, we randomly selected M solutions from the N possible items, prepared an oracle to mark the selected solutions, and used the two methods to estimate M. The oracle was constructed using operators that inverted the phase of each solution, employing a combination of controlled-NOT and controlled-Z operators, as detailed in [29]. Our objective was to determine how many times the two methods needed to call the oracle, so we focused on ensuring the oracle correctly sign-inverted the solutions rather than optimizing its implementation or masking the real solutions. Readers looking to develop and optimize oracles for real-world problems can refer to related studies [14,15,16,17,18,19,20,21]. We then provided the proposed methods with this oracle without directly providing the M solutions (i.e., the methods were unaware of the solutions and had to estimate M and discover the solutions using the oracle). After the methods terminated, we compared their output with the actual solutions to evaluate how many were correctly discovered. The experiments were performed on a system equipped with a 3.4 GHz Intel Core i7-6700 processor and 16 GB of RAM, and we used the AerSimulator backend [38] on IBM’s quantum computing platform.
Table 4 summarizes the average errors across all tested N values, ranging from 23 to 29. We calculated the average error by determining the absolute differences between the estimated and actual values and then averaging these differences. In general, our proposed method more accurately mirrored the actual M values across all of the N values, with an overall average error of 0.5235, compared to Quantum Counting, which had an average error of 2.2599. This implies that when both our method and Quantum Counting use the same number of Grover’s iterations, thereby achieving equivalent time complexities, our method estimates M with greater accuracy than Quantum Counting.
We then evaluated how many counting qubits, t, are required for Quantum Counting to achieve a level of accuracy comparable to our proposed method. To this end, we gradually increased t until the average error of Quantum Counting was nearly equivalent to that of our method.
Table 5 displays the average error and the number of Grover’s iterations required by Quantum Counting as we gradually increased the number of counting qubits in comparison to the average error of our proposed method. Typically, Quantum Counting requires two or three additional counting qubits to achieve an average error comparable to that of our method. These additional counting qubits resulted in 5 to 15 times more Grover’s iterations than those used by our method. For example, when N = 27 = 128, the average error of Quantum Counting decreased to 0.3934, requiring t = 7 counting qubits and 1270 Grover’s iterations. In contrast, our proposed method needed 113 iterations to achieve an average error of 0.3460.
To further understand the differences between our method and Quantum Counting, we analyzed and compared the individual estimation results from both methods. Figure 5 displays the estimated values for N = 29. Figure 5a–c present the results from Quantum Counting using t = 5, 6, and 7 counting qubits, respectively, while Figure 5d shows the results from our proposed method. The actual M values are shown in gray, the estimates from Quantum Counting in red, and those from our method in green. The estimates from Quantum Counting form discrete steps, which double in number as t increases by one. Thus, the algorithm can systematically improve its accuracy with the addition of more counting qubits, although each additional qubit also doubles the required number of Grover’s iterations. In contrast, the estimates from our proposed method appear more continuous. While they sometimes deviate from the actual M values, overall, they achieve a higher level of accuracy with fewer Grover’s iterations than Quantum Counting. In the next subsection (Section 4.2), we demonstrate that the current level of accuracy of our proposed method is sufficient to efficiently find all solutions in Step 2.

4.2. Evaluation of Step 2: Comprehensive Discovery and Efficiency of Search Process

We evaluated Step 2 of our proposed method, which identifies all solutions based on the solution count estimated in Step 1. In particular, we assessed our method’s ability to detect all solutions without missing any. Additionally, we examined the efficiency of this method by measuring the number of Grover’s iterations required to locate the solutions to confirm that all solutions can be discovered with Grover’s iterations proportional to N M × log(M), as derived in Section 3.3.
We compared our results with previous methods [22,23] that assume M is estimated beforehand and repeatedly apply Grover’s algorithm until M distinct solutions are discovered. This previous method starts without any pre-discovered solutions and does not take into account those found in Step 1. It also assumes that M is correctly estimated without considering the possibility of under- or overestimation. However, if M is overestimated (i.e., M < M ^ ), the previous method could potentially run indefinitely, as there would be fewer than M ^ solutions. To avoid this, the method runs Grover’s algorithm only until the number of iterations matches that of our proposed method. This allows for a comparison of both methods under equivalent time complexity. In other words, since increasing the number of Grover’s iterations leads to discovering more solutions in both methods, using the same number of iterations provides a fair basis for comparing their completeness. Additionally, when the previous method identifies a new solution, it updates the oracle to prevent the same solution from being sampled again.
We implemented our method and the previous method using Python and the Qiskit library [37]. We chose N from 23 to 210 and M from 1 to N . For each combination of N and M, we randomly selected M solutions from the search space and prepared the corresponding oracle. We then executed Step 1 of our method to estimate M and applied Step 2 to identify the solutions based on this estimate M ^ . The previous method used the same estimated M ^ and continued applying Grover’s algorithm until either all M ^ solutions were found or the total number of Grover’s iterations exceeded that of our proposed method. This process was repeated one hundred times, and the resulting statistics were compiled.
Table 6 presents the average percentage of discovered solutions across all tested N values, ranging from 23 to 210. We calculated the average percentage by dividing the number of discovered solutions by the total number of solutions M then averaging these percentages over all possible M values. In general, our proposed method discovered nearly 100% of the solutions, rarely missing any. The previous method identified more than 90% of solutions for smaller N values (i.e., from 23 to 27), but as N grew larger, the percentages rapidly dropped below 80% (e.g., 17 out of 22 solutions were discovered, while the remaining 5 were missed).
Figure 6 provides further details for N = 512 and M values ranging from 1 to 22. The horizontal axis represents the various M values, while the vertical axis shows the number of discovered solutions. For each M, the gray, green, and red bars represent the total number of solutions M, the number of solutions found by our proposed method, and the number found by the previous method, respectively. Overall, our proposed method consistently discovered more than 99% of the solutions for most M values, while the percentage of solutions found by the previous method decreased as M grew larger—from 95% when M = 1 to nearly 74% when M = 22.
We then evaluated how many Grover’s iterations were required for the previous method to achieve a discovery percentage comparable to that of our proposed method. To do this, we ran the previous method until the percentage of discovered solutions was nearly equivalent to our method’s and measured the number of Grover’s iterations used.
Table 7 presents the average number of Grover’s iterations and the percentage of solutions discovered by the previous method compared to our proposed method. For smaller N values (i.e., from 23 to 25), the previous method discovered solutions with fewer iterations than our method. However, as N increased, the previous method required more iterations (e.g., 306 vs. 137 iterations for N = 210). Figure 7 provides further details for N = 512 and M ranging from 1 to 22. The horizontal axis represents the different M values, while the vertical axis shows the number of Grover’s iterations required. For each M, the red and green bars represent the number of iterations used by the previous method and our method, respectively. For M values smaller than 4, the previous method required fewer iterations, but as the number of solutions increased, the iterations grew rapidly, reaching double that of our method (e.g., 288 vs. 112 iterations for M = 22).
In summary, our proposed method consistently discovered most solutions with fewer Grover’s iterations than the previous method. The gap between the two methods widened as N and M increased; the previous method missed more solutions and required more iterations. This difference arises because, in our proposed method, many solutions are found in Step 1, which complements Step 2. Additionally, Step 2 ensures that most solutions are discovered even when M ^ is slightly under- or overestimated by continuing the search until the probability of remaining solutions is sufficiently low (Algorithm 2, line 30). In contrast, the previous method starts without any prior discovered solutions and runs until all M ^ solutions are found without accounting for the possibility that M ^ may be under- or overestimated.
The number of Grover’s iterations required in Step 2 of our method did not increase as rapidly as N M × log(M), as we derive in Section 3.3, but at a slower rate. This was because many solutions were already found in Step 1 while estimating M, leaving fewer solutions for Step 2 to find. Figure 8 provides more details for N = 1024 and M = 32. The horizontal axis represents 100 different trials, while the vertical axis shows the number of solutions found in Step 1 (green) and Step 2 (red). The trials are sorted in decreasing order based on the number of solutions found in Step 1. Out of the 32 solutions, 26 or more solutions (i.e., over 80% of the solutions) were found in Step 1, with the remaining solutions identified in Step 2. In summary, while the worst-case time complexity of Step 2 is N M × l o g ( M ) , in most cases, Step 2 was completed in time proportional to approximately N .
Since many solutions are discovered in Step 1, the benefit of Step 2 may not be immediately apparent. However, its importance can be summarized as follows. First, as N and M grow larger, more solutions are likely to be missed in Step 1. Step 2 complements Step 1 by discovering any remaining solutions. Second, the M ^ estimated by Step 1 may slightly differ from the actual M. In such cases, an approach of searching for M ^ distinct solutions may result in searching indefinitely when M < M ^ , or stopping early and missing some solutions when M > M ^ . To handle these scenarios, Step 2 continues the search until the probability of remaining solutions is sufficiently low, thus preventing infinite loops and ensuring most solutions are discovered.
We conducted experiments with N up to 1024 since further increasing N requires prohibitively long simulation times. Starting from N = 1024 and M ≥ 30, we observed instances where a few solutions were not discovered. For example, when M = 32, as illustrated in Figure 8, our proposed method discovered an average of 31.52 solutions (98.5%). In particular, out of 100 trials, all 32 solutions were found in 87 trials, but up to 4 solutions were missing in the remaining 13 trials. We analyzed the reason for this and found that as the estimation error in Step 1 increases (i.e., M ^ estimated in Step 1 deviates from the actual M), Step 2 runs Grover’s iterations ⎣ π /4 × ( N / M ^ ) ⎦ times, which can be greater or less than the optimal value ⎣ π /4 × ( N / M ) ⎦. Consequently, the probability of sampling the solutions is not properly maximized, causing the method to miss some solutions. We can address this issue by increasing max_fail_count, the maximum number of failed samplings before the algorithm terminates. However, we also plan to improve the accuracy of our estimation algorithm for larger N and M in future work.

4.3. Summary of Evaluation Results for Steps 1 and 2 of Our Proposed Methods

We summarize our findings from the evaluation as follows. Our proposed method consists of two steps. Step 1 estimates M, the number of solutions, and based on this estimate, Step 2 aims to find all M solutions. We first compared Step 1 of our method with Quantum Counting, a seminal work in the estimation of solution count. We discovered that our method estimates M more accurately and quickly than Quantum Counting. For example, when the search space size N is 29 = 512, our method estimated M with an average error of 0.8868 and required 226 Grover’s iterations, which is proportional to N . With a similar number of Grover’s iterations, Quantum Counting exhibited an average error of 3.0526 and required over 1200 Grover’s iterations (i.e., 5 times more) to achieve the same level of accuracy as our method.
We then evaluated Step 2 of our method and found that it discovers nearly all solutions most of the time. This success is attributable to the method’s design, which terminates the algorithm if no solution is detected for max_fail_count consecutive times. If any solutions remained and M ^ was accurately estimated, they would have been measured with a probability greater than 90%. Therefore, not detecting any solution after max_fail_count consecutive attempts confirms a high probability that no solutions are left. Although theoretically, Step 2 requires Grover’s iterations to be proportional to N M × log(M), we observed that Step 2 was completed with iterations proportional to N in most cases, because a large portion of solutions (often over 80%) were discovered in Step 1 while estimating M. Consequently, Steps 1 and 2 together required iterations proportional to N in practice.
We also observed that a few solutions (e.g., up to 4 out of 32) were occasionally missed by our method, mainly because the estimated value of M deviated from the actual value. Although applying Grover’s iterations and thus spending more time on searching would discover the missing solutions, we plan to further improve the accuracy of our estimation method without losing efficiency in future work.

5. Conclusions

We propose methods that utilize Grover’s algorithm to find all targets in a search space. These methods first estimate the number of targets M and then run Grover’s algorithm to discover all targets based on this estimate. The methods are efficient because the estimation step identifies a large fraction of target elements, leaving the discovery step to search for only the remaining targets. Additionally, the discovery step aims to discover most targets by terminating when the probability of remaining targets becomes sufficiently low.
We implemented the proposed methods and evaluated their speed and accuracy. Our results show that the methods estimate the number of targets with fewer Grover’s iterations than an existing estimation method (e.g., 226 vs. 1270 for N = 512). The discovery step requires even fewer iterations (e.g., 102 for N = 512) and concludes early because many solutions are found during the estimation step. Additionally, we demonstrated that the proposed methods discover over 99% of solutions on average, with very few targets missed.
For future work, we plan to enhance the accuracy of the estimation step to ensure that the discovery step identifies all targets without missing any. One approach involves dynamically adjusting the number of measurements, k × N , based on the potential error in the estimation. Specifically, we propose dividing the measurements into multiple intervals and calculating the ratio of solutions to measurements within each interval. If these ratios vary significantly, indicating a high error rate, the algorithm will adaptively increase the number of measurements to mitigate errors. We also aim to explore methods that can find all solutions efficiently without prior knowledge of the number of targets, thereby eliminating the need for estimation. Lastly, Quantum Monte Carlo (QMC) methods [39] have proven to be highly effective for analyzing complex quantum systems. We intend to leverage QMC techniques to enhance both the efficiency and accuracy of our discovery process. Specifically, these methods can help identify regions within the search space where solutions are densely clustered, enabling faster and more precise discovery of solutions within these clusters.

Author Contributions

Conceptualization, methodology, software, validation, and writing—original draft preparation, S.L.; Conceptualization, methodology, writing—review and editing, and supervision, S.Y.N. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Data Availability Statement

On our GitHub repository, we shared the implementation of our proposed methods (https://github.com/sihyunglee26/Find-All-Solutions-24 (accessed on 1 November 2024)).

Conflicts of Interest

The authors declare no conflicts of interest.

Appendix A. Expected Proportion of Solutions Found in Step 1

We derive the expected proportion of distinct solutions found in Step 1 (the estimation step) of our proposed methods to analyze its scalability with N. The probability of obtaining one of M solutions in a single trial is p = sin2 ((2j + 1) × M / N ), as shown in Equation (2). Therefore, the probability that a specific solution i is not obtained in a single trial is 1 − p/M. After m trials, the probability that solution i is not obtained becomes (1 − p/M)m. Conversely, the probability of obtaining solution i at least once in m trials is 1 − (1 − p/M)m. The expected number of distinct solutions, E, is the sum of these probabilities over all M solutions, resulting in
E = M × (1 − (1 − p/M)m).
Dividing the equation by M yields the expected proportion of distinct solutions:
E/M = 1 − (1 − p/M)m.
By substituting p = sin2 ((2j + 1) × M / N ) and m = k × N , we derive:
E / M = 1 ( 1 sin 2   ( ( 2 j + 1 )   ×   M / N ) / M ) k N
Equation (A1) does not readily reveal the scalability of E/M with N. To address this, we approximate sin2 ((2j + 1) × M / N ) and apply a Taylor expansion. First, we approximate sin2 ((2j + 1) × M / N ) as (2j + 1)2 × M/N, assuming M N and j is chosen such that (2j + 1) × M / N remains small. Substituting this approximation, we obtain
E / M = 1 ( 1 ( 2 j + 1 ) 2   ×   M / N / M ) k N = 1 ( 1 ( 2 j + 1 ) 2 / N ) k N
Expanding ( 1 ( 2 j + 1 ) 2 / N ) k N using a Taylor series yields
E / M = 1 ( 1 k N   × ( 2 j + 1 ) 2   / N + 1 / 2   × k N ( k N 1 ) × ( ( 2 j + 1 ) 2   / N ) 2 )
Simplifying further:
E / M = k × ( 2 j + 1 ) 2 / N 1 / 2   × k N ( k N 1 × ( 2 j + 1 ) 4 / N 2 +
For large N, the leading-order term dominates, giving
E / M     k × ( 2 j + 1 ) 2 / N .
Thus, the expected proportion of distinct solutions discovered in Step 1, E/M, scales inversely with N as N increases.
To validate the result, we plotted the original equation for E/M (Equation (A1)) for large values of N. Figure A1 illustrates E/M, the expected proportion of solutions found in Step 1, as N ranges from 210 to 220. For the plot, we set M = N and k = 10, consistent with our experimental setup. We also varied j, the number of Grover’s iterations applied prior to sampling, from 1 to 5. The figure demonstrates that the proportion of solutions remains above 80% for N ≤ 211, but it gradually diminishes as N grows larger, consistent with the approximation in Equation (A2). To slow down the rate of decrease, j can be increased since E/M is proportional to (2j + 1)2. However, this comes at the cost of additional Grover’s iterations, resulting in a total of k × j × N iterations. In future work, we plan to develop improved estimation methods that maintain effectiveness for even larger values of N.
Figure A1. Expected proportion of distinct solutions found in Step 1 of the proposed algorithm for N ranging from 210 to 220 and j ranging from 1 to 5.
Figure A1. Expected proportion of distinct solutions found in Step 1 of the proposed algorithm for N ranging from 210 to 220 and j ranging from 1 to 5.
Electronics 13 04830 g0a1

References

  1. Grover, L.K. A fast quantum mechanical algorithm for database search. In Proceedings of the Twenty-Eighth Annual ACM Symposium on Theory of Computing, Philadelphia, PA, USA, 22–24 May 1996; pp. 212–219. [Google Scholar] [CrossRef]
  2. Boyer, M.; Brassard, G.; Hoyer, P.; Tapp, A. Tight bounds on quantum searching. Fortschritte der Physik 2005, 46, 187–199. [Google Scholar] [CrossRef]
  3. Suzuki, Y.; Uno, S.; Raymond, R.; Tanaka, T.; Onodera, T.; Yamamoto, N. Amplitude estimation without phase estimation. Quantum Inf. Process 2020, 19, 75. [Google Scholar] [CrossRef]
  4. Aaronson, S.; Rall, P. Quantum approximate counting, simplified. In Proceedings of the 2020 Symposium on Simplicity in Algorithms (SOSA), Salt Lake City, UT, USA, 6–7 January 2020; pp. 24–32. [Google Scholar] [CrossRef]
  5. Balewski, J.; Camps, D.; Klymko, K.; Tritt, A. Efficient quantum counting and quantum content-addressable memory for DNA similarity. In Proceedings of the IEEE International Conference on Quantum Computing and Engineering, Bellevue, WA, USA, 17–22 September 2023; pp. 378–384. [Google Scholar] [CrossRef]
  6. Widdows, D.; Bhattacharyya, A. Quantum financial modeling on noisy intermediate-scale quantum hardware: Random walks using approximate quantum counting. Quantum Econ. Finance 2024, 1, 5–20. [Google Scholar] [CrossRef]
  7. Brassard, G.; Hoyer, P.; Tapp, A. Quantum counting. Lect. Notes Comput. Sci. 2006, 1443, 820–831. [Google Scholar] [CrossRef]
  8. Fernandes, D.; Dutra, I. Using Grover’s search quantum algorithm to solve Boolean satisfiability problems: Part I. ACM Mag. Students 2019, 26, 64–66. [Google Scholar] [CrossRef]
  9. Saravanan, P.; Jenitha, J.; Sanjana, S.; Haghparast, M. Compact quantum circuit design of PUFFIN and PRINT lightweight ciphers for quantum key recovery attack. IEEE Access 2023, 11, 66767–66776. [Google Scholar] [CrossRef]
  10. Schwabe, P.; Westerbaan, B. Solving binary MQ with Grover’s algorithm. In Proceedings of the 6th International Conference, SPACE 2016, Hyderabad, India, 14–18 December 2016; pp. 303–322. [Google Scholar] [CrossRef]
  11. Haverly, A.; Lopez, S. Implementation of Grover’s algorithm to solve the maximum clique problem. In Proceedings of the 2021 IEEE Computer Society Annual Symposium on VLSI (ISVLSI), Tampa, FL, USA, 7–9 July 2021; pp. 441–446. [Google Scholar] [CrossRef]
  12. Iqbal, B.; Singh, H. Identification of desired pixels in an image using Grover’s quantum search algorithm. arXiv 2021, arXiv:2107.03053. [Google Scholar]
  13. Borujeni, S.E.; Harikrishnakumar, R.; Nannapaneni, S. Quantum Grover search-based optimization for innovative material discovery. In Proceedings of the IEEE International Conference on Big Data, Los Angeles, CA, USA, 9–12 December 2019; pp. 4486–4489. [Google Scholar] [CrossRef]
  14. Jiang, J.; Kao, T. Solving Hamiltonian cycle problem with Grover’s algorithm using novel quantum circuit designs. In Proceedings of the IEEE 5th Eurasia Conference on IOT, Communication and Engineering (ECICE), Yunlin, Taiwan, 27–29 October 2023; pp. 796–801. [Google Scholar] [CrossRef]
  15. Saha, A.; Saha, D.; Chakrabarti, A. Circuit design for k-coloring problem and its Implementation in any dimensional quantum system. SN Comput. Sci. 2021, 2, 427. [Google Scholar] [CrossRef]
  16. Mukherjee, S. A Grover search-based algorithm for the list coloring problem. IEEE Trans. Quantum Eng. 2022, 3, 3101008. [Google Scholar] [CrossRef]
  17. Lutze, D. Solving Chromatic Number with Quantum Search and Quantum Counting. Master’s Thesis, Department of Computer Science, California Polytechnic State University, San Luis Obispo, CA, USA, 2021. [Google Scholar] [CrossRef]
  18. Jiang, J.; Yan, W. Novel quantum circuit designs for the oracle of Grover’s algorithm to solve the vertex cover problem. In Proceedings of the IEEE 5th Eurasia Conference on IOT, Communication and Engineering, Yunlin, Taiwan, 27–29 October 2023; pp. 652–657. [Google Scholar] [CrossRef]
  19. Jiang, J.; Wang, Y. Quantum circuit based on Grover’s algorithm to solve exact cover problem. In Proceedings of the VTS Asia Pacific Wireless Communications Symposium (APWCS), Tainan city, Taiwan, 23–25 August 2023; pp. 1–5. [Google Scholar] [CrossRef]
  20. Jiang, J.; Lin, Q. Utilizing novel quantum counters for Grover’s algorithm to solve the dominating set problem. arXiv 2023, arXiv:2312.09388. [Google Scholar]
  21. Roch, C.; Castillo, S.L.; Linnhoff-Popien, C. A Grover based quantum algorithm for finding pure Nash equilibria in graphical games. In Proceedings of the IEEE 19th International Conference on Software Architecture Companion (ICSA-C), Honolulu, HI, USA, 12–15 March 2022; pp. 147–151. [Google Scholar] [CrossRef]
  22. Grover, L.K.; Radhakrishnan, J. Quantum search for multiple items using parallel queries. arXiv 2004, arXiv:quant-ph/0407217. [Google Scholar]
  23. Apeldoorn, J.; Gribling, S.; Nieuwboer, H. Basic quantum subroutines: Finding multiple marked elements and summing numbers. Quantum 2024, 8, 1284–1312. [Google Scholar] [CrossRef]
  24. Seidel, R.; Becker, C.K.; Bock, S.; Tcholtchev, N.; Gheorghe-Pop, I.; Hauswirth, M. Automatic generation of Grover quantum oracles for arbitrary data structures. Quantum Sci. Technol. 2023, 8, 025003. [Google Scholar] [CrossRef]
  25. Mandviwalla, A.; Ohshiro, K.; Ji, B. Implementing Grover’s algorithm on the IBM Quantum computers. In Proceedings of the IEEE International Conference on Big Data, Seattle, WA, USA, 10–13 December 2018; pp. 2531–2537. [Google Scholar] [CrossRef]
  26. Wu, X.; Li, Q.; Li, Z.; Yang, D.; Yang, H.; Pan, W.; Perkowski, M.; Song, X. Circuit optimization of Grover quantum search algorithm. Quantum Inf. Process 2023, 22, 69. [Google Scholar] [CrossRef]
  27. Lee, S.; Nam, S. Implementation of Grover’s iterator for quantum search with an arbitrary number of qubits. IEEE Access 2024, 12, 43027–43038. [Google Scholar] [CrossRef]
  28. Park, G.; Zhang, K.; Yu, K.; Korepin, V. Quantum multi-programming for Grover’s search. Quantum Inf. Process. 2023, 22, 54. [Google Scholar] [CrossRef]
  29. Nielsen, M.A.; Chuang, I.L. Quantum Computation and Quantum Information; Cambridge University Press: Cambridge, UK, 2011. [Google Scholar]
  30. Qiu, D.; Luo, L.; Xiao, L. Distributed Grover’s algorithm. Theor. Comput. Sci. 2024, 993, 114461. [Google Scholar] [CrossRef]
  31. Grover, L. Fixed-point quantum search. Phys. Rev. Lett. 2005, 95, 150501–150504. [Google Scholar] [CrossRef]
  32. Byrnes, T.; Forster, G.; Tessler, L. Generalized Grover’s algorithm for multiple phase inversion states. Phys. Rev. Lett. 2018, 120, 060501–060505. [Google Scholar] [CrossRef]
  33. Yan, B.; Wei, S.; Jiang, H.; Wang, H.; Duan, Q.; Ma, Z.; Long, G. Fixed-point oblivious quantum amplitude-amplification algorithm. Sci. Rep. 2022, 12, 14339. [Google Scholar] [CrossRef]
  34. Motwani, R.; Raghavan, P. The coupon collector’s problem. Randomized Algorithms; Cambridge University Press: Cambridge, UK, 1995; pp. 57–63. [Google Scholar]
  35. Implementation of Quantum Counting Based on Qiskit Library. Available online: https://github.com/Qiskit/textbook/blob/main/notebooks/ch-algorithms/quantum-counting.ipynb (accessed on 20 October 2024).
  36. Chung, N.; Nepomechie, R.I. Quantum counting, and a relevant sign. arXiv 2023, arXiv:2310.07428. [Google Scholar]
  37. Qiskit: Open-Source Toolkit for Quantum Development. Available online: https://qiskit.org (accessed on 20 October 2024).
  38. AerSimulator. Available online: https://qiskit.org/ecosystem/aer/stubs/qiskit_aer.AerSimulator.html (accessed on 20 October 2024).
  39. Gubernatis, J.; Kawashima, N.; Werner, P. Quantum Montel Carlo Methods; Cambridge University Press: Cambridge, UK, 2016. [Google Scholar]
Figure 1. Overview of Grover’s algorithm.
Figure 1. Overview of Grover’s algorithm.
Electronics 13 04830 g001
Figure 2. Example of Grover’s iterator process for N = 8 and target item ‘100’.
Figure 2. Example of Grover’s iterator process for N = 8 and target item ‘100’.
Electronics 13 04830 g002aElectronics 13 04830 g002b
Figure 3. Overview of proposed methods.
Figure 3. Overview of proposed methods.
Electronics 13 04830 g003
Figure 4. Implementation of Quantum Counting.
Figure 4. Implementation of Quantum Counting.
Electronics 13 04830 g004
Figure 5. Scatter plot of estimated values of M for N = 29.
Figure 5. Scatter plot of estimated values of M for N = 29.
Electronics 13 04830 g005
Figure 6. Average number of solutions found by our method and the previous method for N = 512.
Figure 6. Average number of solutions found by our method and the previous method for N = 512.
Electronics 13 04830 g006
Figure 7. Average number of Grover’s iterations used by our method and the previous method for N = 512.
Figure 7. Average number of Grover’s iterations used by our method and the previous method for N = 512.
Electronics 13 04830 g007
Figure 8. Number of solutions found in Steps 1 and 2 for N = 1024 and M = 32.
Figure 8. Number of solutions found in Steps 1 and 2 for N = 1024 and M = 32.
Electronics 13 04830 g008
Table 1. Use cases of finding all solutions in a search problem.
Table 1. Use cases of finding all solutions in a search problem.
IDApplication DomainUse Case
1Database SearchIn a database, find all records that meet a given condition (e.g., “select * from table_name where condition is true”).
2SecurityIn computer applications, identify as many vulnerabilities as possible and patch them promptly to reduce the risk of compromise and potential loss.
3Image ProcessingIn a network of surveillance cameras, find all video snapshots that show characteristics of a suspect following a crime to help the police track the suspect’s whereabouts.
4AstronomyIn an astronomical catalog, identify all planets where life may exist to understand the distribution of such planets in space.
5BiologyIn a collection of genetic information, find all genetic markers associated with a particular symptom to develop a medicine that cures the symptom.
Table 2. Objectives of this work and how we fulfill them.
Table 2. Objectives of this work and how we fulfill them.
IDObjectiveHow We Fulfill the Objective and Results
1(Step 1) Quickly and accurately estimate the number of solutions M
  • Use a single repetition of Grover’s iterator to collect one sample and gather samples proportional to N , thereby requiring oracle calls proportional to N
  • Achieved accuracy similar to Quantum Counting [7] with fewer repetitions (e.g., 226 vs. 1270 for N = 512)
2(Step 2) Discover as many solutions as possible without missing any
  • Continue the search until the probability of remaining solutions is sufficiently low, considering that M may be slightly under- or overestimated
  • Consistently discover over 99% of the solutions for search space sizes ranging from 23 to 210, with very few solutions missed
3Optimize Steps 1 and 2 together
  • Discover many solutions (over 80%) in Step 1 so that Step 2 finds the remaining ones
  • Reuse Grover’s iterator in both steps to simplify implementation
  • Combined Steps 1 and 2 require oracle calls proportional to N in practice, with worst-case N M × log ( M ) being rare
Table 3. Summary of terms.
Table 3. Summary of terms.
TermDescription
GGrover’s Iterator—A combination of the oracle and amplification processes used to increase the probability of target items in Grover’s search algorithm. Gi indicates that G is applied i times.
HHadamard Operator—A fundamental quantum operator used to create superposition.
Hn means n Hadamard operators applied in parallel on n qubits, one operator per qubit.
MSolution Count—The number of solutions in the search space, assumed to be M     N , as explained in Section 3.1.
M ^ Estimated M—The value of M is estimated by an algorithm. This can match or differ from the actual M.
NSearch Space Size—The total number of elements in the search space.
nQubit Count—The number of qubits used to represent the search space, equal to ⎡log2(N)⎤
QFTQuantum Fourier Transform—A quantum version of Fourier Transform used in many quantum algorithms. QFT† refers to its inverse.
max_fail_countTermination Threshold—A threshold in the proposed search algorithm. If no solution is found after max_fail_count consecutive attempts, the algorithm terminates, assuming that no more solutions exist.
Table 4. Average error of our method and Quantum Counting when similar numbers of Grover’s iterations were used.
Table 4. Average error of our method and Quantum Counting when similar numbers of Grover’s iterations were used.
Search Space Size NSolution Count
M   in   [ 0 ,   N ]
Quantum CountingProposed Method
# of Counting Qubits tAverage ErrorAverage Error
23 = 8[0, 2]21.16670.1138
24 = 16[0, 4]30.80630.1942
25 = 32[0, 5]31.10640.2373
26 = 64[0, 8]41.59520.3094
27 = 128[0, 11]42.62440.3460
28 = 256[0, 16]52.30950.5409
29 = 512[0, 22]53.05260.8868
Table 5. Average error of Quantum Counting with various numbers of counting qubits.
Table 5. Average error of Quantum Counting with various numbers of counting qubits.
Search Space Size 2n = NQuantum CountingProposed Method
# of Counting Qubits t# of Grover’s
Iterations (=10
(2t − 1))
Average Error# of Grover’s
Iterations (=10 N )
Average Error
23 = 82301.1667280.1138
3700.3333
41500.2196
53100.1462
24 = 163700.8063400.1942
41500.4803
53100.3614
66300.1162
25 = 323701.1064560.2373
41500.6184
53100.3725
66300.2259
26 = 6441501.5952800.3094
53100.7906
66300.4205
712700.1967
27 = 12841502.62441130.3460
53101.0868
66300.6013
712700.3934
28 = 25653102.30951600.5409
66300.9626
712700.5384
29 = 51253103.05262260.8868
66301.6082
712700.9045
Table 6. Average percentage of solutions found by our method and the previous method using a similar number of Grover’s iterations.
Table 6. Average percentage of solutions found by our method and the previous method using a similar number of Grover’s iterations.
Search Space Size NSolution Count
M   in   [ 1 ,   N ]
Previous MethodProposed Method
23 = 8[1, 2]98.67%100.00%
24 = 16[1, 4]97.50%100.00%
25 = 32[1, 5]95.27%100.00%
26 = 64[1, 8]92.53%100.00%
27 = 128[1, 11]91.45%99.98%
28 = 256[1, 16]86.53%99.95%
29 = 512[1, 22]79.45%99.42%
210 = 1024[1, 32]71.32%99.13%
Table 7. Numbers of Grover’s iterations used by our method and the previous method when achieving a similar level of discovery percentage.
Table 7. Numbers of Grover’s iterations used by our method and the previous method when achieving a similar level of discovery percentage.
Search
Space Size N
Previous MethodProposed Method
Average # of Grover’s
Iterations
Discovery
Percentage
Average # of Grover’s
Iterations
Discovery
Percentage
23 = 82.6498.67%6.95100.00%
24 = 166.8698.50%10.86100.00%
25 = 3212.6697.93%16.41100.00%
26 = 6429.6598.67%28.47100.00%
27 = 12852.8298.89%42.6699.98%
28 = 256106.4198.88%70.6799.95%
29 = 512186.8498.20%102.2099.42%
210 = 1024306.7797.89%137.1599.13%
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Lee, S.; Nam, S.Y. Finding All Solutions with Grover’s Algorithm by Integrating Estimation and Discovery. Electronics 2024, 13, 4830. https://doi.org/10.3390/electronics13234830

AMA Style

Lee S, Nam SY. Finding All Solutions with Grover’s Algorithm by Integrating Estimation and Discovery. Electronics. 2024; 13(23):4830. https://doi.org/10.3390/electronics13234830

Chicago/Turabian Style

Lee, Sihyung, and Seung Yeob Nam. 2024. "Finding All Solutions with Grover’s Algorithm by Integrating Estimation and Discovery" Electronics 13, no. 23: 4830. https://doi.org/10.3390/electronics13234830

APA Style

Lee, S., & Nam, S. Y. (2024). Finding All Solutions with Grover’s Algorithm by Integrating Estimation and Discovery. Electronics, 13(23), 4830. https://doi.org/10.3390/electronics13234830

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop