In computational complexity theory and computability theory, a **search problem** is a type of computational problem represented by a binary relation. If *R* is a binary relation such that field(*R*) ⊆ Γ^{+} and *T* is a Turing machine, then *T* calculates *R* if:

If *x* is such that there is some *y* such that *R*(*x*, *y*) then *T* accepts *x* with output *z* such that *R*(*x*, *z*) (there may be multiple *y*, and *T* need only find one of them)
If *x* is such that there is no *y* such that *R*(*x*, *y*) then *T* rejects *x*
Intuitively, the problem consists in finding structure "y" in object "x". An algorithm is said to solve the problem if at least one corresponding structure exists, and then one occurrence of this structure is made output; otherwise, the algorithm stops with an appropriate output ("Item not found" or any message of the like).

Such problems occur very frequently in graph theory, for example, where searching graphs for structures such as particular matching, cliques, independent set, etc. are subjects of interest.

Note that the graph of a partial function is a binary relation, and if *T* calculates a partial function then there is at most one possible output.

A relation *R* can be viewed as a search problem, and a Turing machine which calculates *R* is also said to solve it. Every search problem has a corresponding decision problem, namely

L
(
R
)
=
{
x
∣
∃
y
R
(
x
,
y
)
}
.
This definition may be generalized to *n*-ary relations using any suitable encoding which allows multiple strings to be compressed into one string (for instance by listing them consecutively with a delimiter).

A search problem is defined by:

A set of states
A start state
A goal state or goal test
a boolean function which tells us whether a given state is a goal state

A successor function
a mapping from a state to a set of new states

Find a solution when not given an algorithm to solve a problem, but only a specification of what a solution looks like.

Generic search algorithm: given a graph, start nodes, and goal nodes, incrementally explore paths from the start nodes.
Maintain a frontier of paths from the start node that have been explored.
As search proceeds, the frontier expands into the unexplored nodes until a goal node is encountered.
The way in which the frontier is expanded defines the search strategy.
Input: a graph,
a set of start nodes,
Boolean procedure goal(n) that tests if n is a goal node.
frontier := {s : s is a start node};
while frontier is not empty:
select and remove path <n0, ..., nk> from frontier;
if goal(nk)
return <n0, ..., nk>;
for every neighbor n of nk
add <n0, ..., nk, n> to frontier;
end while