































































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
2025 OCR A Level Computer Science H446/02 Algorithms and programming Verified Question paper with Marking Scheme Attached
Typology: Exams
1 / 71
This page cannot be seen from the preview
Don't miss anything!
































































Oxford Cambridge and RSA
Time allowed: 2 hours 30 minutes You can use: • a ruler (cm/mm)
Please write clearly in black ink. Do not write in the barcodes. Centre number Candidate number
First name(s) Last name
INSTRUCTIONS
© OCR 2025 [601/4911/5] DC (PQ/CGW) 337417/5 OCR is an exempt Charity Turn over
© OCR 2025
(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
(c) A third type of sorting algorithm is a quick sort.
The following quick sort algorithm is made up of two functions called partition()and quickSort(). The algorithm will sort an integer array into ascending numerical order. 01 function partition(array, low, high) 02 pivot = array[high] 3 index = low - 1 4 for count = low to high- 5 if array[count] < pivot then 06 index = index + 1 07 temp = array[index] 08 array[index] = array[count] 09 array[count] = temp 10 endif 11 next count 12 temp = array[index + 1] 13 array[index + 1] = array[high] 14 array[high] = temp 15 return index + 1 16 endfunction 17 18 function quickSort(array, low, high) 19 if low < high then 20 partitionIndex = partition(array, low, high) 21 quickSort(array, low, partitionIndex - 1) 22 quickSort(array, partitionIndex + 1, high) 23 endif 24 endfunction (i) Identify which of the two functions is recursive and give all of the line numbers where recursive calls are made.
© 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 Turn over
(b) The website collects data from customers’ activities once they log on. For example, the items they view and purchase. The company that owns the website would like to use data mining toimprove their website and customer experience.
(i) Describe what data mining means. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .................................................................................................................................................. [3] (ii) Explain how the company can make use of data mining to improve their website and customer experience. .......................................................................................................................................................... ..........................................................................................................................................................
© OCR 2025 Turn over
© 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 "I" 1 "n" 0 "k" pointer = 2
(a) Show the contents of the stack and its pointer value after the data items "t" and "s" are inserted inthe order given.
5 4 3 2 1 0
pointer = ................... [2]
© OCR 2025
(b) The stack is stored using a 0-based 1-dimensional array called theStack with 20 elements. The function push() stores its parameter into the next space in the stack if it is not full. The function returns true if it is successfully stored and returns false if the stack is full. Complete the function push() using pseudocode or program code. function push(data) if pointer == ................................. then return false else pointer = ..................................................................... theStack[pointer] = ..................................................................... ..................................................................... endif endfunction [4]
© OCR 2025 Turn over
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 designallocates 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 Turn over
© 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: ..........................................................................................................................................
© OCR 2025 Turn over