Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Suppose before we call linearSearch we randomly permute (i.e., reorder) the elements in A. In the following problem, we will find the expected asymptotic runtime
Suppose before we call linearSearch we randomly permute (i.e., reorder) the elements in A. In the following problem, we will find the expected asymptotic runtime of linearSearch. 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? 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? For the sake of simplicity, assume val is in A. 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 linearSearch for that permutation and 0 otherwise. What is the expected value of X_j? 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. Define X using n copies of the random variable defined in the previous step. Compute the expected value of X for using the linearity of expectation. Given this, what is the expected asymptotic runtime of linearSearch
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started