A Level Computer Science
H446/02 Algorithms and programming
JUNE 2022
Time allowed: 2 hours 30 min
INSTRUCTIONS
• Use black ink. You can use an HB pencil, but only for grap
...
A Level Computer Science
H446/02 Algorithms and programming
JUNE 2022
Time allowed: 2 hours 30 min
INSTRUCTIONS
• Use black ink. You can use an HB pencil, but only for graphs and diagrams.
• Write your answer to each question in the space provided. If you need extra space use the lined pages at the end of this booklet. The question numbers must be clearly shown.
• Answer all the questions.
INFORMATION
• The total mark for this paper is 140.
• The marks for each question are shown in brackets [ ].
• Quality of extended response will be assessed in questions marked with an asterisk (*).
• This document has 36 pages.
ADVICE
• Read each question carefully before you start your answer.
BLANK PAGE
PLEASE DO NOT WRITE ON THIS PAGE
Section A
Answer all the questions.
1 A computer program stores data in an array named words.
(a) The data in the array needs to be searched for a value that the user inputs.
(i) One example of a searching algorithm is a binary search.
Identify the precondition for a binary search.
...........................................................................................................................................
...................................................................................................................................... [1]
(ii) A second example of a searching algorithm is a linear search.
Describe how a linear search works.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
(b) The array words is defined as a global variable and contains these values:
"house" "boat" "car" "telephone" "garden" "spice" "elephant"
The pseudocode function useWords() here uses the global array words. The number of words in the array words is passed as a parameter.
function useWords(numberOfWords : byVal) contents = ""
for count = 0 to numberOfWords - 1 contents = contents + words[count] + " "
next count return contents
endfunction
(i) Identify two variables in the function useWords().
1 ........................................................................................................................................
2 ........................................................................................................................................
[2]
(ii) numberOfWords is a parameter passed by value.
Describe the difference between passing a parameter by value and by reference.
................................................................
[Show More]