Coding the DJ Algorithm

Let’s code the circuit for the Deutsch-Jozsa algorithm.

We'll cover the following

Before we formally present the code for the Deutsch-Jozsa (DJ) algorithm, let’s go back to the start of this chapter, where we covered oracles. The astute reader would have noticed that the DJ algorithm creates an oracle when defining this function $f$. In fact, we packaged the functionality of $f$ within a black box that we queried with superposition and received outputs from. We measured those outputs to reveal something about the nature of the oracle, as we stipulated that we would when we first read about oracles.

This creation of oracles and then querying them is a powerful technique in quantum computing, and many other algorithms use it. But before diving into those, let’s close off this discussion of the DJ algorithm.

As a refresher, let’s see the circuit for the constant and balanced function $f$. For constant, recall that we would not have the $CNOT$ operation or the $X$ on the ancilla. It just returns $|0\rangle$. So, the circuit for that is as follows:

Get hands-on with 1200+ tech skills courses.