# Deutsch-Jozsa algorithm

> A register of n qubits and one ancilla, an oracle U_f, and a measurement that tells constant from balanced. A quantikz example with its LaTeX source.

A quantikz example in the TeXeR TikZ library: https://texer.org/library/quantikz/deutsch-jozsa

Package: [quantikz](https://texer.org/library/quantikz.md), on CTAN at https://ctan.org/pkg/quantikz.

Tags: Deutsch-Jozsa, oracle, algorithm

## Source

```latex
\usepackage{quantikz}

\begin{quantikz}
  \lstick{$|0\rangle^{\otimes n}$} & \qwbundle{n} & \gate{H^{\otimes n}} & \gate[2]{U_f} & \gate{H^{\otimes n}} & \meter{} \\
  \lstick{$|1\rangle$} & \qw & \gate{H} & \qw & \qw & \qw
\end{quantikz}
```

## As a complete document

The same example in a document that compiles on its own with pdfLaTeX:

```latex
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{quantikz}

\begin{document}

\begin{quantikz}
  \lstick{$|0\rangle^{\otimes n}$} & \qwbundle{n} & \gate{H^{\otimes n}} & \gate[2]{U_f} & \gate{H^{\otimes n}} & \meter{} \\
  \lstick{$|1\rangle$} & \qw & \gate{H} & \qw & \qw & \qw
\end{quantikz}
\end{document}
```
