Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[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 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
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