A Bi-directional Quantum Search Algorithm
Abstract
Grover’s search algorithms, including various partial Grover searches, experience scaling problems as the number of iterations rises with increased qubits, making implementation more computationally expensive. This paper combines Partial Grover’s search algorithm and Bi-directional Search to create a fast Grover’s quantum search algorithm, referred to as Bi-Directional Grover Search (BDGS). We incorporated a bi-directional search tactic with a partial Grover search, starting from an initial state and a single marked state in parallel. We have shown in this article that our novel approach requires iterations over regular Grover Search and Partial Grover Search (PGS), which take (here, elements, is the branching factor of partial search and ). The proposed BDGS algorithm is benchmarked against the state-of-the-art Depth-First Grover’s Search (DFGS) and generic Grover’s Search (GS) implementations for to qubits and provides promising results. The Qiskit Python implementation of the proposed BDGS algorithm is available on Github∗∗∗https://github.com/hafeezzwiz21/DFGS-BDGS.
Index Terms:
Grover’s search algorithm, IBM quantum computer, Quantum Computing, QubitI Introduction
Grover’s quantum search algorithm [1] is one of the well-known applications of quantum computing, enabling quantum computers to perform a database search (an unsorted array) and quadratically outperform their classical counterparts in terms of time. Despite the efficient database search for an Oracle model (black box), researchers have shown several Grover circuit implementations across various platforms [2, 3, 4, 5, 6], as well as theoretical evidence of the algorithm’s efficiency [7]. Grover’s Search (GS) technique only requires O() [8] evaluations to find an item with a high probability in an unstructured list. Compared to a classical system, Grover’s approach locates an entity in an unstructured list in fewer steps [1]. One state out of every conceivable superposition state is the search entity in quantum processing. Grover’s quantum search algorithm [1] asserts that in a -qubit network, there are = states, and the chance of discovering each state is . Each state’s amplitude is therefore . In the classical system, the identical problem requires a maximum of O() [1] trials. Bennett et al. [8] states that no quantum approach can, asymptotically, solve the database search problem in fewer steps than O(). Subsequently, Boyer et al. [9] has demonstrated that no quantum algorithm with a success probability can outperform Grover’s method by over a few percentage points. Grover’s search can solve collision problems, determine a dataset’s mean and median [1], and reverse-engineer cryptographic hash algorithms by revealing a victim’s password to an attacker.
However, generic Grover’s quantum search is computationally expensive in terms of computational time when the number of qubits or circuit depth increases, even though its implementation yielded a high success rate. To avoid a comprehensive (Grover) search and high computational complexity, the search often focuses on a block or collection of items that include the marked state rather than the marked state itself, and it is known as a Quantum Partial Search Algorithm (QPSA) [10]. Heiligman (2000) described a partial quantum search algorithm to find matches between two databases in [11]. Of late, a quantum pattern-matching method, as presented by P. Niroula et al., matches a search string (pattern) of length inside a larger text of length with time complexity [12]. A quantum search method for nearest pattern matching in , where is the string’s length, is introduced by P. Mateus [13]. A. Tulsi introduced a quantum search algorithm, which finds a single element in common between two sets in [14]. Grover and Radhakrishnan introduced a fast algorithm for partial Grover search relying on local and global searches [15] and attains iterations. Recently, Guo et al. introduced an improved version of QPSA using Depth-First Search (DFS) referred to as Grover’s Search (DFGS) [16].
However, despite its potential in the faster partial Grover search procedures regarding iteration, partial Grover search algorithms have been limited in implementation due to their complex formulation [10]. This paper provides a bi-directional quantum search algorithm, which draws inspiration from the Quantum Partial Search Algorithm (QPSA) [15, 10] and Depth-First Grover’s Search (DFGS) [16]. We incorporated a Bi-directional search tactic with QPSA starting from an initial state and a single marked state in parallel. The notable contributions of the article are provided as follows.
-
1.
In this research, a faster and scalable bi-directional Grover’s search algorithm (BDGS) relying on partial Grover’s search for any number of qubits is introduced.
-
2.
Furthermore, we have implemented the Depth-First Grover Search Algorithm (DFGS) [16] on quantum simulation for the first time and benchmarked with the proposed BDGS with empirical results.
-
3.
On parallelization, our novel Bi-directional approach requires iterations over Depth-First Partial Grover Search (DFGS) and the regular Grover Search.
II Partial Grover’s Search
Grover’s algorithm for quantum searching is primarily concerned with searching an unstructured data array of items [17]. Grover’s quantum search approach has to locate an element in the collection , where is the total number of elements in the set , to be effective. Finding an element in the collection is necessary for [6]. This is the responsibility of the Boolean function . The full Grover search algorithm locates the marked state in iterations [15].
(1) |
The input qubits are first converted into a superposition with equal coefficients using a Hadamard gate. The initial quantum state is subjected to phase inversion and inversion around the mean [6].
Grover’s iteration, also known as Grover’s operator, is used in the quantum Grover search circuit. Grover’s iteration is divided into two phases [17]. In a marked state, the oracle function first flips the phase of a single amplitude. The diffusion layer is said to have done its job when the indicated state amplitude flips over. The target state is inverted, causing its amplitude to grow dramatically while the amplitudes of the other states only slightly decrease. The other states maintain their previous amplitude.
II-A Oracle
An Oracle [18] is often shown as a black box that inverts the chosen coefficient of the target base state after receiving the input state, .
Initialization:
Due to creating an equal superposition of base states, the Hadamard gate ( gate) is utilized in the initial stage of Grover’s search algorithm to put all of the qubits in superposition [18]. The state, i.e.,, is superposed with equal probability over the and states when a gate is applied to it. The following matrix represents an gate:
(2) |
The uniform superposition of every basis vector in the whole database serves as the starting point for the Grover search as follows [19]:
(3) |
Iteratively, the Grover’s algorithm looks for a single target object . A unitary transform is the Grover iteration:
(4) |
Two inversions on the marked state are presented as (Diffusion operator) and (Oracle operator) as follows:
(5) |
(6) |
where is an identity operator.
The marked state undergoes a phase flip using the oracle function. All the states, including the one that is indicated, have an initial amplitude of . All states have a mean amplitude of . The initial state has its amplitude transformed by the phase flip to . The following is the change in mean amplitude ().
(7) |
the amplitudes of the marked and unmarked states are denoted by and , respectively.
The Grover iteration rotates at an angle in Hilbert space, moving from to the destination , where, and following iterations
(8) |
Hence, following repetitions, the amplitudes of all other items vanish, and the probability amplitude of becomes unity.
(9) |
II-B Diffusion
A diffusion model can be implemented as HX + Oracle + XH, where represents the Hadamard transform and represents the gate. This combination inverts the amplitudes surrounding their mean. According to Grover’s search, the amplitude of the marked state will rise by . The marked state has a new amplitude that can be calculated using formula 2.-. We can derive as follows using = and = - (from Equation 7):
(10) |
II-C Partial Grover Search Algorithm
Grover and Radhakrishnan (GRK) [15] proposed a faster quantum search method for partial search using the same Oracle as the Grover algorithm. The partial search also begins with the uniform superposition of all base states. The generic partial Grover search problem considers the following: A database with items is divided into identically sized blocks.
(11) |
In partial Grover search, approximately searches are required to locate the target block [15]. When the blocks are infinitely large (), is a finite positive number that depends on .
Every block has concurrent local Grover iterations, , as follows.
(12) |
where each and inversion on the marked state (query to the oracle) is and the local inversion is presented as (Diffusion operator)
(13) |
The uniform superposition of items in a block, , is represented here as follows.
(14) |
Regional repetition is the Grover iteration carried out concurrently in every block. Only the target block has a non-trivial operation [rotation] with a new rotation angle specified by
(15) |
Every item in non-target blocks can have its amplitudes eliminated by applying one more global iteration [20].
(16) |
For GRK partial Grover’s search, we randomly select () blocks and apply Grover’s quantum search method to places inside the selected blocks. This would need inquiries are needed, and it is faster than a standard full Grover’s search [15].
III Bi-directional Grover Search Algorithm
A novel approach combining Bi-directional search (BDS) [21] and Partial Grover Search (PGS) [15] algorithms is proposed and referred to as Bi-directional Grover Search (BDGS) for faster convergence. In the proposed quantum circuit, as shown in Figure 1, and are two functions as the Oracle and Diffuser, respectively. The main idea of BDGS lies in forward and backward passes from the initial and target states simultaneously until the two search frontiers intersect. The entire solution path is then formed by concatenating the path from the start state with the inverse path from the target state. Optimal solutions are guaranteed using the proposed bi-directional quantum search algorithm with a time complexity of , and each search only needs to go halfway down the solution depth in parallel.
In this proposed BDGS algorithm,
1. we recursively traversed each possible solution interval at each layer using Partial Grover Search (quantum operator ) for blocks to identify which intervals among the (branching factor) equal-size split sub-interval has a solution.
2. Finally, a standard Grover Search (using quantum operator ) is involved in determining the precise address of the solution for intervals whose widths are less than or equal to .
The proposed BDGS algorithm incorporates Partial Grover Search [21] to determine the next bits in forward and backward search in BDGS as follows:
(17) |
(18) |
Here, . Two auxiliary qubits are placed to store the following: (1) the bits’ found value; and (2) the bits’ status (checked and unchecked). The qubits will be initialized into a superposition of this encoding. Assuming
(19) |
(20) |
As shown in Figure 2, since the first four bits are determined on the second layer, the first four bits are encoded by the auxiliary qubits, which have the values = and = as follows.
(21) |


We aim to find the next bits using the Partial Grover Search, but the determined bits are fixed. A pseudo-code for our BDGS algorithm Procedure BDGS () has been provided to understand the potential readers better.
III-A Computational Complexity Analysis
In bi-directional search, if forward () and backward () passes to meet the satisfaction criteria , it is considered the target item has been found. We can create a database with all r-length pathways (), . The subpath path each vertex once.
The proposed BDGS algorithm’s initial step aims to increase the target blocks’ amplitude using Partial Grover Search iteratively. To make it, in Equation 8 , i.e., .
Hence, the maximum number of iterations at level of the bi-directional tree search is evaluated as [15].
(22) |
Since , , which implies that regardless of the number of iterations, the amplitudes of non-target blocks are all set to (Ref: Equation 8).
For example, as shown in Fig. 2, the database requires representing qubits (). is the initial qubits’ satisfaction condition and is the final qubits’ satisfaction requirement, with . Therefore, and .
According to GRK’s partial Grover’s search [15], the total number of queries required for BDGS for a single partial Grover search in both forward and backward pass at level is , assuming, on an average, each pass comprises states.
The BDGS procedure does partial or regular Grover searches for intervals with a size less than or equal to for each query at level . Hence, the total complexity of the proposed BDGS is
(23) |
We deduce that the average number of oracle calls of BDGS is . Whereas, our BDGS, the DFGS [16] and the standard Grover Search [17], attains same the average computational complexity of .
IV Simulation Results



We have conducted various trials on quantum simulation on a qubit space ranging from to qubits on the Qiskit Aer simulator∗∗∗https://qiskit.github.io/qiskit-aer/stubs/qiskit_aer.AerSimulator.html with shots with each execution on -cores systems with a maximum frequency of 3.5 GHz and -GB RAM. In our quantum simulation settings, we implemented the Oracle and Diffuser searching for qubits as a part of a partial search in the forward and backward direction for the proposed BDGS algorithm. The choice of has functioned flawlessly in a database with an even distribution. An oracle design for has been shown in Figure 3. In general, the database configuration and the quantum resources will significantly impact the value of . We have also implemented a DFGS [16] algorithm based on a similar partial search method in a depth-wise manner using the same quantum simulation settings. We performed distinct trials in the experiments using the proposed BDGS, DFGS, and standard GS algorithms [17]. The simulation results demonstrate a significant improvement in runtime without compromising the accuracy of the proposed BDGS search algorithm compared with DFGS and standard GS algorithms, as shown in Table I. It is worth noting that the runtime of standard GS grows exponentially with an increase in the search space, whereas DFGS and BDGS grow linearly, as shown in Figure 4. In addition, we have also visualized the number of iterations required with an increase in the number of qubits, as shown in Figure 5. Our results indicate that DFGS and BDGS significantly lower the required iterations, making it far more efficient for larger search spaces. It may be noted that for qubits search space, the standard GS takes iterations, whereas DFGS and the proposed BDGS require only and iterations, respectively.
GS | DFGS | BDGS | |||||
---|---|---|---|---|---|---|---|
Qubits | Trial | Acc. | Time(s) | Acc. | Time(s) | Acc. | Time(s) |
1 | |||||||
2 | |||||||
4 | 3 | ||||||
4 | |||||||
5 | |||||||
Avg. | |||||||
1 | |||||||
2 | |||||||
8 | 3 | ||||||
4 | |||||||
5 | |||||||
Avg. | |||||||
1 | |||||||
2 | |||||||
16 | 3 | ||||||
4 | |||||||
5 | |||||||
Avg. | |||||||
1 | |||||||
2 | |||||||
20 | 3 | ||||||
4 | |||||||
5 | |||||||
Avg. |
V Discussion
In this study, we explore a class of structured bi-directional search problems for which the satisfaction criterion can be decomposed to and , the search-based satisfaction conditions. Using smaller oracles, we introduce the faster quantum partial search method for a single target item. The BDGS algorithm’s general concept is to parallelly increase the amplitude of the items in each block that fulfill and .
The maximum number of Grover iterations for the bi-directional quantum search with a smaller oracle we provided in this work is .
Our simulation results show that the proposed BDGS algorithms yielded much shorter run times than DFGS [16] and standard GS [17] while maintaining similar measurement accuracy. This is primarily attributed to the efficient usage of gates and Grover iterations in DFGS and BDGS.
Moreover, owing to the decomposition of the entire problem search space into two halves (forward and backward passes), the proposed BDGS algorithm only requires smaller oracles, which is the most significant advantage of the quantum search with smaller oracles. The circuit depth of oracles will rise as database size increases. Operating the quantum circuit error-free becomes increasingly tricky as the circuit depth increases. Our BDGS technique will mitigate this issue by employing smaller oracles. Smaller oracles are more straightforward to build and aid in the error-free operation of the quantum circuit.
However, the proposed BDGS algorithm’s supremacy suffers due to the structured search problems subject to the requirements of satisfaction of the condition . Hence, the procedure is not a universal search algorithm.
VI Conclusion
This article offers the first new attempt to enable the creation of Bi-directional implementations of partial Grover’s quantum search method with a reduction in computational complexity. Here, the proposed quantum circuit is simulated for 2-qubit to 20-qubit circuits and enabled for scalable solutions for any number of qubits. The proposed framework exhibits a potential solution for quantum advantage in implementing our Bi-directional Grover’s Search (BDGS) algorithm without compromising the probability of success in searching a target. Our unique approach uses amplitude amplification to solve all problems and achieves the same efficiency as the standard Grover search with a lesser run time. Hence, our proposed BDGS offers an efficient usage of gates allowing for significantly smaller run times. In forthcoming research, the proposed Bi-directional Grover’s Search has the potential to extend to a multi-solution search using a hybrid quantum-classical approach to enable solutions for applications across various fields with better performance waiting to be discovered.
Acknowledgment
This work was partially supported by the Fulbright-Nehru Visiting Researcher Grant .
Code availability
The Qiskit Python implementation of the proposed BDGS algorithm is available on Github: https://github.com/hafeezzwiz21/DFGS-BDGS.
References
- [1] L. K. Grover, “Quantum mechanics helps in searching for a needle in a haystack,” Physical review letters, vol. 79, no. 2, p. 325, 1997.
- [2] C. Durr and P. Hoyer, “A quantum algorithm for finding the minimum,” arXiv, 1999.
- [3] G. Brassard, P. HØyer, and A. Tapp, “Quantum cryptanalysis of hash and claw-free functions,” In proc. LATIN 1998: Theoretical Informatics, Springer, Berlin, Heidelberg, vol. 1380, pp. 163–169, 1998.
- [4] ——, “Quantum counting,” In proc. Automata, Languages and Programming: ICALP 1998, Springer, Berlin, Heidelberg, vol. 1443, pp. 159–164, 1998.
- [5] N. J. Cerf, L. K. Grover, and C. P. Williams, “Nested quantum search and structured problems,” Phys. Rev. A, vol. 61, p. 032303, 2000.
- [6] N. Mahmud, B. Haase-Divine, A. MacGillivray, and E. El-Araby, “Quantum dimension reduction for pattern recognition in high-resolution spatio-spectral data,” IEEE Transactions on Computers, vol. 71, no. 1, pp. 1–12, 2022.
- [7] C. Zalka, “Grover’s quantum searching algorithm is optimal,” Phys. Rev. A, vol. 60, no. 4, pp. 2746–2751, 1999.
- [8] C. H. Bennett, E. Bernstein, G. Brassard, and U. Vazirani, “Strengths and weaknesses of quantum computing,” SIAM Journal on Computing, vol. 26, no. 5, pp. 1510–1523, 1997.
- [9] M. Boyer, G. Brassard, P. Høyer, and A. Tapp, “Tight bounds on quantum searching,” Fortschr. Phys., vol. 46, no. 4/5, pp. 493–505, 1998.
- [10] V. Korepin and L. Grover, “Simple algorithm for partial quantum search,” Quantum Inf Process, vol. 5, p. 5–10, 2006.
- [11] M. Heiligman, “Finding matches between two databases on a quantum computer,” 2000.
- [12] P. Niroula and Y. Nam, “A quantum algorithm for string matching,” npj Quantum Inf, vol. 7, no. 37, 2021.
- [13] P. Mateus and Y. Omar, “Quantum pattern matching,” 2005.
- [14] A. Tulsi, “Optimal quantum searching to find a common element of two sets,” 2012.
- [15] L. K. Grover and J. Radhakrishnan, “Is partial quantum search of a database any easier?” in Proceedings of the Seventeenth Annual ACM Symposium on Parallelism in Algorithms and Architectures, 2005, p. 186–194.
- [16] H. Guo, “Depth-first grover search algorithm on hybrid quantum-classical computer,” 2022.
- [17] L. K. Grover, “A fast quantum mechanical algorithm for database search,” In Proc. 28th Annu. ACM Symp. Theory Comput., pp. 212–219, 1996.
- [18] C. P. Williams, “Explorations in quantum computing,” Texts in Computer Science, Springer, 2011.
- [19] I. Chuang and M. Nielsen, Quantum computation and quantum information, 2001, vol. 54.
- [20] V. Korepin and J. Liao, “Quest for fast partial search algorithm,” Quantum Inf Process, vol. 5, p. 209–226, 2006.
- [21] R. E. Korf, “Search techniques,” in Encyclopedia of Information Systems, 2003, pp. 31–43.