Algorithms: OCR A‑Level Computer Science questions
Every OCR A-Level Computer Science exam question on 2.3.1 Algorithms, 2021–2025, with its mark scheme and examiner’s report.
Find questions593
Calculations
Q1(a)(i)
The whole paper ↗![June 2025 Paper 2, question 1(a)(i): Describe the steps a bubble sort will take to sort items into ascending order. [5]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun25-01-ai-qp.webp)
Q1(a)(ii)
The whole paper ↗
Q1(b)
The whole paper ↗
Q1(c)(iii)
The whole paper ↗![June 2025 Paper 2, question 1(c)(iii): Describe the role of the function partition() in the quick sort algorithm. [3]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun25-01-ciii-qp.webp)
Q1(c)(iv)
The whole paper ↗
Q2(a)
The whole paper ↗
Q5(b)
The whole paper ↗
Q5(c)
The whole paper ↗![June 2025 Paper 2, question 5(c): The A* algorithm can also be used to find the shortest path in a graph. Describe how an A* algorithm uses heuristics to be an efficient algorithm. [2]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun25-05-c-qp.webp)
Q7(c)
The whole paper ↗
![June 2025 AS Paper 2, question 3: A student has written this algorithm in pseudocode: for x = 1 to 4 item = data[x] y = x - 1 while (y >= 0) and (item < data[y]) data[y + 1] = data[y] y = y - 1](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h04602-jun25-03-qp.webp)
Q5(d)(i)
The whole paper ↗
Q5(d)(ii)
The whole paper ↗![June 2025 AS Paper 2, question 5(d)(ii): One alternative search algorithm is a binary search. Describe the steps in a binary search. [4]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h04602-jun25-05-dii-qp.webp)
![June 2025 AS Paper 2, question 8: Show each pass of a bubble sort to sort the following string data into descending order. friend sun earth orange night time [4]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h04602-jun25-08-qp.webp)
Q3(a)
The whole paper ↗
Q6(a)
The whole paper ↗![June 2024 Paper 2, question 6(a): Explain how a linear search would search the array for the index that stores "clouds". [3]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun24-06-a-qp.webp)
Q6(b)
The whole paper ↗![June 2024 Paper 2, question 6(b): State why a binary search cannot be used in this example. [1]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun24-06-b-qp.webp)
Q6(c)
The whole paper ↗![June 2024 Paper 2, question 6(c): Show how an insertion sort will sort the given data into ascending alphabetical order. "rainbow" "moon" "sun" "stars" "clouds" "tornado" [5]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun24-06-c-qp.webp)
Q6(d)(i)
The whole paper ↗![June 2024 Paper 2, question 6(d)(i): A sorting algorithm has a best time complexity of O(n). Describe what is meant by the best time complexity O(n) for a sorting algorithm. [2]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun24-06-di-qp.webp)
Q6(d)(ii)
The whole paper ↗![June 2024 Paper 2, question 6(d)(ii): Another sorting algorithm has a worst space complexity of O(log(n)). Describe what is meant by the worst space complexity O(log(n)) for a sorting algorithm. [2]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun24-06-dii-qp.webp)
Q6(d)(iii)
The whole paper ↗![June 2024 Paper 2, question 6(d)(iii): Identify the time complexity that means the time will not change even when the number of items increases. [1]](https://pub-e8a9dbab8e2a4d089f52b2a45e0d0b50.r2.dev/bank/h44602-jun24-06-diii-qp.webp)
All 58 questions on Algorithms, as a list
- June 2025, Paper 2, Q1(a)(i) (5 marks): Describe the steps a bubble sort will take to sort items into ascending order. [5]
- June 2025, Paper 2, Q1(a)(ii) (2 marks): Darcie and Felix have both written a program that will perform a bubble sort to put these numbers into ascending order. 2 1 3 4 5 6 7 Darcie’s version will comp
- June 2025, Paper 2, Q1(b) (5 marks): A second type of sorting algorithm is an insertion sort. Describe how an insertion sort can be used to put the following data into ascending order. 20 8 15 36 [
- June 2025, Paper 2, Q1(c)(iii) (3 marks): Describe the role of the function partition() in the quick sort algorithm. [3]
- June 2025, Paper 2, Q1(c)(iv) (2 marks): The algorithm needs to be changed to sort the integer array into descending numerical order. Identify the line number that needs to be changed and write the ame
- June 2025, Paper 2, Q2(a) (9 marks): The usernames and passwords are stored securely in a file. The file contains the username and passwords for 50 million users which are sorted in alphabetical or
- June 2025, Paper 2, Q5(b) (7 marks): A user needs to travel from planet A to planet H. They need to travel the least expensive route. Show how Dijkstra’s algorithm can be used on the directed graph
- June 2025, Paper 2, Q5(c) (2 marks): The A* algorithm can also be used to find the shortest path in a graph. Describe how an A* algorithm uses heuristics to be an efficient algorithm. [2]
- June 2025, Paper 2, Q7(c) (4 marks): A different binary search tree stores the following data: 100 35 402 20 75 220 600 80 450 602 Give the output that will be produced from a depth-first (post-ord
- June 2025, AS Paper 2, Q3 (6 marks): A student has written this algorithm in pseudocode: for x = 1 to 4 item = data[x] y = x - 1 while (y >= 0) and (item < data[y]) data[y + 1] = data[y] y = y - 1
- June 2025, AS Paper 2, Q5(d)(i) (5 marks): The linear search has been written as a pseudocode function that: • takes an array called array of an unknown length as a parameter • takes a search value calle
- June 2025, AS Paper 2, Q5(d)(ii) (4 marks): One alternative search algorithm is a binary search. Describe the steps in a binary search. [4]
- June 2025, AS Paper 2, Q8 (4 marks): Show each pass of a bubble sort to sort the following string data into descending order. friend sun earth orange night time [4]
- June 2024, Paper 2, Q3(a) (7 marks): The number in bold below each node in Fig. 3 is the heuristic value. Perform an A* algorithm on the graph shown in Fig. 3 to find the shortest path from A to G.
- June 2024, Paper 2, Q6(a) (3 marks): Explain how a linear search would search the array for the index that stores "clouds". [3]
- June 2024, Paper 2, Q6(b) (1 mark): State why a binary search cannot be used in this example. [1]
- June 2024, Paper 2, Q6(c) (5 marks): Show how an insertion sort will sort the given data into ascending alphabetical order. "rainbow" "moon" "sun" "stars" "clouds" "tornado" [5]
- June 2024, Paper 2, Q6(d)(i) (2 marks): A sorting algorithm has a best time complexity of O(n). Describe what is meant by the best time complexity O(n) for a sorting algorithm. [2]
- June 2024, Paper 2, Q6(d)(ii) (2 marks): Another sorting algorithm has a worst space complexity of O(log(n)). Describe what is meant by the worst space complexity O(log(n)) for a sorting algorithm. [2]
- June 2024, Paper 2, Q6(d)(iii) (1 mark): Identify the time complexity that means the time will not change even when the number of items increases. [1]
- June 2024, Paper 2, Q6(d)(iv) (1 mark): Identify the space complexity that means the amount of memory (space) used will double each time a new item is included. [1]
- June 2024, Paper 2, Q7(b)(iii) (5 marks): Tick (3) one column in each row to identify whether each statement applies to a depth-first (post-order) tree traversal, a breadth-first tree traversal, or neit
- June 2024, AS Paper 2, Q5(a) (6 marks): The following incomplete pseudocode algorithm uses a binary search to find the integer numberToFind in the array array. It returns the index of the array or –1
- June 2024, AS Paper 2, Q5(b)(i) (5 marks): Describe how the given data will be sorted into descending numerical order using an insertion sort. You should refer to the data in this array throughout your a
- June 2024, AS Paper 2, Q5(b)(ii) (2 marks): The size of the array has now been increased to seven elements. The insertion sort algorithm needs to be tested to ensure it sorts a range of test data into des
- June 2023, Paper 2, Q1(a)(v) (4 marks): Identify the order that the nodes will be visited in a depth-first (post-order) traversal of this binary search tree. H C P A F L T [4]
- June 2023, Paper 2, Q1(a)(vi) (2 marks): Explain how backtracking is used in depth-first (post-order) traversals. [2]
- June 2023, Paper 2, Q1(b) (6 marks): A graph is another type of data structure. An example graph is shown in Fig. 1. 2 C A G 8 5 10 4 B D 12 1 2 8 F E Fig. 1 Show how Dijkstra’s algorithm can be us
- June 2023, Paper 2, Q7(a) (9 marks): A program designer needs to decide on an algorithm to use from a choice of three. The table shows the worst-case Big O complexities for each algorithm. Algorith
- June 2023, Paper 2, Q7(c)(i) (5 marks): Describe how a merge sort works. [5]
- June 2023, Paper 2, Q7(c)(ii) (2 marks): Give one benefit and one drawback of the programmer using a merge sort instead of a bubble sort. Benefit Drawback [2]
- June 2023, AS Paper 2, Q1(a) (4 marks): Show each stage of a bubble sort to sort this data into ascending numerical order: 1 5 3 9 2 7 You should clearly show and label each pass in your answer. [4]
- June 2023, AS Paper 2, Q1(b)(iii) (3 marks): State the purpose of the variable holdValue in the procedure bubbleSort. [3]
- June 2023, AS Paper 2, Q1(b)(iv) (2 marks): The procedure bubbleSort will only partially sort the array numbers into order. Describe what the programmer would need to add to the algorithm to enable it to
- June 2023, AS Paper 2, Q1(c)(i) (1 mark): The array numbers contains 356 numbers to be sorted by the bubble sort algorithm. State the maximum number of passes a bubble sort would need to complete to sor
- June 2023, AS Paper 2, Q1(c)(ii) (1 mark): State the name of one other sorting algorithm. [1]
- June 2023, AS Paper 2, Q6(a)(i) (5 marks): Describe how a linear search will search the data in the array for a number that has been input. [5]
- June 2023, AS Paper 2, Q6(a)(ii) (1 mark): State why you would use a linear search rather than a binary search. [1]
- June 2022, Paper 2, Q1(a)(i) (1 mark): One example of a searching algorithm is a binary search. Identify the precondition for a binary search. [1]
- June 2022, Paper 2, Q1(a)(ii) (4 marks): A second example of a searching algorithm is a linear search. Describe how a linear search works. [4]
- June 2022, Paper 2, Q2(d) (9 marks): A computer program is being written to store data about students. Fig. 2 shows a binary search tree that stores data about students. Each student is represented
- June 2022, Paper 2, Q3(b) (5 marks): This bubble sort algorithm is written to sort numberArray into ascending numerical order. Complete this bubble sort algorithm. arrayLength = tempValue = 0 do fl
- June 2022, Paper 2, Q3(c) (4 marks): One section of numberArray is shown here. 2 12 1 9 3 5 15 7 A second sorting algorithm that could be used to sort this data is a merge sort. Show how a merge so
- June 2022, Paper 2, Q3(d) (12 marks): A bubble sort will sort an array of 50 integer values called numberArray. (d)* Another sorting algorithm is insertion sort. The number of values stored in the a
- June 2022, Paper 2, Q5(c)(i) (6 marks): Show how Dijkstra’s algorithm can be used on the graph shown in Fig. 5 to find the shortest path from the start node A and the end node H. You should state the
- June 2022, Paper 2, Q5(c)(ii) (2 marks): Give a similarity and difference between the performance of Dijkstra’s algorithm and the performance of A* algorithm. Similarity Difference [2]
- June 2022, AS Paper 2, Q3(a) (4 marks): Trudi will use a bubble sort to put these numbers into order from smallest to largest. Show the first pass of the bubble sort. You should clearly show each comp
- June 2022, AS Paper 2, Q3(b)(iii) (2 marks): Describe the purpose of the temp variable in the procedure bubbleSort. [2]
- June 2022, AS Paper 2, Q3(b)(iv) (2 marks): Describe the purpose of the sorted variable in the procedure bubbleSort. [2]
- June 2022, AS Paper 2, Q5(a) (3 marks): When customers make an appointment they often ask for the first available booking slot. Describe how a linear search could be used for this purpose. [3]
- June 2022, AS Paper 2, Q5(b) (7 marks): A function findFirst, is used to find the first available appointment. Write the function findFirst that will find the first available appointment and return th
- November 2021, Paper 2, Q1(c)(i) (2 marks): Define the term heuristic in relation to the A* algorithm. [2]
- November 2021, Paper 2, Q1(c)(ii) (8 marks): Perform an A* algorithm on the graph shown in Fig. 1 to find the shortest path from the starting node to the end node. Show your working, the nodes visited and
- November 2021, Paper 2, Q1(d) (6 marks): A breadth-first traversal can be performed on both a tree and a graph. Show how a breadth-first traversal is performed on the following binary tree. M E S C J P
- November 2021, Paper 2, Q2(a)(i) (6 marks): Complete the algorithm by filling in the missing statements. function binarySearch(dataArray:byref, upperbound, lowerbound, ………………………………) while true middle = lo
- November 2021, Paper 2, Q2(b) (6 marks): The tables below show possible Big O complexities for the worst-case space, best-case space and average time for search algorithms. Tick the worst-case space co
- November 2021, Paper 2, Q2(c) (1 mark): Identify one situation where a linear search is more appropriate than a binary search. [1]
- November 2021, Paper 2, Q3(a) (5 marks): A one dimensional array holds data that needs to be sorted. Describe how a quicksort would sort data into ascending order. [5]
Questions, mark schemes and examiner’s reports are © OCR, from their published past papers. Plumi isn’t affiliated with any exam board. Want whole papers? Full past papers.
Rather write your answers by hand on iPad? Plumi marks them against the same mark schemes.