# Randomized Algorithms (Spring 2010)/Complexity classes and lower bounds

Last time we talked about algorithms. Today's topic is complexity.

## Upper bounds, lower bounds

Bounds are just inequalities (in a general sense, e.g. asymptotic inequalities). An inequality

${\displaystyle A\leq B}$

is read "${\displaystyle A}$ is a lower bound of ${\displaystyle B}$" or equivalently "${\displaystyle B}$ is an upper bound of ${\displaystyle A}$".

In Computer Science, when talking about upper or lower bounds, people really mean the upper or lower bounds of complexities.

In this lecture, we are focused on the time complexity, although there are other complexity measures in various computational models (e.g. space complexity, communication complexity, query complexity).

The complexity is represented as a function of ${\displaystyle n}$, where ${\displaystyle n}$ is the length of the input.

There are two fundamental ways of measuring complexities

Complexity of algorithms
For an algorithm ${\displaystyle A}$, the (worst-case) time complexity of ${\displaystyle A}$ is the maximum running time over all inputs ${\displaystyle x}$ of length ${\displaystyle n}$.
Complexity of problems
For a computational problem, its time complexity is the time complexity of the optimal algorithm which solves the problem.

The complexity of an algorithm tells how good the algorithm is, yet the complexity of a problems tells how hard the problem is. While the former is what we care mostly about in practice, the later is more about the fundamental truths of computation.

In Theoretical Computer Science, when talking about upper or lower bounds, people usually refer to the bounds of the complexities of problems, rather than those of algorithms. Therefore, an upper bound means an algorithm; and a lower bound means bad news such as impossibility results.

Today's lecture is devoted to lower bounds, i.e. the necessary prices which have to paid by any algorithms which solve the given problems. Speaking of necessary prices, we have to be specific about the model, the mathematical rules which stipulate what is problem and what is algorithm.

### Decision problems

Computational problems are functions mapping inputs to outputs. Sometimes, an input is called an instance of the problem and an output is called a solution to that instance. The theory of complexity deals almost exclusively with decision problems, the computational problems with yes-or-no answers.

For a decision problem ${\displaystyle f}$, its positive instances are the inputs with "yes" answers. A decision problem can be equivalently represented as the set of all positive instances, denoted ${\displaystyle L}$. We call ${\displaystyle L}$ a formal language (not entirely the same thing as the c language). The task of computing ${\displaystyle f(x)}$ is equivalent to that of determining whether ${\displaystyle x\in L}$. Therefore the two formulations of "decision problems" and "formal languages" can be interchangeably used.

### Turing Machine

In order to study complexities, which deal with the limits of computations, we have to be clear about what computation is, that is, modeling computations.

This work was done by Alan Turing in 1937. The model is now referred by the name Turing machine.

## Complexity Classes

Problems are organized into classes according to their complexity in respective computational models. There are nearly 500 classes collected by the Complexity Zoo.

### P, NP

A deterministic algorithm ${\displaystyle A}$ is polynomial time if its running time is within a polynomial of ${\displaystyle n}$ on any input of length ${\displaystyle n}$.

 Definition (P) The class P is the class of decision problems that can be computed by polynomial time algorithms.

We now introduce the infamous NP class.

 Definition (NP) The class NP consists of all decision problems ${\displaystyle f}$ that have a polynomial time algorithm ${\displaystyle A}$ such that for any input ${\displaystyle x}$, ${\displaystyle f(x)=1}$ if and only if ${\displaystyle \exists y}$, ${\displaystyle A(x,y)=1}$, where the size of ${\displaystyle y}$ is within polynomial of the size of ${\displaystyle x}$

Informally, NP is the class of decision problems that the "yes" instances can be verified in polynomial time. The string ${\displaystyle y}$ in the definition is called a certificate or a witness. Provided a polynomial size certificate, the algorithm ${\displaystyle A}$ verifies (instead of computing) the ${\displaystyle f(x)}$ for any positive instance ${\displaystyle x}$ in polynomial time.

Example
Both the problems of deciding whether an input array is sorted and deciding whether an input graph has Hamiltonian cycles are in NP. For the former one, the input array itself is a certificate. And for the later one, a Hamiltonian cycle in the graph is a certificate (given a cycle, it is easy to verify whether it is Hamiltonian).

This definition is one of the equivalent definitions of the NP class. Another definition (also a classic one) is that NP is the class of decision problems that can be computed by polynomial time nondeterministic algorithms.

Common misuses of the terminology:

• "This algorithm is NP." --- NP is a class of decision problems, not algorithms.
• "This problem is a NP problem, so it must be very hard." --- By definition, a problem is in NP if its positive instances are poly-time verifiable, which implies nothing about the hardness. You probably means the problem is NP-hard.
• "NP problems are the hardest problems." --- There are infinitely many harder problems outside NP. Actually, according to a widely believed conjecture, there are infinitely many classes of problems which are harder than NP (see [1]).

Note that unlike P, the definition of NP is asymmetric. It only requires the positive instances (the ${\displaystyle x}$ that ${\displaystyle f(x)=1}$) to be poly-time verifiable, but does not say anything about the negative instances. The class for that case is co-NP.

 Definition (co-NP) The class co-NP consists of all decision problems ${\displaystyle f}$ that have a polynomial time algorithm ${\displaystyle A}$ such that for any input ${\displaystyle x}$, ${\displaystyle f(x)=0}$ if and only if ${\displaystyle \exists y}$, ${\displaystyle A(x,y)=0}$, where the size of ${\displaystyle y}$ is within polynomial of the size of ${\displaystyle x}$

Clearly, P ${\displaystyle \subseteq }$ NP ${\displaystyle \cap }$ co-NP. Does P = NP ${\displaystyle \cap }$ co-NP? It is an important open problem in the complexity theory which is closely related to our understanding of the relation between NP and P.

### ZPP, RP, BPP

Now we proceeds to define complexity classes of the problems that is efficiently computable by the randomized algorithms, i.e. the randomized analogs of P.

In the last class we learned that there are two types of randomized algorithms: Monte Carlo algorithms (randomized algorithms with erros) and Las Vegas algorithms (randomized algorithms with random running time but with no erros). For Monte Carlo algorithms, there are two types of errors: one-sided errors where the algorithm errs only for positive instances, and two-sided errors where there are both false positives and false negatives. Therefore, there are three cases to deal with:

1. Las Vegas algorithms, the corresponding class is ZPP (for Zero-error Probabilistic Polynomial time).
2. Monte Carlo algorithms with one-sided error, the corresponding class is RP (for Randomized Polynomial time).
3. Monte Carlo algorithms with two-sided error, the corresponding class is BPP (for Bounded-error Probabilistic Polynomial time).

We first introduce the class ZPP of the problems which can be solved by polynomial time Las Vegas algorithms. For Las Vegas algorithms, the running time is a random variable, therefore we actually refer to the Las Vegas algorithms whose expected running time is within a polynomial of ${\displaystyle n}$ for any input of size ${\displaystyle n}$, where the expectation is taken over the internal randomness (coin flippings) of the algorithm.

 Definition (ZPP) The class ZPP consists of all decision problems ${\displaystyle f}$ that have a randomized algorithm ${\displaystyle A}$ running in expected polynomial time for any input such that for any input ${\displaystyle x}$, ${\displaystyle A(x)=f(x)}$.

Next we define the class RP of the problems which can be solved by polynomial time Monte Carlo algorithms with one-sided error.

 Definition (RP) The class RP consists of all decision problems ${\displaystyle f}$ that have a randomized algorithm ${\displaystyle A}$ running in worst-case polynomial time such that for any input ${\displaystyle x}$, if ${\displaystyle f(x)=1}$, then ${\displaystyle \Pr[A(x)=1]\geq 1-1/2}$; if ${\displaystyle f(x)=0}$, then ${\displaystyle \Pr[A(x)=0]=1}$.
Remark
The choice of the error probability is arbitrary. In fact, replacing the 1/2 with any constant ${\displaystyle 0 will not change the definition of RP.
Example
Define the decision version of the minimum cut problem as follows. For a graph ${\displaystyle G}$, ${\displaystyle f(G)=1}$ if and only if there exists any cut of size smaller than ${\displaystyle k}$, where ${\displaystyle k}$ is an arbitrary parameter. The problem ${\displaystyle f}$ can be solved probabilistically by Karger's min-cut algorithm in polynomial time. The error is one-sided, because if there does not exists any cut of size smaller than ${\displaystyle k}$, then obviously the algorithm cannot find any. Therefore ${\displaystyle f\in }$RP.

Like NP, the class RP is also asymmetrically defined, which hints us to define the co-RP class.

 Definition (co-RP) The class co-RP consists of all decision problems ${\displaystyle f}$ that have a randomized algorithm ${\displaystyle A}$ running in worst-case polynomial time such that for any input ${\displaystyle x}$, if ${\displaystyle f(x)=1}$, then ${\displaystyle \Pr[A(x)=1]=1}$; if ${\displaystyle f(x)=0}$, then ${\displaystyle \Pr[A(x)=0]\geq 1-1/2}$.

We then define the class BPP of the problems which can be solved by polynomial time Monte Carlo algorithms with two-sided error.

 Definition (BPP) The class BPP consists of all decision problems ${\displaystyle f}$ that have a randomized algorithm ${\displaystyle A}$ running in worst-case polynomial time such that for any input ${\displaystyle x}$, if ${\displaystyle f(x)=1}$, then ${\displaystyle \Pr[A(x)=1]\geq 1-1/4}$; if ${\displaystyle f(x)=0}$, then ${\displaystyle \Pr[A(x)=0]\geq 1-1/4}$.
Remark
Replacing the error probability from ${\displaystyle {\frac {1}{4}}}$ to ${\displaystyle {\frac {1}{3}}}$, or any constant ${\displaystyle 0 will not change the definition of the BPP class.

What is known (you can even prove by yourself):

• RP, BPP, ZPP all contain P
• RP ${\displaystyle \subseteq }$ NP
• ZPP = RP${\displaystyle \cap }$co-RP;
• RP ${\displaystyle \subseteq }$ BPP;
• co-RP ${\displaystyle \subseteq }$ BPP.

Open problem:

• BPP vs P (the second most important open problem in the complexity theory to the NP vs P).

## Yao's minimax principle

Given a problem ${\displaystyle f}$, how to prove the lower bound of ${\displaystyle f}$ for randomized algorithms? This sounds very hard, because we have to show that for all randomized algorithms which solve the problem ${\displaystyle f}$, the expected performance is bad. How can we do that? The following principle is due to Andrew Chi-Chih Yao (姚期智):

 Yao's Minimax Principle For any problem ${\displaystyle f}$, for any probability distribution ${\displaystyle {\mathcal {P}}}$ over the input domain, the expected running time of the optimal (Las Vegas) randomized algorithm ${\displaystyle \geq }$ the expected running time of the optimal deterministic algorithm on the input generated by ${\displaystyle {\mathcal {P}}}$.

In other words, the performance of the optimal randomized algorithm is lower bounded by the average (with respect to an arbitrary distribution of the inputs) performance of the optimal deterministic algorithm. Therefore, the task of proving lower bounds of randomized algorithms is reduced to the task of proving lower bounds of the average-case performances of deterministic algorithms, which sounds like a much more doable task (not to mention that the input distribution is chosen by us).

More than 30 years has past since its first publication. Yao's principle remains the only general technique for proving lower bounds for randomized algorithms.

### Proof of the principle

First, we have to realize what randomized algorithms really are. We make the following observation:

A (Las Vegas) randomized algorithm for a problem ${\displaystyle f}$ is a probability distribution over all deterministic algorithms for ${\displaystyle f}$.

Then we can formally state the Yao's principle.

 Yao's Minimax Principle (formally stated) Let ${\displaystyle f}$ be a problem with a finite set ${\displaystyle {\mathcal {X}}}$ of input instances of a fixed size ${\displaystyle n}$, and a finite set of deterministic algorithms ${\displaystyle {\mathcal {A}}}$. For input ${\displaystyle x\in {\mathcal {X}}}$ and algorithm ${\displaystyle A\in {\mathcal {A}}}$, let ${\displaystyle T(A,x)}$ denote the running time of algorithm ${\displaystyle A}$ on input ${\displaystyle x}$. Then for all distributions ${\displaystyle {\mathcal {P}}}$ over ${\displaystyle {\mathcal {X}}}$ and ${\displaystyle {\mathcal {Q}}}$ over ${\displaystyle {\mathcal {A}}}$, {\displaystyle {\begin{aligned}\min _{A\in {\mathcal {A}}}\mathbf {E} _{x:{\mathcal {P}}}\left[T(A,x)\right]&\leq \max _{x\in {\mathcal {X}}}\mathbf {E} _{A:{\mathcal {Q}}}\left[T(A,x)\right]\end{aligned}}}.

We exhibit two proofs of the principle. One is due to the probabilistic method, the other is due to game theory.

#### Proof by probabilistic arguments

Let ${\displaystyle t_{0}=\min _{A\in {\mathcal {A}}}\mathbf {E} _{x:{\mathcal {P}}}\left[T(A,x)\right]}$. Then ${\displaystyle \forall A_{0}\in {\mathcal {A}}}$, it holds that ${\displaystyle \mathbf {E} _{x:{\mathcal {P}}}\left[T(A_{0},x)\right]\geq t_{0}}$. Let ${\displaystyle A\in {\mathcal {A}}}$ be generated from the distribution ${\displaystyle {\mathcal {Q}}}$ over ${\displaystyle {\mathcal {A}}}$. Due to the law of total expectation, it holds that

{\displaystyle {\begin{aligned}\mathbf {E} _{x:{\mathcal {P}},A:{\mathcal {Q}}}\left[T(A,x)\right]&=\sum _{A_{0}\in {\mathcal {A}}}\mathbf {E} _{x:{\mathcal {P}},A:{\mathcal {Q}}}\left[T(A,x)\mid A=A_{0}\right]\cdot \Pr _{A:{\mathcal {Q}}}[A=A_{0}]\\&=\sum _{A_{0}\in {\mathcal {A}}}\mathbf {E} _{x:{\mathcal {P}}}\left[T(A_{0},x)\right]\cdot \Pr _{A:{\mathcal {Q}}}[A=A_{0}]\\&\geq \sum _{A_{0}\in {\mathcal {A}}}t_{0}\cdot \Pr _{A:{\mathcal {Q}}}[A=A_{0}]\\&=t_{0}.&&(*)\end{aligned}}}

Actually, the above inequalities can be implied by an almost naive observation: "if all cases are at least ${\displaystyle t_{0}}$, then the weighted average over these cases cannot be smaller than ${\displaystyle t_{0}}$."

Then we apply this argument again to the inputs, this time in another direction: "If the weighted average is no smaller than ${\displaystyle t_{0}}$, then there must be a case which is at least ${\displaystyle t_{0}}$."

Formally, expanding ${\displaystyle \mathbf {E} _{x:{\mathcal {P}},A:{\mathcal {Q}}}\left[T(A,x)\right]}$ by ${\displaystyle x}$,

{\displaystyle {\begin{aligned}\mathbf {E} _{x:{\mathcal {P}},A:{\mathcal {Q}}}\left[T(A,x)\right]&=\sum _{x_{0}\in {\mathcal {X}}}\mathbf {E} _{x:{\mathcal {P}},A:{\mathcal {Q}}}\left[T(A,x)\mid x=x_{0}\right]\cdot \Pr _{x:{\mathcal {P}}}[x=x_{0}]\\&=\sum _{x_{0}\in {\mathcal {X}}}\mathbf {E} _{A:{\mathcal {Q}}}\left[T(A,x_{0})\right]\cdot \Pr _{x:{\mathcal {P}}}[x=x_{0}].&&(**)\end{aligned}}}

Due to Equation ${\displaystyle (*)}$, it holds that ${\displaystyle \mathbf {E} _{x:{\mathcal {P}},A:{\mathcal {Q}}}\left[T(A,x)\right]\geq t_{0}}$. Then it must hold that

{\displaystyle {\begin{aligned}\exists x_{0}\in {\mathcal {X}},{\mbox{such that }}\mathbf {E} _{A:{\mathcal {Q}}}\left[T(A,x_{0})\right]\geq t_{0}=\min _{A\in {\mathcal {A}}}\mathbf {E} _{x:{\mathcal {P}}}\left[T(A,x)\right],&&(***)\end{aligned}}}

because if to the contrary ${\displaystyle \forall x_{0}\in {\mathcal {X}},\mathbf {E} _{A:{\mathcal {Q}}}\left[T(A,x_{0})\right], then due to Equation ${\displaystyle (**)}$, it holds that ${\displaystyle \mathbf {E} _{x:{\mathcal {P}},A:{\mathcal {Q}}}\left[T(A,x)\right], which contradicts ${\displaystyle (*)}$.

Finally, ${\displaystyle (***)}$ implies that

{\displaystyle {\begin{aligned}\max _{x\in {\mathcal {X}}}\mathbf {E} _{A:{\mathcal {Q}}}\left[T(A,x)\right]\geq \min _{A\in {\mathcal {A}}}\mathbf {E} _{x:{\mathcal {P}}}\left[T(A,x)\right],\end{aligned}}}

The Yao's principle is proved.

#### Proof by game-theoretical arguments

von Neumann's Minimax Theorem
For any two-player zero-sum game with a payoff matrix ${\displaystyle M}$,
{\displaystyle {\begin{aligned}\max _{p}\min _{q}p^{T}Mq&=\min _{q}\max _{p}p^{T}Mq\end{aligned}}}.
Loomis' Theorem
For any two-player zero-sum game with a payoff matrix ${\displaystyle M}$,
{\displaystyle {\begin{aligned}\max _{p}\min _{j}p^{T}Me_{j}&=\min _{q}\max _{i}e_{i}^{T}Mq.\end{aligned}}}
where ${\displaystyle e_{k}}$ denotes the unit vector with 1 in the ${\displaystyle k}$th position and 0s elsewhere.
Yao's Minimax Principle
Let ${\displaystyle f}$ be a problem with a finite set ${\displaystyle {\mathcal {X}}}$ of input instances of a fixed size ${\displaystyle n}$, and a finite set of deterministic algorithms ${\displaystyle {\mathcal {A}}}$. For input ${\displaystyle x\in {\mathcal {X}}}$ and algorithm ${\displaystyle A\in {\mathcal {A}}}$, let ${\displaystyle T(A,x)}$ denote the running time of algorithm ${\displaystyle A}$ on input ${\displaystyle x}$. Then for all distributions ${\displaystyle {\mathcal {P}}}$ over ${\displaystyle {\mathcal {X}}}$ and ${\displaystyle {\mathcal {Q}}}$ over ${\displaystyle {\mathcal {A}}}$,
{\displaystyle {\begin{aligned}\min _{A\in {\mathcal {A}}}\mathbf {E} _{x:{\mathcal {P}}}\left[T(A,x)\right]&\leq \max _{x\in {\mathcal {X}}}\mathbf {E} _{A:{\mathcal {Q}}}\left[T(A,x)\right]\end{aligned}}}.

### Proving lower bounds with Yao's principle

Suppose that ${\displaystyle \pi }$ is an arbitrary permutation of a set ${\displaystyle S}$ of ${\displaystyle n}$ elements, and we want to find the position of an arbitrary element ${\displaystyle x\in S}$ in ${\displaystyle \pi }$, with as few accesses to ${\displaystyle \pi }$ as possible.

For deterministic algorithms, with a simple adversary argument, we know that any deterministic algorithm has to access ${\displaystyle n-1}$ positions of ${\displaystyle \pi }$ in the worst case. A very natural randomized algorithm for this problem is:

repeat for (n-1) times:
uniformly pick a random position r from all unaccessed positions;
if π(r) = x, then return r;
return the only unaccessed position;


The algorithm can be equivalently viewed as first randomly reordering the ${\displaystyle \pi }$, and then scanning from the 1st position to the ${\displaystyle (n-1)}$th position of the reordered permutation to find ${\displaystyle x}$. If ${\displaystyle x}$ is in the last position of the reordered permutation, then after accessing the first ${\displaystyle (n-1)}$ positions we automatically know that the last one must be ${\displaystyle x}$.

For any ${\displaystyle \pi }$ and ${\displaystyle x}$, ${\displaystyle x}$ is in every position of the randomly reordered ${\displaystyle \pi }$ with equal probability ${\displaystyle {\frac {1}{n}}}$. The expected number of accesses made by our randomized searching algorithm is:

{\displaystyle {\begin{aligned}{\frac {1}{n}}\left((n-1)+\sum _{k=1}^{n-1}k\right)&={\frac {n+1}{2}}-{\frac {1}{n}}\end{aligned}}}

How good is it? Is there any randomized algorithm that can do better than this? With the help of Yao's principle, we can prove that this bound is the best we can get.

We analyze this problem first for a special class of algorithms, then generalize to all algorithms.

#### Lower bound for oblivious algorithms

We call a search algorithm oblivious if the algorithm follows the same predetermined order to access the positions of any input permutation. For example, the following code of linearly scanning all positions is a typical oblivious algorithm.

for(i=1 to n-1){
if π(i) = x
return i;
}
return n;


Without loss of generality, we can rule out those stupid algorithms that access the same position twice. (Since we are proving lower bound, we are safe to do this.) Therefore, a deterministic oblivious algorithm can be represented by a permutation ${\displaystyle \rho }$ of ${\displaystyle \{1,2,\ldots ,n\}}$, where the ${\displaystyle i}$th position to access is specified by ${\displaystyle \rho (i)}$. By a simple adversary argument, we know that except the last element (which can be figured out by knowing the rest ${\displaystyle n-1}$ elements), the algorithm has to access the exact position which stores ${\displaystyle x}$. Therefore, the following lemma holds:

 Lemma 1 For an input permutation ${\displaystyle \pi }$ and element ${\displaystyle x}$, an oblivious algorithm with access sequence ${\displaystyle \rho }$ has to access ${\displaystyle k}$ many positions, where either ${\displaystyle \pi (\rho (k))=x}$ or ${\displaystyle k=n-1}$.

A randomized oblivious algorithm is a probability distribution ${\displaystyle {\mathcal {Q}}}$ over all oblivious algorithms. Due to Yao's principle, to prove a lower bound for randomized oblivious algorithms, it is sufficient to lower bound the expected number of accesses required by any deterministic oblivious algorithm (a permutation ${\displaystyle \rho }$ of ${\displaystyle \{1,2,\ldots ,n\}}$) for the random permutation ${\displaystyle \pi }$ of ${\displaystyle S}$ and the random ${\displaystyle x\in S}$.

Let ${\displaystyle \pi }$ be a uniformly random permutation of ${\displaystyle S}$ and ${\displaystyle x}$ be uniformly chosen from ${\displaystyle S}$. Because of the symmetry, we can assume that the access sequence ${\displaystyle \rho }$ is just ${\displaystyle 1,2,\ldots ,n}$. This is because changing to any other access sequence will not change the distribution of the ${\displaystyle i}$th accessed element ${\displaystyle \pi (\rho (i))}$ for any ${\displaystyle i}$ (verify this by yourself).

Because both ${\displaystyle x}$ and ${\displaystyle \pi }$ are uniform, ${\displaystyle x}$ appears in each position of ${\displaystyle \pi }$ with equal probability. Due to Lemma 1, assuming that ${\displaystyle x}$ is in the ${\displaystyle k}$th position, the number of accesses needed by the algorithm is ${\displaystyle k}$ if ${\displaystyle k and is ${\displaystyle (n-1)}$ if ${\displaystyle k=n}$. Taking the average, the expected number of accesses is

{\displaystyle {\begin{aligned}{\frac {1}{n}}\left((n-1)+\sum _{k=1}^{n-1}k\right)&={\frac {n+1}{2}}-{\frac {1}{n}}\end{aligned}}}

Due to Yao's principle, this gives the lower bound of the expected running time of randomized oblivious algorithms for the problem.

#### Lower bound for adaptive algorithms

For an adaptive algorithm, the next position to access is determined by the results of all previous accesses.

Formally, let ${\displaystyle \tau }$ be a decision tree such that for an input permutation ${\displaystyle \pi }$ and an input element ${\displaystyle x}$, the ${\displaystyle k}$th accessed position ${\displaystyle i_{k}}$ is given by

{\displaystyle {\begin{aligned}i_{k}&={\begin{cases}\tau (x)&{\mbox{if }}k=1\\\tau \left(x,\pi \left(i_{1}\right),\pi \left(i_{2}\right),\ldots ,\pi \left(i_{k-1}\right)\right)&{\mbox{if }}k>1\end{cases}}\end{aligned}}}

The following figure illustrates the structure of the decision tree ${\displaystyle \tau }$:

360px

This decision tree is an ${\displaystyle n}$-ary labeled tree. The label of each edge is the input to ${\displaystyle \tau }$, and the label of each node is the access position returned by ${\displaystyle \tau }$ for the sequence specified by the labels along the path from the root to the node.

This model seems having substantially more power than the oblivious algorithms, because it allows the algorithm be adaptive to the input. It actually covers all possible algorithms (no matter realistic or unrealistic) for the problem.

By an adversary argument, the algorithm still has to either access the position which stores ${\displaystyle x}$ or access ${\displaystyle (n-1)}$ positions, because if otherwise the adversary can always let ${\displaystyle x}$ be stored in the position which is not the one returned by the algorithm.

Apply Yao's principle. Let ${\displaystyle \pi }$ be a uniformly random permutation of ${\displaystyle S}$ and ${\displaystyle x}$ be uniformly chosen from ${\displaystyle S}$. Due to the uniformity of ${\displaystyle \pi }$, conditioning on any ${\displaystyle \pi \left(i_{1}\right),\pi \left(i_{2}\right),\ldots ,\pi \left(i_{k-1}\right)}$ and any ${\displaystyle x}$, for any ${\displaystyle i_{k}\not \in \{i_{1},i_{2},\ldots ,i_{k-1}\}}$, it holds that ${\displaystyle \pi (i_{k})}$ is uniformly distributed over the set ${\displaystyle S-\{\pi \left(i_{1}\right),\pi \left(i_{2}\right),\ldots ,\pi \left(i_{k-1}\right)\}}$ of the unaccessed elements, and the distribution of ${\displaystyle \pi (i_{k})}$ is independent of ${\displaystyle \pi \left(i_{1}\right),\pi \left(i_{2}\right),\ldots ,\pi \left(i_{k-1}\right)}$ and ${\displaystyle x}$.

The above probability distribution is the same for both the oblivious ${\displaystyle \{i_{1},i_{2},\ldots ,i_{k-1}\}}$ which are fixed independent of ${\displaystyle \pi }$ and the adaptive ${\displaystyle \{i_{1},i_{2},\ldots ,i_{k-1}\}}$ which depends on ${\displaystyle \pi }$ and ${\displaystyle x}$. Therefore the expected number of accesses needed by an adaptive algorithms is the same as that of an oblivious algorithm. The same lower bound of ${\displaystyle {\frac {n+1}{2}}-{\frac {1}{n}}}$ holds.