Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Algorithm 1 int linearSearch(int A[0...n1], int val) i = 0; while i < n do if val == A[i] then return i; end if i

Algorithm 1 int linearSearch(int A[0...n1], int val)

i = 0;

while i < n do

if val == A[i] then

return i;

end if

i + +;

end while

return 1;

Suppose before we call linearSearch we randomly permute (i.e., reorder) the elements in A. In the following problem, we will nd the expected asymptotic runtime of linearSearch.

a) (1 point) What is the best case asymptotic runtime of linearSearch on an array of n elements? What index must val be located at to elicit this runtime?

b) (1 point) What is the worst case asymptotic runtime of linearSearch on an array of n elements? What index must val be located at to elicit this runtime?

c) (1 point) For the sake of simplicity, assume val is in A. Let Xj be the random variable which, given an permutation of the elements in our array, is 1 if index A[j] will be checked in our linearSearch for that permutation and 0 otherwise. What is the expected value of Xj?

d) (1 point) Let X be the random variable which, given an permutation of the elements in our array, is the number of elements of A which will be checked in our linearSearch for that permutation. Dene X using n copies of the random variable dened in the previous step.

I need help please.

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 Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

Explain walter's model of dividend policy.

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago