Searching with a three qubit Grover
The 3-qubit Grover algorithm is very similar to the two qubit implementation that we explored in the previous recipe. The main difference is in how we build the oracle circuit for three instead of two qubits, building a phase kickback that adds the phase to two qubits instead of one.
To do this, we have to use a controlled-NOT gate that uses two qubits as input to flip the third to entangle the qubits and mark the correct answer with a phase. That gate is the Toffoli (CCX) gate instead of the CX gate.
In the following example, the two qubit input Toffoli gate (CCX) with 2 controlling qubits and 1 controlled qubit serves as the phase kickback that shifts the phase of the state by if the value of the three qubits matches the correct answer:
We will be using the same sample functions as in The Grover search algorithm recipe.
How to do it...
To create a three qubit...