1
$\begingroup$

I am studying the Bernstein-Vazirani Algorithm from the Qiskit Textbook and I don't understand why specifically the CNOT gate is applied when s[q]=1 (see the code at the end of the linked page). I know that it somehow checks whether it should flip the probability amplitude of that particular state or not, but I can't precisely explain how.

$\endgroup$

1 Answer 1

2
$\begingroup$

As you have identified yourself the CNOT is used to flip the sign of the coefficient of that particular bitstring. The reason this works is because $|+\rangle$ and $|-\rangle$ are the eigenvectors of the $X$ gate with eigenvalues 1 and -1 respectively:

$$ |\psi\rangle \otimes X|-\rangle = 1/\sqrt{2}(|\psi\rangle \otimes X(|0\rangle-|1\rangle)) $$ $$ = 1/\sqrt{2}(|\psi\rangle \otimes (-|0\rangle+|1\rangle)) $$ $$ =-|\psi\rangle \otimes |-\rangle $$ So the CNOT will flip the sign of the state if the control qubit is 1.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.