Question: PProblem 1 . Consider the following RANDOM - SEARCH algorithm that searches for an integer value x in an array A [ ] that consists
PProblem Consider the following RANDOMSEARCH 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 Ak x then it terminates; otherwise, it continues the search by picking random indices into A until it finds an index j such that Aj 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 Randomu v that returns a random integer in the range u v where each integer is equally likely. RANDOMSEARCH int visitedn Comment: visitedk indicates if element Ak has been searched int numberVisited Comment: keeps track of the number of nodes visited so far for i n visitedn Comment: initialize visited while numberVisited n Comment: keep searching if there are some elements that havent been visited k Randomn if visitedk then visitedk numberVisited numberVisited if Ak x then return k; a pt Suppose there is exactly one index k such that Ak x What is the expected number of indices into A that the algorithm must pick before it finds x and RANDOMSEARCH terminates? b pt Suppose there are no indices k such that Ak x What is the expected number of indices into A that the algorithm picks before it checked all elements of A and RANDOMSEARCH terminates.roblem Consider the following RANDOMSEARCH 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 Ak x then it terminates; otherwise, it continues the search by picking random indices into A until it finds an index j such that Aj 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 Randomu 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
