Please teach the construction law of Orcle Uf in Grover's algorithm

The framework of Grover’s algorithm is shown in Figure from Qiskit.

But I didn’t understand the tutorial’s construction rules for U_f. If there are four qubits, labeled 0001, 0010, 1001, and 1110, how to design U_f? If there are 5 bits, labeled 00101, 01010, 10101, and 11110, how to design U_f? Can you summarize in code how Uf imposes CZ gates?


Hey @R-X!

Great question. I think you should check out our YouTube video for Grover’s algorithm:

It should answer a lot of your questions!