Question: 3. (a) Explain what is meant by a specification and an implementation [10 marks] (b) Write an algorithm which inputs an array A[1...n and returns

3. (a) Explain what is meant by a specification and an implementation [10 marks] (b) Write an algorithm which inputs an array A[1...n and returns the same array with the elements in reverse order. Examples of use include: output input: A 15,8,1, 7, 2,9 (4,3,2,1] 9,2, 7, 1,8,5) (1,2,3,4 Your algorithm should work in-situ (i.e., an in-place algorithm that does not use any other array). (15 marks] (c) Rewrite the following algorithm so that the variable FOUND is not used (i.e., the value of the variable FOUND should be computed from other variables in the algorithm). Input: Array Ai...n), item M Output: true, if M in A, false otherwise FOUND + false PTR+1 while not FOUND and PTR
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
