Finding one of 2/3 of all array elements in constant expected time
-
04-11-2019 - |
题
How do I go about designing a constant time algorithm which satisfies the following I/O requirements:
Input: an array $A$ of length $3n$, containing $2n$ values of the symbol $X$ and $n$ of the symbol $Y$
Output: a number $i$, such that $A[i]=X$
It is clear that the naive linear scan approach is $O(n)$. Is there any good algorithm, potentially randomized, that has a constant number of expected operations $O(1)$?
没有正确的解决方案
不隶属于 cs.stackexchange