Question: [20 points] The following program determines the maximum value in an unordered array A[1n] of distinct elements: 1. max= 2. for i=1 to n do

 [20 points] The following program determines the maximum value in an

[20 points] The following program determines the maximum value in an unordered array A[1n] of distinct elements: 1. max= 2. for i=1 to n do 3. compare A[i] to max 4. if A[i]>max then 5. max=A[i] (a) If a number x is randomly chosen from a set of n distinct numbers, what is the probability that x is the largest in that set? (b) When line 5 of the program is executed, what is the relationship between A[i] and A[j] for 1ji ? (c) For each i in the range 1in, what is the probability that line 5 is executed? (d) Let s1,s2,,sn be n random variables, where si represents the number of times ( 0 or 1) that line 5 is executed during the i-th iteration of the for-loop. What is E[si] ? (e) Let s=s1+s2++sn be the total number of times that line 5 is executed during some run of the program. Prove that E[s]=(logn)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!