Mystery 2005

This is an algorithm trace task. No implementation is required.

Read the following algorithm for the recursive function called Mystery. X( ) is a one-dimensional array.

mystery2005.jpg - 12/2015

(a) Write down the exact output when the function is called with [2 Marks]

  1. Output  ‘The answer is: ’, Mystery(A( ), 5) if A(1) = 6, A(2) = 10, A(3) = 6, A(4) = 18, A(5) = 15. 
  2. Output ‘The answer is: ’, Mystery(A( ), 5) if A(1)=16, A(2)=18,A(3)=12, A(4)=15, A(5)=18. 

(b) The function is called with Mystery(A( ), 3) where A(1) = 28, A(2) = 20 and A(3) = 28.

Produce a diagram showing each step of the algorithm and the function calls. [9 Marks]

(c) Describe the purpose of the algorithm. [3]

(d) Write an iterative algorithm that does the same task as the recursive algorithm. [7]

This task was worth 21 Marks.  It was an algorithm trace task. No implementation is required that originally appeared in OCR 2507 Task 4 Jun 2005.  All rights and copyright to OCR.  Please refer to the OCR Copyright Statement for further information.

Comments 0

Write a Reply or Comment

We will not publish your email.*


*