Search code examples
quantum-computingqiskit

In Grover's Algorithm, is there a way to find 2-3 solutions with only 2 qubits?


I am currently learning grover's algorithm on qiskit(https://qiskit.org/textbook/ch-algorithms/grover.html). I notice that in the example of 2 qubits, we are looking for only one solution(|11>). Is there a way to modify the circuit so that we can find 2 or 3 solutions? Thanks!


Solution

  • Generally speaking it is possible to modify Grover's search algorithm for problems that have multiple solutions. However, for 2 qubits it's not practical to do that. For 2 solutions, we get a problem in which exactly half of the search space are solutions, and no number of Grover's iterations will increase the probability of getting a solution when doing the measurement - it will always be 50%. For 3 solutions, solutions represent more than half of the search space, so the probability of getting a solution when doing the measurement will actually decrease when doing Grover's iterations.

    If you want to explore the behavior of Grover's search algorithm for various search space sizes and solution numbers, this tutorial goes deeper into that, both with math and with visualizations of what's happening during the algorithm.