Circuit Depth and Width
Two simple numbers summarise the structure of any quantum circuit: width and depth.
Width
The width of a circuit is the number of qubits it uses. A circuit operating on qubits has width . Width directly sets the memory cost — a width- circuit manipulates a -dimensional state vector. A circuit that introduces an ancilla qubit to assist a calculation has larger width than one that avoids it.
Depth
The depth of a circuit counts the minimum number of time-steps required when gates acting on disjoint qubits are allowed to execute in parallel. Concretely, you assign each gate to the earliest layer that does not already contain a gate on any of the same qubits. The depth is the index of the last layer needed.
Consider this three-qubit example:
Here means the Hadamard on qubit 0 and denotes a controlled-NOT with control and target . The symbol shows that the two operands run in the same layer because they act on distinct qubits. The circuit uses 3 qubits, so its width is 3, and it fills 3 layers, so its depth is 3.
Why depth matters
A naive implementation of an -qubit algorithm might place every gate sequentially, giving depth equal to the total gate count. Recognising which gates commute — because they act on different qubits — lets a compiler collapse them into the same layer, reducing depth without changing the computation. In the example above, the five gates collapse to depth 3 rather than 5.
Try it
The circuit described in the starter code has 3 qubits and the three layers shown above. Return its depth as an integer.
Sign in on the full site to ask questions and join the discussion.