I've always been confused as to when a quantum algorithm is allowed to have an oracle and what kind of a function the oracle can have. For instance, I know in Hamiltonian simulation algorithms, you need an oracle $O_H$ to access the matrix elements of the Hamiltonian $H$. This seems fine to me since a general Hamiltonian simulation algorithm doesn't know of the specific structure of the Hamiltonian it's trying to simulate, so it delegates that knowledge to the oracle.

On the other hand, in Grover's algorithm, the oracle applies an $e^{i\pi}$ phase to the state if it's a solution state, and doesn't do anything otherwise. This has always been sketchy to me since it seems like the oracle already knows what the solution state is, so how could you even construct it in the first place?

I'm trying to understand when it is justified to have an oracle in an algorithm, and how can we tell if a potential oracle can/cannot be constructed? Any insight would be greatly appreciated!


2 Answers 2


Your question already contains the answer: oracles are used when the general algorithm described doesn't know the specific structure of the problem it's solving and thus cannot rely on it. In this case the algorithm delegates any knowledge of the specific problem being solved to the oracle. When the algorithm is implemented for a specific problem, it uses the oracle implementation to access that information.

Now, the second part of the question is how to implement the oracle for Grover's search without knowing the solution upfront. There are a lot of great answers to this at the oracles tag of this site. In short, the oracle doesn't hardcode the list of answers; it encodes the conditions that the answers must satisfy. For example, for a SAT problem, the answers are bit strings, and the condition is that the given SAT formula has to evaluate to true for the variable assignment that is a solution. The oracle then implements the formula evaluation and the check that the result is true, rather than hardcodes the bit strings.


It is true that in case of Grover algorithm you more or less tells the oracle which basis state probability amplitude should be amplified. This can be confusing but lets imagine that we are looking for a string representing for example number of a quantum state stored a in quantum memory. Once the string is marked, you can get the item from the memory, similarly to looking for e.g. a personal card based on name of an employee.

However, we still do not have a reliable quantum memory. But fortunately, we can employ Grover algorithm in binary function extremes finding. In article Grover Adaptive Search, it was devised that a special kind of oracle can be constructed based on parameters of an objective function in QUBO problems. The oracle marks minimum of that function without knowing a solution in advance. This is probably what confuses you when you look at textbooks examples of Grover algorithm for database searching. In case of adaptive search, knowing the solution before is not necessary and probability amplitude amplification is really used for finding the solution.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.