# Implementation of the oracle of Grover's algorithm on IBM Q using three qubits

I am trying to get used to IBM Q by implementing three qubits Grover's algorithm but having difficulty to implement the oracle.

Could you show how to do that or suggest some good resources to get used to IBM Q circuit programming?

What I want to do is to mark one arbitrary state by flipping its sign as the oracle supposed to do.

For example, I have

$1/\sqrt8(|000\rangle+|001\rangle+|010\rangle+|011\rangle+|100\rangle+|101\rangle+|110\rangle+|111\rangle)$.

and I want to mark $|111\rangle$ by flipping its sign to $-|111\rangle$. I somehow understand that CCZ gate would solve the problem but we do not have CCZ gate in IBM Q. The combination of some gates will act the same as CCZ but I am not sure how to do that yet. And I am also struggling for the other cases not only for $|111\rangle$.

Two qubits case is simple enough for me to implement, but three qubits care is still confusing to me.

• Their documentation includes some examples of Grover's algorithm, although I do not remember how big the search space was. – Norrius Jun 1 '18 at 0:33
• Thanks for the comment. Yes, this page (quantumexperience.ng.bluemix.net/proxy/tutorial/full-user-guide/…) explains two qubits Grover's algorithm implementation. – Bick Jun 1 '18 at 14:12

For the 3 qubit state you presented, you can use an oracle like the one here (I'm using quirk just to show the amplitudes in real time). Note that the first three Hadamards (the ones before the ...) are there only to simulate a random input to the oracle and are not part of the oracle itself. In every case, as you can see from the amplitudes at the end of the circuit, only the $$|111\rangle$$ state gets flipped out, while all the other states remain unchanged.