Menu

Question 1 1 Marks Following Procedure Input Array 1n N 2 Arbitrary Integers Pseudo Code R Q43880155

Question 1. (1 marks) The following procedure has an input array A[1..n] with n > 2 arbitrary integers. In the pseudo-code,

Question 1. (1 marks) The following procedure has an input array A[1..n] with n > 2 arbitrary integers. In the pseudo-code, “return” means immediately erit the procedure and then halt. Note that the indices of array A starts at 1. NOTHING(A) 1 n = A. size 2 for i = 1 ton // i=1,2,…, n (including n) 3 for j = 1 ton // j = 1,2,…,n (including n) 4. if A[n – j +1] + j then return 5 if (A[i] + n-i) or (A[1] + A[2] = 2n-3) then return 6 return Assume that each assignment, comparison and arithmetic operation takes constant time. Let T(n) be the worst-case time complexity of calling NOTHING(A) on an array A of size n > 2. Give a tight asymptotic bound for T(n), that is give a function f(n) such that T(n) is (f(n)). Justify your answer by explaining why it is (f(n)), and why it is 2(f(n)). Any answer without a sound and clear justification may receive no credit. Show transcribed image text Question 1. (1 marks) The following procedure has an input array A[1..n] with n > 2 arbitrary integers. In the pseudo-code, “return” means immediately erit the procedure and then halt. Note that the indices of array A starts at 1. NOTHING(A) 1 n = A. size 2 for i = 1 ton // i=1,2,…, n (including n) 3 for j = 1 ton // j = 1,2,…,n (including n) 4. if A[n – j +1] + j then return 5 if (A[i] + n-i) or (A[1] + A[2] = 2n-3) then return 6 return Assume that each assignment, comparison and arithmetic operation takes constant time. Let T(n) be the worst-case time complexity of calling NOTHING(A) on an array A of size n > 2. Give a tight asymptotic bound for T(n), that is give a function f(n) such that T(n) is (f(n)). Justify your answer by explaining why it is (f(n)), and why it is 2(f(n)). Any answer without a sound and clear justification may receive no credit.

Expert Answer


Answer to Question 1. (1 marks) The following procedure has an input array A[1..n] with n > 2 arbitrary integers. In the pseudo-co…

OR