# Quantum circuit CCX optimization for Grover

I am working on a circuit for a Grover problem and during that I am trying to minimize the used QuBits.

The problem is shown in the attached image. In this case the circuit is more or less efficient but with a growing number of input bits (the x register) the ccx grows more complex (cccx, ccccx, ...) and inefficient but more importantly more qubits in y register are needed (one more for each comparison).

My primary goal is to reduce the used y-QuBits. Can someone think of such a circuit or is it already optimal (I really dont think so).

Instead of saving the information of a single comparison into a y qubit, you can use a controlled adder. Instead of $$n$$ y qubits you would only need $$\log_2 n$$.