Question 1
15 marks
1
A programmer is designing a program that will store data.
The programmer is deciding whether to store the data in a stack or a queue.
The pseudocode function, enqueue, inserts an item into a queue.
01 function enqueue(item)
02 if tailPointer >= queue.length then
03 return false
04 else
05 queue[tailPointer] = item
06 tailPointer = tailPointer + 1
07 return true
08 endif
09 endfunction
1(i) 1 mark
Give the name of the parameter in the function enqueue.
Mark scheme 1(i)
Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.
item
Guidance
Allow queue can be circular or linear, stack can only be linear
Examiner’s Comments
The vast majority of candidates identified that item was the paramete
1(ii) 1 mark
Give the name of one global variable that is used in the function enqueue.
Mark scheme 1(ii)
Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.
tailPointer
Guidance
Allow queue
Examiner’s Comments
Many candidates identified that tailPointer was an example of a global variable in the code.
1(iii) 4 marks
Describe one benefit and one drawback of using global variables instead of parameter passing in a subroutine.
Benefit
Drawback
Mark scheme 1(iii)
Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.
1 mark for benefit and 1 mark for expansion:
e.g.
-
Simpler to program ...
-
... because values do not need to be passed/renamed/moved between different subroutines
-
Do not need to worry about returning values / do not need to decide between byval/byref ...
-
... all parts of the program can access the (same) value (in the same way)
1 mark for drawback and 1 mark for expansion:
-
Uses more memory ...
-
... because the memory space is declared when the program starts and remains in use throughout
-
Makes testing / debugging more difficult ...
-
.... as it’s difficult to test an individual block of code
-
Reduces data accuracy / integrity ...
-
.... changing a global variable may have an impact on another module
Guidance
2 marks max for benefit
2 marks max for drawback
Examiner’s Comments
The majority of candidates struggled to describe the implications of using global variables, and this highlighted a lack of appreciation of parameter passing and variable scope. At AS Level candidates should become more adept at using parameters and develop an understanding of why this is beneficial – both in theoretical terms and
within their personal programming practice. There were few responses that were able to give complete descriptions.
1(iv) 3 marks
The function enqueue can be called by the main program.
Explain why the function enqueue returns true or false values, and how this can be used by the main program that calls the function.
Mark scheme 1(iv)
Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.
1 mark per bullet to max 3
-
False is returned if the queue is full ...
-
... the main will not attempt to add another item
-
True is returned if the item is successfully added ...
-
... so the main program can try to add another item
Guidance
Examiner’s Comments
Some candidates thought that if enqueue() returned True it meant that there would be space to add additional values. This was not the case; it meant that the item had been enqueued successfully, but it could have been the last item that then filled the queue to capacity.
Sometimes candidates did explain the reasons why True and False would be returned but were then unable to go on to say how they could be used. Good responses were seen such as ‘the main program can give an error message if the operation didn’t work if the queue was full’.
Exemplar 1
[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]
A candidate's handwritten answer:
The request() function returns "False" if the array variable is null (i.e. the null pointer is greater than equal to the pre-defined length) and the reference attribute has not been added. The function returns "True" if the query is not null and indicates the item has been added. Their other results can be used to select whether the item pointed to request() has been successfully added by assigning him to a variable : successful = request("x") for example.
This response showed clear understanding of the need to store the result returned by dequeue() to be used in the conditional loop test.
1(v) 3 marks
The pseudocode function, dequeue, removes and returns the first item in the queue. If the queue is empty, the function returns the string "EMPTY".
01 function dequeue(data)
02 if headPointer != tailPointer then
03 return "EMPTY"
04 elseif
05 value = queue[headPointer]
06 return value
07 headPointer = headPointer + 1
08 endif
09 endfunction
The function dequeue has several errors.
Identify the line number of any three errors and state the correction required.
Error 1 Line Number
Error 1 Correction
Error 2 Line Number
Error 2 Correction
Error 3 Line Number
Error 3 Correction
Mark scheme 1(v)
Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.
1 mark for error and correction to max 3
-
Line 01 There is no need to pass in a parameter
-
Line 02 has != instead of == Line 04 has elseif and no condition / replace with else
-
Line 06 should be
headpointer=headpointer+ 1 / Swap lines 06 and 07 -
Line 07 should be
return value
Guidance
Do not award marks for the line number. The error must be related to the line number stated.
Examiner’s Comments
Many candidates identified at least one logical error, but few were able to identify three errors. The most common error identified was the error in line 02.
1(vi) 3 marks
The programmer has corrected all of the errors in the function dequeue.
The main program repeatedly calls the function dequeue until all of the elements in the queue have been output.
Write the main program using pseudocode or program code.
Mark scheme 1(vi)
Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.
1 mark per bullet to max 3
-
Use of loop to call dequeue()....
-
...to output the return value...
-
...until “EMPTY” is returned
e.g.
elementsLeft = true
while elementsLeft == true
value = dequeue()
if not(value = “EMPTY”) then
print(value)
else
elementsLeft = false
endif
endwhile
Guidance
Examiner’s Comments
Some candidates mistakenly gave a definition for the dequeue() function instead of answering the question set. Candidates need to be mindful to read the question carefully.
Some candidates used a count-controlled loop whereas a conditional loop was required. Those who made a good attempt at a response often did not assign the result of dequeue() to a variable,
so could not effectively use the return value from the function as well as print the value returned.