ocr-h446-2-3-mark-scheme
ocr-h446-2-3-mark-scheme
2.3 ALGORITHMS
www.learn-computerscience.com
EXAM QUESTIONS
QUESTION 1
The array queue shown below is set up to hold a small queue. Assume that there is sufficient
storage to hold all necessary additions to the queue.
Queue
The table below shows variables that are used to maintain the queue:
Variable Type Purpose
pointer to the front element of
front integer
the queue
pointer to the rear element of
rear integer
the queue
indicates whether the queue is
queue_full Boolean
full
the maximum size of the
max integer
queue
• Item (1).
1 For 1 mark.
Describe the logical decision that is made.
• The queue is checked to determine if it is full (1), if it is, then stop (1) Up to 2 marks for valid description that
otherwise continue (1). 2 demonstrates application of knowledge and
understanding to given context.
This algorithm contains a logic mistake. Explain what the mistake is.
2 For 2 marks.
rear = rear − 1
queue[rear] = item
QUESTION 2
A car has a feature in its engine management system that is intended to save fuel and
emissions produced when the car is waiting at traffic lights or in a traffic jam. The default
option is that the gears are disengaged, and the car is not moving, the engine is switched
off. There is a display on the dashboard that indicates when the engine has been switched
off in this way. However, sometimes it is necessary to keep the engine running when the
car is stationary, in order to provide electric power to charge the battery, run the heater,
run the air conditioning system or keep the lights on. This, in turn, is affected by the external
and internal temperatures, the settings chosen by the driver and the intensity of light
outside.
Write an algorithm that would produce the results described for this engine management
system feature.
• Use of endless loop while ignition is turned on (1).
• If external temp < target then override (1).
• If external light < target then override (1).
• If internal temperature < set temperature and heater on then override Up to 8 marks – 1 mark for each correct step in
(1). process.
• If internal temperature > set temperature and air conditioning on then
8
override (1). Various approaches could be correctly used. Allow
• If battery output < target then override (1). credit for evidence of each step as given, however
• If wheels not moving and gears not engaged and not override then expressed.
stop engine (1).
• If override and engine not running then start engine (1).
QUESTION 3
Consider the following algorithm in Fig.2, expressed in pseudocode, as function S:
• To locate an item (1) in a list (1). The list is in some order (1).
2 Up to 2 marks for a valid description.
QUESTION 4
It is possible to use XOR together with a key to encrypt a plain text message. For example,
to encrypt the bit pattern 111100001111 using the number 5 as a key, the key is repeated
as often as necessary to match the length of the message. An XOR operation is performed
to generate the encoded message.
111100001111 <- Message to be encrypted
101101101101 <- Key: repeated as necessary
010001100010 <- Encrypted message
Write an algorithm to accept a text message and a key that would use the method above to
generate an encoded message. Annotate your pseudocode with comments to show how it
solves the problem.
The game is played by rolling two 6-sided dice and moving that number of spaces. Both
players start on the START space. If a player lands on a space occupied by the other player,
they move to the next available space. The board is to be stored as a 2-dimensional array.
The board shown in Fig 2.1 is a visualisation of the problem. Explain what visualisation
means in this example.
2 marks, 1 for defining visualisation, 1 for application to the 2-d array and gridd
Each time a player moves, a series of obstacles are to be added to the board. On their turn,
each player rolls two dice. The smaller number from the two dice is taken, and that many
obstacles will appear on the board in random locations. For example, if a 3 and 6 are rolled,
then 3 obstacles will appear. A recursive function is written in pseudocode to perform this
task.
The code new obstacle() generates an instance of the object obstacle. Explain the
purpose of the code in line 01 in the algorithm.
• 08 (1)
1
The recursive function could have been written using iteration. Describe the benefits and
drawbacks of using recursion instead of iteration.
max 3 marks for benefit, max 3 for drawback, max 4 marks overall
Benefit
Drawback 4
• Can run out of stack space / memory (1) (due to too many calls (1))
causing it to crash (1) This can be avoided with tail recursion (1)
• More difficult to trace / follow (1) as each frame on the stack has its
own set of variables (1)
• Requires more memory than the equivalent iterative algorithm.
• Usually slower than iterative methods (1) due to maintainence of the
stack (1)
e.g.
3
The programmer has been told the recursive function has the Big O notation of O(n). State
the purpose of Big O notation.
1 from
Explain what the Big O notation O(n) means for this recursive function.
• As the dice number increases, the time the function takes to run
increases proportionally / linearly (1) 1
QUESTION 6
A 1-dimensional array stores a set of numbered cards from 0 to 7. An example of this data
is shown in Fig 4.1.
The programmer wants to search for a specific card in the array. State whether a binary
search or a linear search would be the most appropriate method to search for a specific
card and justify your answer.
A programmer is writing a computer program to sort the cards into the correct order (0 to
7). Show how an insertion sort would sort the array in Fig 4.1 into the correct order. Draw
the array after each move.
• 02174356
01274356 (1)
• 01247356 3 Allow follow through if one move is incorrect
01234756 (1)
• 01234576
• 01234567 (1)
Describe how a quick sort algorithm works with the data in Fig 4.2.
OR
Example of alternative quicksort method
marks for:
AO3: Evaluation
Mark Band 1 – Low Level
Candidates will need to evaluate the benefits and
(1–3 marks)
drawbacks of each sorting algorithm
The candidate demonstrates a basic knowledge of merge and bubble sorts with
e.g.
limited understanding shown; the material is basic and contains some
inaccuracies. The candidates makes a limited attempt to apply acquired
• Merge is fast on large data sets
knowledge and understanding to the context provided.
• Bubble is intuitive (easier to program)
The candidate provides a limited discussion which is narrow in focus.
Judgements if made are weak and unsubstantiated.
• Both are fast (or even) on smaller data
sets
The information is basic and comunicated in an unstructured way. The
information is supported by limited evidence and the relationship to the evidence
• Bubble's average speed is worse than
merge
may not be clear.
• Bubble will be easier to write for such a
small data set
0 marks
No attempt to answer the question or response is not worthy of credit.
• Accept argument for either way as long
as justified