Question: PProblem 1 . Consider the following RANDOM - SEARCH algorithm that searches for an integer value x in an array A [ ] that consists

PProblem 1. Consider the following RANDOM-SEARCH algorithm that searches for an integer value x in an array A[] that consists of n elements. The algorithm picks a random index k into A. If A[k]= x then it terminates; otherwise, it continues the search by picking random indices into A[] until it finds an index j such that A[j]= x or until it checked every element of A[]. Note that it picks from the whole set of indices each time, so that it may examine a given element more than once. It uses a random number generator (or a pseudo random number generator) Random(u, v) that returns a random integer in the range [u, v], where each integer is equally likely. RANDOM-SEARCH int visited[n] Comment: visited[k] indicates if element A[k] has been searched int numberVisited =0 Comment: keeps track of the number of nodes visited so far for i =1,2,... n visited[n]=0 Comment: initialize visited while numberVisited < n Comment: keep searching if there are some elements that havent been visited k = Random(1,n) if visited[k]=0 then visited[k]=1 numberVisited = numberVisited 1 if A[k]= x then return k; (a)[5 pt] Suppose there is exactly one index k such that A[k]= x. What is the expected number of indices into A[] that the algorithm must pick before it finds x and RANDOM-SEARCH terminates? (b)[5 pt] Suppose there are no indices k such that A[k]= x. What is the expected number of indices into A[] that the algorithm picks before it checked all elements of A[] and RANDOM-SEARCH terminates.roblem 1. Consider the following RANDOM-SEARCH algorithm that searches for an integer value x in an array A[] that consists of n elements. The algorithm picks a random index k into A. If A[k]= x then it terminates; otherwise, it continues the search by picking random indices into A[] until it finds an index j such that A[j]= x or until it checked every element of A[]. Note that it picks from the whole set of indices each time, so that it may examine a given element more than once. It uses a random number generator (or a pseudo random number generator) Random(u, v) that returns a random integer in the range [u, v], where

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!