Download 2025 OCR AS Level Computer Science H046/02 Algorithms&problem solving QP+MS and more Exams Computer Science in PDF only on Docsity!
2025 OCR AS Level Computer Science
H046/02 Algorithms and problem solving
Verified Question paper with Marking Scheme Attached
Oxford Cambridge and RSA
Monday 19 May 2025 – Afternoon
AS Level Computer Science
H046/02 Algorithms and problem solving
Time allowed: 1 hour 15 minutes Do not use: • a calculator
Please write clearly in black ink. Do not write in the barcodes. Centre number Candidate number
First name(s) Last name
INSTRUCTIONS
- Use black ink.
- Write your answer to each question in the space provided. If you need extra space use the lined page at the end of this booklet. The question numbers must be clearly shown.
- Answer all the questions. INFORMATION
- The total mark for this paper is 70.
- The marks for each question are shown in brackets [ ].
- Quality of extended response will be assessed in questions marked with an asterisk (*).
- This document has 16 pages.
ADVICE
- Read each question carefully before you start your answer
© OCR 2025 [601/5030/0] DC (KS) 324952/8 OCR is an exempt Charity Turn over
© OCR 2025 Turn over
BLANK PAGE
DO NOT WRITE ON THIS PAGE
© OCR 2025
2 Players in a computer game collect items. Each item has a name, e.g. “Fruit” and a type, e.g. “Apple”. The items for player 1 are stored in a 2D array. The array is 0-indexed. The pseudocode declaration for the array is: array p1Items[10,2] The first dimension stores the item name and the second dimension stores the type.
(a) One characteristic of the array is that it has 2 dimensions. Identify two other characteristics of the given array. 1 ....................................................................................................................................................... .......................................................................................................................................................... 2 ....................................................................................................................................................... .......................................................................................................................................................... [2]
(b) When the game starts, the pseudocode procedure initialiseArraywill initialise each name and type in the array to "empty". 1 procedure initialiseArray(p1Items:byRef) 2 counter = 0 3 while counter < 10 04 p1Items[counter, 0] = "empty" 05 p1Items[counter, 1] = "empty" 06 counter = counter + 1 7 endwhile 8 endprocedure (i) State why emptyis in speech marks on lines 04and 05. .......................................................................................................................................................... ..................................................................................................................................................................... [1]
(ii) Rewrite the code in lines 02to 07to use a for loop instead of a while loop. Write your answer using pseudocode or program code. .......................................................................................................................................................... .......................................................................................................................................................... ..........................................................................................................................................................
© OCR 2025
(iii) State one reason why the array should be passed by reference and not by value. .......................................................................................................................................................... .................................................................................................................................................. [1]
(c) When a user collects an item, the name and type are added to the array p1Items. At the end of the game, the name of each item collected is output. Write an algorithm, using pseudocode or program code, to:
- output the name of each item in the array
- output a suitable message if there are no items in the array. If the item is "empty" it should not be output. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .................................................................................................................................................. [6]
© OCR 2025
[6]
© OCR 2025 Turn over
Additional space for question 3 if required. data x item y 0 1 2 3 4
© OCR 2025
© OCR 2025 Turn over
(b) The students intend to use both black-box testing and white-box testing. Give one difference between black-box testing and white-box testing. .......................................................................................................................................................... .......................................................................................................................................................... .................................................................................................................................................. [1]
© OCR 2025 Turn over
(d) The programmer needs to extend the program. The program will use a linear search. (i) 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 called value to search for as a parameter
- uses a linear search to find the value in the array
- returns true if the value is found and false otherwise. Complete the pseudocode function. function linearSearch(array, ................. ) counter = 0 while counter .......... array.length if array[counter] == value then return ………………………… endif counter = counter ………………………… endwhile ………………………… ………………………… endfunction [5] (ii) One alternative search algorithm is a binary search. Describe the steps in a binary search. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .................................................................................................................................................. [4]
© OCR 2025
6 Two data structures are a queue and a stack. (a) Describe one difference between a queue and a stack. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .................................................................................................................................................. [2] (b) The current contents of a stack created from an array called stack and pointer called topPointer are shown: index stack 7 6 5 4 3 2 13 1 21 0 10 The topPointer currently stores 2. (i) State the purpose of topPointer in the stack.
.......................................................................................................................................................... .................................................................................................................................................. [1]
© OCR 2025
7 Write an algorithm, using program code or pseudocode to:
- take a user’s date of birth as a string input in the format DD/MM/YYYY
- take a year as input from the user in the format YYYY
- output the age the user will be on their birthday in the year input in the format: You will be 18 on the 1 January 2029 You can use the function getMonth() to convert a 2-digit month into a string. For example: getMonth(02) will return "February". You do not need to check the inputs are in the correct format. You should assume the year entered will always be in the future. .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .................................................................................................................................................. [8]
© OCR 2025
8 Show each pass of a bubble sort to sort the following string data into descending order. friend sun earth orange night time .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .......................................................................................................................................................... .................................................................................................................................................. [4]
END OF QUESTION PAPER