Skip to main content
A-LevelComputer ScienceData types and structures9618/42 · May/June 2025 · Q222 Marks

A program stores data in a 1D array of records, HashTable. The array has space for 200 records. Each data item is stored in a specific index of the array that is calculated using an algorithm. The index is calculated from the key field using the formula: Key MOD 200 If two key fields generate the same index, there is a collision. Any records that have a collision are stored in a second array, Spare. This array has space for 100 records. When a collision is detected, the record is stored in the next free space in Spare.

  1. (a)The pseudocode record format is: TYPE NewRecord DECLARE Key : INTEGER DECLARE Item1 : INTEGER DECLARE Item2 : INTEGER ENDTYPE Write program code to declare the record type NewRecord If your chosen programming language does not support record formats, a class can be used instead. Save your program as Question2_J25. Copy and paste the program code into part 2(a) in the evidence document.[2]
  2. (b)(i)Write program code to declare the global arrays HashTable and Spare Save your program. Copy and paste the program code into part 2(b)(i) in the evidence document.[1]
  3. (b)(ii)An empty record has the integer -1 stored in each field. The procedure Initialise () stores an empty record in each element in HashTable and Spare Write program code for Initialise() Save your program. Copy and paste the program code into part 2(b)(ii) in the evidence document.[2]
  4. (c)The hash value is calculated from the key field using the formula: Key MOD 200 The function CalculateHash() takes a key field as a parameter and calculates and returns the hash value for the key field. Write program code for CalculateHash() Save your program. Copy and paste the program code into part 2(c) in the evidence document.[2]
  5. (d)The procedure InsertIntoHash(): • takes a record of type NewRecord as a parameter • uses CalculateHash() to calculate the hash value for the key field in the record • checks if the hash value index in HashTable currently stores an empty record Ο if the index stores an empty record, store the parameter in this index Ο if the index does not store an empty record, store the parameter in Spare You can assume there will always be enough space in Spare to store any collisions. Write program code for InsertIntoHash() Save your program. Copy and paste the program code into part 2(d) in the evidence document.[6]
  6. (e)The text file HashData.txt stores up to 200 rows of data to be stored into the hash table. Each row contains three integer numbers separated by commas. The first number is the key field, the second number is item 1 and the third number is item 2. For example: The first row in the text file contains: 646,12,568 The key field is 646, item 1 is 12 and item 2 is 568 The procedure CreateHashTable(): • opens the file HashData.txt • creates a record for each row of data in the file • calls InsertIntoHash() with each record. Write program code for CreateHashTable() Save your program. Copy and paste the program code into part 2(e) in the evidence document.[5]
  7. (f)(i)The procedure PrintSpare() outputs the key field of each element in the array Spare that does not contain an empty record. Write program code for PrintSpare() Save your program. Copy and paste the program code into part 2(f)(i) in the evidence document.[2]
  8. (f)(ii)The main program should call the procedure to initialise the arrays, call the procedure to create the hash table and then call the procedure to output the contents of the array Spare Write program code for the main program. Save your program. Copy and paste the program code into part 2(f)(ii) in the evidence document.[1]
  9. (f)(iii)Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 2(f)(iii) in the evidence document.[1]

Mark scheme

Marking points from the official mark scheme (May/June 2025). The mark or mark type is shown in brackets.

  1. [1] Record/class NewRecord declared
  2. [1] 3 variables within structure (all integer)
  3. [1] HashTable (200 records) and Spare (100 records) declared as (global) arrays
  4. [1] Procedure Initialise() header (and close where appropriate) that initialises all elements in both arrays ...
  5. [1] ... to an empty record with -1 in each of the 3 fields/elements
  6. [1] Function header (and close where appropriate), taking one (integer) parameter and returning the calculated value
  7. [1] Calculation of parameter MOD 200
  8. [1] Procedure header (and end where appropriate) taking one record as a parameter
  9. [1] Calling CalculateHash() with key from parameter record and storing/using return value
  10. [1] Checking if HashTable at return value from CalculateHash is empty record
  11. [1] ... if it is empty, store parameter in location
  12. [1] ... otherwise, locating next free space in Spare ...
  13. [1] ... and storing in that index only (i.e. not in all other free spaces)
  14. [1] Procedure header (and end where appropriate), opening and closing file HashData.txt
  15. [1] Reading in all lines of data
  16. [1] splitting each line by commas
  17. [1] Creating record with correct values with each line read in from file
  18. [1] Calling InsertIntoHash() with each record they have created
  19. [1] Exception handling for opening and reading from file with appropriate catch and output.
  20. [1] Procedure header (and end where appropriate) and looping through each element in Spare ...
  21. [1] ... checking if record is empty and outputting key field if not empty
  22. [1] 1 mark for calling Initialise() then CreateHashTable() then PrintSpare()
  23. [1] 1 mark for output

Write your answer and get it marked

On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.

Sign up free →

About this question

Topic
Data types and structures, A-Level Computer Science (syllabus 9618). Structured question, 22 marks.
Source
A-Level Computer Science, May/June 2025 Paper 4 Variant 2, question 2.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep