Question: please write out the general formula */ Algorithm 1: Mystery(A, k) Input: A is an array of integers, indexed 0 through n-1. k is a

please write out the general formula
*/ Algorithm 1: Mystery(A, k) Input: A is an array of integers, indexed 0 through n-1. k is a positive integer. in = length(A); 2 S = zeros(n - k)/* length n-k array of Os 3 for j=0 to k-1 do 4 L S[0] = S[0] + A[j]; 5 for i = 1 to n - k-1 do 6 L S[i] = S[i 1] Ai 1] + A[i+k 1); 7 return S; 1. Explain in English what Mystery is computing in terms of A, i.e. explain how the value contained in S[i] relate to the values stored in A for every i = 0,1,...n-k-1. 2. Compute the total number of additions and subtractions in lines 4 and 6 that are performed in this algorithm. Give an exact formula as a function of n and k. Explain your computation in a few words. 3. Formally prove the relationship between S[i] and A that you stated. (Hint: State a clear loop invariant for lines 5-6, and explain why it holds for each S[i].)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
