Question 4 2014 · May-June · Paper 22 · 17 marks
Reveal official mark-scheme answer
Official answer for Question 4
Question 1
Show text version of question
Question 4
Look at this pseudocode function:
FUNCTION Y(s : STRING) RETURNS STRING DECLARE x : INTEGER x LENGTH(s) IF x = 1 THEN RETURN s ELSE RETURN Y(RIGHT(s, x - 1)) + LEFT(s, 1) // RIGHT above returns rightmost x - 1 characters of string s // LEFT above returns leftmost character of string s ENDIF ENDFUNCTION
(i)
How can you tell that function Y is recursive?
(ii)
Dry-run the function when it is called with the string ‘BYTE’ as parameter.
Call s x RIGHT (s, x - 1) LEFT (s, 1) Function call Return value Number
1 Y ('BYTE') 'BYTE'
(iii)
What does function Y do?
(iv)
List two features of the pseudocode above that make it easier to understand.
Question 1
Question 2
Question 11
(v)
List one feature of the pseudocode above that makes it more difficult to understand.
Question 1
(vi)
Re-write the pseudocode function as an iterative function.
FUNCTION Y(s : STRING) RETURNS STRING
ENDFUNCTION
Question 12
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.
Why this question appears here
98% assigned-topic match · Computational thinking and problem-solving › Recursion
Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.
Permanent source page: Educate A Change · From 9691_s14_qp_22.pdf
