1. Engineering
  2. Computer Science
  3. 5 3 points the following routine takes as input a...

Question: 5 3 points the following routine takes as input a...

Question details

5. (3 points) The following routine takes as input a list of n numbers, and returns the first value of i for which L[i ] < L[1-1], or n if no such number exists. int firstDecrease(int *L, int n) { for (int i-2, i <= n && L[i] >= L[i-1]; i++) { } return i 5a) What is the big-O runtime for the routine, measured as a function of its return value i? 5b) If the numbers are chosen independently at random, then the probability that firstDecrease(L) returns i is (i I/it, except for the special case of i -n+ for which the probability is I/m! Use this fact to write an expression for the expected value returned by the algorithm. (Your answer can be expressed as a sum, it does not have to be solved in closed form. Do not use O-notation.)

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution