


























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
OCR A Level Computer Science H446/02 Algorithms and programming UPDATED ACTUAL Questions and Marking Scheme
Typology: Exams
1 / 66
This page cannot be seen from the preview
Don't miss anything!



























































Time allowed: 2 hours 30 minutes You can use:
Oxford Cambridge and RSA INSTRUCTIONS
© OCR 2025 [601/4911/5] DC (PQ/CGW) 337417/ OCR is an exempt Charity Turn over
(^1) (^3) (^5) (^2) (^4) (^4) (^1) (^7) (^8) (^5) (^) *
© OCR 2025 Section A 1 Data in a computer program needs to be sorted. (a) (i) Describe the steps a bubble sort will take to sort items into ascending order. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... ..........................................................................................................................................................
. ................................................................................................................................................. [5] (ii) 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 complete six passes. However, Felix’s version will only need to complete two passes. Explain how Felix may have made his version more efficient than Darcie’s version. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... . ................................................................................................................................................. [2]
© OCR 2025^ Turn^ over (b) 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 .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... ..........................................................................................................................................................
. ................................................................................................................................................. [5]
© OCR 2025^ Turn^ over (ii) Identify the type of iteration used in the function partition().
. ................................................................................................................................................. [1] (iii) Describe the role of the function partition() in the quick sort algorithm. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... . ................................................................................................................................................. [3] (iv) 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 amended line of code. Line number ................... Amended line of code ....................................................................................................................... .......................................................................................................................................................... [2] (v) The quick sort is an example of a divide-and-conquer algorithm. Describe what divide-and-conquer means. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... . ................................................................................................................................................. [2]
© OCR 2025 2* A shopping website requires customers to create a username and password. (a) 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 order by username. The file can be searched using a linear search or a binary search. The big-O complexities for a linear search and a binary search are given in the table: Search algorithm Worst-case time Average-case time Worst-case space Linear O(n) O(n) O(1) Binary O(log n) O(log n) O(1) Compare the use of a linear search and a binary search in this scenario. You should include the following in your answer:
© OCR 2025
© OCR 2025^ Turn^ over 3 A program is designed to use a stack data structure. The current contents of part of the stack and its current pointer value are shown: 5 4 3 2 1 0 pointer = 2 (a) Show the contents of the stack and its pointer value after the data items "t" and "s" are inserted in the order given. 5 4 3 2 1 0 pointer = ................... [2]
"n" "k"
© OCR 2025^ Turn^ over (c) A pointer value of - 1 indicates that the stack is empty. The function pop() returns the next element in the stack. If the stack is empty it returns "false". The function updates the pointer value when appropriate. Write the function pop() using pseudocode or program code. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... ..........................................................................................................................................................
. ................................................................................................................................................. [6] (d) A program is designed to reverse a set of data using the stack. The main program takes 10 characters separately as input from the user and uses the function push() to insert these into the stack. Once all 10 characters have been inserted into the stack, the program then uses the function pop() to output all 10 characters from the stack. Write the main program to achieve this using pseudocode or program code. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... . ................................................................................................................................................. [5]
© OCR 2025 4* A processor is being designed to use pipelining and will need to be able to process millions of instructions. For each instruction the following stages will be performed: A the instruction will be fetched from memory B the instruction will be decoded C the instruction will be executed The first four instructions to be processed will be instructions 1, 2, 3 and 4. The design allocates 1 - time interval for each of the three stages A, B, C. Discuss the use of pipelining by this processor. You should include the following in your answer:
© OCR 2025
5 A program is being written that allows users to travel between different planets in a virtual world. Spaceships are used to travel between planets and there are only set routes that they use. Fig. 5 shows a directed graph. The nodes represent the different planets and the edges represent the routes the spaceships can travel. The arrows on the edges show which way the spaceships can travel. For example, a spaceship can travel from planet B to planet C, but not from planet C to planet B. The value on each edge is the cost in space dollars to travel on that route. Fig. 5 (a) Explain why this graph is a visualisation of the problem. .......................................................................................................................................................... .......................................................................................................................................................... ..........................................................................................................................................................
. ................................................................................................................................................. [2]
© OCR 2025^ Turn^ over (b) 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 shown in Fig. 5 to find the shortest path from start planet A to the end planet H. You must state the nodes on the final path and the distance of this path. Show your working. You may use the table to give your answer. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... Node Distance travelled Previous node Final path: ........................................................................................................................................ Distance: .......................................................................................................................................... [7]
© OCR 2025^ Turn^ over (b) The program the student is developing includes both global and local variables. (i) Explain the difference between a global variable and a local variable. .......................................................................................................................................................... .......................................................................................................................................................... ..........................................................................................................................................................
. ................................................................................................................................................. [2] (ii) Describe one drawback of using global variables in a program. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... . ................................................................................................................................................. [2] (iii) Describe one drawback of using local variables in a program. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... . ................................................................................................................................................. [2] (c) A variable can be passed as a parameter into a function by value or by reference. Describe what parameter passing by value means. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... . ................................................................................................................................................. [2]
© OCR 2025 (d) An algorithm is needed to count how many times each of the numbers from 1 to 9 appear in an array called myArray. Another array called checked is used to store each number found in myArray and the number of times it appears. For example, the contents of myArray are: 7 3 6 7 5 3 2 3 6 Based on these contents in myArray, the contents in checked would be: 7 2 3 3 6 2 5 1 2 1