Question: What is the worst-case running time of Find-Index-2(A[1 : n])? What about its worst-case expected running time? Remember to prove your answer formally.
Question: What is the worst-case running time of Find-Index-2(A[1 : n])? What about its worst-case
expected running time? Remember to prove your answer formally.
![Find-Index-2(A[1 : n]):
• For j = 1 to n:
Sample i e {1, ..., n} uniformly at random and if A[i] mod 8 € {1,2}, output i and terminate;
otherwise, continue.
• If the for-loop never terminated, go over the array A one element at a time to find an index i with A[i]
mod 8 E {1, 2} and output it as the answer.
Again, we skip the proof of correctness of this algorithm.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5ff83b3f-35bb-4190-932b-2e5a6e904b7a%2F362fba9e-da80-45dd-9e7a-6cf3e55acff0%2F4o25wwa_processed.png&w=3840&q=75)
![Problem 2. Suppose we have an array A[1 : n] which consists of numbers {1,..., n} written in some
arbitrary order (this means that A is a permutation of the set {1,...,n}). Our goal in this problem is to
design a very fast randomized algorithm that can find an index i in this array such that A[i] mod 8 E {1,2},
i.e., the reminder of dividing A[i] by 8 is either 1 or 2. For simplicity, in the following, we assume that n
itself is a multiple of 8 and is at least 8 (so a correct answer always exist).
For instance, if n = 8 and the array is A = [8,7, 2, 5, 4, 6, 3, 1], we want to output either of indices 3 or 8.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5ff83b3f-35bb-4190-932b-2e5a6e904b7a%2F362fba9e-da80-45dd-9e7a-6cf3e55acff0%2Fjzwxytb_processed.png&w=3840&q=75)

Solution:--
1)The given question has required for the solution to be provided with the help of correctness in
the solution for finding the index - 2.
2)As it has been specifically mentioned in the question is to find the index-2 for the A([1:n]) as
stated.
3)A for loop is been applied with the help of the j which is been initialized to 1 upto the range of
the n.
4)Some other regulations and the guidelines are also given in the question and it is required to be
followed in providing the solution.
5)Note:-- I have provided the required answer for the given problem in the next following step
respectively.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps









