Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given below is a randomized algorithm for searching for a value x in an unsorted array consisting of n elements. The strategy it utilizes is

Given below is a randomized algorithm for searching for a value x in an unsorted array consisting of n elements. The strategy it utilizes is as follows. It randomly picks an index i between 1 and n (inclusive). If A[i] = x, it terminates. Otherwise, it continues picking random indices until it finds an index j such that A[j] = x, or it has checked every element of A. Note that it may examine a given element more than once. Give the average-case running time both in terms of T(n) and O() for this algorithm. Clearly explain how you arrived at your answer. Assume we are using 1-based indexing for the array.

Hint: Look up information about simple probability experiments, maybe a particular kind of distribution that begins with a B

search(x, A):

n = A.length();

checked = { };

found = false;

while ((! found) && (checked.size() != n)) do // assume checked.size() takes O(1) time

{

i = RANDOM(1, n); if (A[i] == x) found = true; else checked = checked U i; // assume this can be done in O(1) time

}

return(found);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

Students also viewed these Databases questions

Question

6. b is: (a) 2.049 (b) 0.31928 (c) 0.01659 (d) None of these

Answered: 1 week ago

Question

6. Be able to choose and prepare a training site.

Answered: 1 week ago