Elements of Computational Thinking - Worksheets, Questions and Revision

14 original exam-style questions - 10 pages of questions with a full mark scheme - free printable PDF.

Download PDFJump to mark scheme (page 11)Read the revision guide
« Previous: Recursion and Advanced AlgorithmsNext: Problem Solving and Programming »
Revision Library
revisionlibrary.co.uk
A-Level · Paper 2: Algorithms and Programming

A2.1 Elements of Computational Thinking

OCR H446 · Calculators not allowed · about 150 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.
1
Nia Okafor is part of a small software team designing a new online catalogue and booking system for Bramwell Public Library. Members will be able to search the catalogue, reserve books that are currently out on loan, and receive a notification when a reserved book becomes available.
(a)Define what is meant by abstraction as a computational thinking technique.(2)
(b)Define what is meant by decomposition as a computational thinking technique.(2)
(c)Using decomposition, identify three separate sub-problems that Nia's team would need to solve in order to build the library system described above. For one of your three sub-problems, state one piece of detail that could be abstracted away (ignored) at this early design stage.(4)
(Total for Question 1 is 8 marks)
2
Devon is a software engineer working on an air quality sensor for Marlow Council. Each reading is stored as an 8-bit binary value. To save storage space, repeated identical readings are compressed by recording a value once together with a count of how many times it repeats, an application of pattern recognition in computational thinking.
(a)Convert the denary value 173 to an 8-bit binary number. Show your working.(2)
(b)Convert your answer to part (a) into hexadecimal.(2)
(c)State the name of the pattern recognition technique described above, in which a repeated value is stored once together with a count of how many times it occurs, and state one benefit of using it.(2)
(d)A second sensor reading is recorded as FE in hexadecimal. State this value in binary and in denary.(2)
(Total for Question 2 is 8 marks)
3
Callum is writing the control program for a vending machine. The machine should display a prompt unless a coin has been inserted AND the selection button has been pressed. His first version of the condition, using two Boolean variables hasCoin and buttonPressed, is:
IF NOT (hasCoin AND buttonPressed) THEN
  OUTPUT "Please insert a coin and press the button"
ENDIF
(a)Complete a truth table for the expression NOT (hasCoin AND buttonPressed) for all four combinations of hasCoin and buttonPressed.(3)
(b)Show that NOT (hasCoin AND buttonPressed) is logically equivalent to (NOT hasCoin) OR (NOT buttonPressed).(3)
(c)Rewrite the IF statement above so that it uses the simplified logical expression from part (b) instead, using OCR Exam Reference Language.(3)
(Total for Question 3 is 9 marks)
4
Mr Whitfield stores the exam scores for five students in an array called scores, with indices 0 to 4. The initial contents are scores = [67, 45, 89, 23, 71]. He sorts them using the following algorithm:
FOR i <- 0 TO 3
  FOR j <- 0 TO 3 - i
    IF scores[j] > scores[j + 1] THEN
      temp <- scores[j]
      scores[j] <- scores[j + 1]
      scores[j + 1] <- temp
    ENDIF
  NEXT j
NEXT i
(a)Complete a trace table showing the contents of the array scores after each comparison (each value of j) during the first pass of the outer loop, i.e. when i = 0.(4)
(b)State how many comparisons of the IF condition take place during this first pass (i = 0), for this 5 item list.(2)
(c)State an expression, in terms of n, for the total number of comparisons of the IF condition made in the worst case when sorting a list of n items using this algorithm.(2)
(d)The inner loop bound (3 - i) means that, as i increases, fewer comparisons are made in each successive pass. Explain why this is a valid optimisation of the algorithm.(2)
(Total for Question 4 is 10 marks)
5
Elodie is optimising a program that calculates Fibonacci numbers, where Fibonacci(0) = 0, Fibonacci(1) = 1, and Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2) for n ≥ 2. She notices that a simple recursive version recalculates the same values many times over, so she decides to store (cache) results as they are calculated for reuse later, an example of the 'thinking ahead' computational thinking technique.
(a)Define what is meant by memoisation, and state which computational thinking technique it is an example of.(2)
(b)The bottom-up algorithm below calculates Fibonacci(n) by filling an array called cache:
FUNCTION Fibonacci(n)
  DECLARE cache : ARRAY[0:n] OF INTEGER
  cache[0] <- 0
  cache[1] <- 1
  FOR i <- 2 TO n
    cache[i] <- cache[i - 1] + cache[i - 2]
  NEXT i
  RETURN cache[n]
ENDFUNCTION
Complete a trace table showing the value stored in cache[i] for each value of i from 2 to 6, when Fibonacci(6) is called.
(3)
(c)Rewrite Fibonacci as a recursive function, in OCR Exam Reference Language, that uses memoisation to avoid recomputing values. You should use a global array called cache, with every element initially set to -1 to show that no value has yet been calculated.(5)
(d)State one other situation in computing, other than calculating Fibonacci numbers, where caching improves performance, and explain why it helps.(2)
(Total for Question 5 is 12 marks)
6
Zainab is programming a robot to escape a small square maze on a 5 by 5 grid. Columns are numbered x = 0 to 4 (left to right) and rows are numbered y = 0 to 4 (top to bottom). The robot starts at S (0,0) and must reach the exit E (4,4). The function below searches for a path using backtracking, trying directions in the fixed order right, down, left, up:
FUNCTION FindPath(x, y)
  IF grid[x][y] = "E" THEN
    RETURN TRUE
  ENDIF
  IF NOT ValidMove(x, y) THEN
    RETURN FALSE
  ENDIF
  MarkVisited(x, y)
  IF FindPath(x + 1, y) THEN
    RETURN TRUE
  ENDIF
  IF FindPath(x, y + 1) THEN
    RETURN TRUE
  ENDIF
  IF FindPath(x - 1, y) THEN
    RETURN TRUE
  ENDIF
  IF FindPath(x, y - 1) THEN
    RETURN TRUE
  ENDIF
  RETURN FALSE
ENDFUNCTION
ValidMove(x, y) returns TRUE only if (x, y) is inside the grid, is not a wall, and has not already been visited during this search.
x (columns) y (rows) 0 1 2 3 4 0 1 2 3 4 S E = wall (#) = open path (.) S = start (0,0), E = exit (4,4)
(a)Explain what the final line, RETURN FALSE, allows the algorithm to do, and state which computational thinking technique this line is an example of.(2)
(b)Trace the algorithm starting at S(0,0). State the sequence of coordinates visited up to and including the point at which the first backtrack occurs, and state the coordinate to which the algorithm backtracks.(4)
(c)Continuing from the backtrack in part (b), state the full sequence of coordinates that leads the algorithm to the exit E, following the same priority order (right, down, left, up) at each step.(4)
(Total for Question 6 is 10 marks)
7
Priya drives a delivery van and must visit customers at four locations, A, B, C and D, before returning to the depot P. The table below shows the distance, in km, between each pair of locations:
P-A=4, P-B=9, P-C=7, P-D=6, A-B=5, A-C=8, A-D=3, B-C=2, B-D=10, C-D=6.
Because checking every possible route becomes impractical as the number of locations grows, Priya's route-planning app uses the nearest-neighbour heuristic: starting at the depot, always travel next to the closest location not yet visited.
Distance matrix (km) P A B C D P A B C D - 4 9 7 6 4 - 5 8 3 9 5 - 2 10 7 8 2 - 6 6 3 10 6 -
(a)State why an exact algorithm that checks every possible route becomes impractical as the number of delivery locations increases.(2)
(b)Apply the nearest-neighbour heuristic, starting and ending at the depot P, to find a route visiting A, B, C and D. State the order in which locations are visited and calculate the total distance travelled.(4)
(c)Show that the route P-A-B-C-D-P is shorter than the nearest-neighbour route found in part (b), and explain what this shows about the nearest-neighbour heuristic.(3)
(d)Give one advantage and one disadvantage of using a heuristic approach, such as nearest-neighbour, rather than an exact algorithm for this kind of real-world routing problem.(2)
(Total for Question 7 is 11 marks)
8
Kestrel Stores is a supermarket chain that analyses transaction data collected through its loyalty card scheme, searching for patterns in what customers buy in order to improve stock control and target promotions.
(a)Define what is meant by data mining.(2)
(b)Big data is often characterised using several 'V' properties. Other than Volume, identify and briefly explain two of these properties, applying each one to Kestrel Stores' transaction data.(4)
(Total for Question 8 is 6 marks)
9
Kestrel Stores (see the previous question) is considering extending its data mining to build detailed individual customer profiles that could predict sensitive health conditions, such as pregnancy or diabetes, purely from patterns in a customer's purchases, without asking the customer directly. Discuss the ethical issues raised by this proposal, and evaluate whether Kestrel Stores would be justified in using data mining in this way.
(Total for Question 9 is 6 marks)
10
Kelvin Grove Hospital models patient waiting times at its walk-in triage desk to test how changes might affect the department, without needing to trial them on real patients (performance modelling). One triage nurse (a single server) sees patients strictly in the order they arrive. Five patients arrive at times (in minutes after opening) of 0, 4, 5, 9 and 15, and require treatment (service) times of 6, 3, 5, 4 and 2 minutes respectively. The algorithm below simulates the queue:
arrival[1] <- 0
arrival[2] <- 4
arrival[3] <- 5
arrival[4] <- 9
arrival[5] <- 15
service[1] <- 6
service[2] <- 3
service[3] <- 5
service[4] <- 4
service[5] <- 2
finishPrev <- 0
totalWait <- 0
FOR i <- 1 TO 5
  IF arrival[i] > finishPrev THEN
    start[i] <- arrival[i]
  ELSE
    start[i] <- finishPrev
  ENDIF
  finish[i] <- start[i] + service[i]
  wait[i] <- start[i] - arrival[i]
  finishPrev <- finish[i]
  totalWait <- totalWait + wait[i]
NEXT i
(a)State what is meant by performance modelling as a computational thinking technique, and give one reason it is used instead of trialling changes on the real system.(2)
(b)Complete a trace table showing the values of start[i], finish[i] and wait[i] for i = 1 to 5, and the final value of totalWait, when the algorithm above is executed.(6)
(c)Calculate the mean waiting time per patient across this simulation, giving your answer to 1 decimal place.(3)
(d)Explain why simulating a much larger number of patients would improve the reliability of this performance model's predictions, and suggest one limitation that would remain even with a much larger simulation.(3)
(Total for Question 10 is 14 marks)
11
A CPU in a laptop used by Kwame's college uses a 4-stage instruction pipeline, Fetch, Decode, Execute and Write-back, to increase throughput by overlapping the execution of successive instructions. Each stage takes exactly one clock cycle, and one clock cycle lasts 2 ns. The processor must execute a program made up of 10 instructions.
(a)State two reasons why pipelining increases the throughput of a processor compared with executing each instruction's stages sequentially, with no overlap between instructions.(2)
(b)Calculate the total time, in ns, to execute all 10 instructions if pipelining is NOT used, i.e. each instruction completes all 4 stages before the next instruction begins.(3)
(c)Calculate the total time, in ns, to execute all 10 instructions using the 4-stage pipeline, assuming no stalls or hazards occur.(3)
(d)Calculate the speed-up factor achieved by using the pipeline for this program, giving your answer correct to 2 decimal places.(2)
(e)State what is meant by a pipeline hazard, and give one example of a situation that could cause the pipeline to stall.(2)
(Total for Question 11 is 12 marks)
12
Freya analyses monthly visitor numbers for a council website: Jan 1200, Feb 1350, Mar 3100, Apr 1400, May 1450, Jun 1500.
(a)State two reasons why visualising this data (e.g. as a line graph) can make patterns easier to identify than examining the raw numbers alone.(2)
(b)Identify, from the data given, the month that is an outlier compared with the general trend, and suggest a possible real-world cause.(2)
(c)State one type of visualisation, other than a line graph, that would be more appropriate for showing the proportion of the total annual visitors contributed by each month, and justify your choice.(2)
(d)Explain one limitation of relying on visualisation alone, rather than combining it with other computational thinking techniques such as data mining, when analysing very large datasets.(2)
(Total for Question 12 is 8 marks)
13
Jayden is developing a funds transfer feature for Nexbank's mobile app. Two processes, ProcessA and ProcessB, may run at the same time and both need exclusive access to a shared balanceRecord and a shared transactionLog to complete a transfer:
ProcessA:
LOCK balanceRecord
LOCK transactionLog
// transfer funds
UNLOCK transactionLog
UNLOCK balanceRecord
ProcessB:
LOCK transactionLog
LOCK balanceRecord
// transfer funds
UNLOCK balanceRecord
UNLOCK transactionLog
(a)Define what is meant by 'thinking concurrently' as a computational thinking technique.(2)
(b)Explain, with reference to the pseudocode above, how a deadlock could occur if ProcessA and ProcessB run at the same time.(3)
(c)Suggest a change to the order of the LOCK statements in ProcessB that would prevent this deadlock, and explain why your change works.(3)
(d)State one difference between a deadlock and a race condition.(2)
(Total for Question 13 is 10 marks)
14
TransitLink is a logistics company whose route-planning software must decide the delivery order for up to 200 stops per van each day. Discuss how a combination of computational thinking techniques, decomposition, abstraction, heuristics and performance modelling, could be applied by TransitLink's developers to produce a workable, efficient solution, and evaluate the trade-offs involved in using approximate (heuristic) methods rather than exact algorithms for a problem of this scale.
(Total for Question 14 is 9 marks)
Mark scheme · A2.1 Elements of Computational Thinking

Question 1

Question 2

Question 3

Question 4

Question 5

Question 6

Question 7

Question 8

Question 9

Question 10

Question 11

Question 12

Question 13

Question 14