Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code below searches an unsorted array, A, for a given value. It returns the index of the value if it is present. Otherwise it

image text in transcribed
The code below searches an unsorted array, A, for a given value. It returns the index of the value if it is present. Otherwise it returns -1. Suppose before we call linear Search we randomly permute (i.e., reorder) the elements in A. In the following problem, we will find the expected asymptotic runtime of linear Search. (1) What is the best case asymptotic runtime of linear Search on an array of n elements? What index must val be located at to elicit this runtime? (2) What is the worst case asymptotic runtime of linear Search on an array of n elements? What index must val be located at to elicit this runtime? (3) Let X_j 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 linear Search for that permutation and 0 otherwise. What is the expected value of X_j? (4) 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 linear Search for that permutation. Define X using n copies of the random variable defined in the previous step. (5) Compute the expected value of X for using the linearity of expectation. Given this, what is the expected asymptotic runtime of linear Search

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

\(2 x+5\) when \(x=3\) Evaluate and simplify the expression.

Answered: 1 week ago

Question

=+7. What is progressive discipline?

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago