Past-paper question · 2025 May-June · Paper 42 · Q2(d)

Question 2(d) 2025 · May-June · Paper 42 · 17 marks

Original past-paper question for 2(D)
Original past-paper question for 2(D)
Original past-paper question for 2(D)
Reveal official mark-scheme answer Official mark-scheme answer for 2(D)Official mark-scheme answer for 2(D)Official mark-scheme answer for 2(D)

Official answer for Question 2

Part (d)

Question 1

mark each:

Question 6

  • Procedure header (and end where appropriate) taking one record as a parameter
  • Calling CalculateHash() with key from parameter record and storing/using return value
  • Checking if HashTable at return value from CalculateHash is empty record …
  • … if it is empty, store parameter in location
  • … otherwise, locating next free space in Spare …
  • … and storing in that index only (i.e. not in all other free spaces)
✓
9618/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Example program code:
✓
Java
✓
public static void InsertIntoHash(NewRecord TheRecord){
✓
Integer HashValue = CalculateHash(TheRecord.GetKey());
✓
if(HashTable[HashValue].GetKey().equals(-1)){
✓
HashTable[HashValue] = TheRecord;
✓
}else{
✓
for(Integer X = 0; X < 99; X++){
✓
if(Spare[X].GetKey().equals(-1)){
✓
Spare[X] = TheRecord;
✓
X = 99;
✓
}
✓
}
✓
}
✓
}
✓
VB.NET
✓
Sub InsertIntoHash(TheRecord)
✓
Dim HashValue As Integer = CalculateHash(TheRecord.Key)
✓
If HashTable(HashValue).Key = -1 Then
✓
HashTable(HashValue) = TheRecord
✓
Else
✓
For X = 0 To 99
✓
If Spare(X).Key = -1 Then
✓
Spare(X) = TheRecord
✓
X = 100
✓
End If
✓
Next
✓
End If
✓
End Sub
✓
9618/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Python
✓
def InsertIntoHash(TheRecord):
✓
global HashTable
✓
global Spare
✓
HashValue = CalculateHash(TheRecord.GetKey())
✓
if HashTable[HashValue].GetKey() == -1:
✓
HashTable[HashValue] = TheRecord
✓
else:
✓
for x in range(0, 100):
✓
if Spare[x].GetKey() == -1:
✓
Spare[x] = TheRecord
✓
break
✓
9618/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s25_ms_42.pdf →

Show text version of question

Question 2

Part (d)

Question 2

The total is initialised to the first value in the stack: 10

total = 10

The next two values are: + 3

total = 10 + 3 = 13

The next two values are: – 2

total = 13 – 2 = 11

The final total is 11 and this is returned.

Write program code for the function Calculate() to:

  • take each value from the stack
  • calculate and return the final total.

Save your program.

Copy and paste the program code into part 1(e) in the evidence document.

[7]

Question 5

Part (f)

(i)

Write program code to extend the main program to:

  • take a filename as input from the user
  • call ReadData() with the input filename
  • call Calculate()
  • output the final total.

Save your program.

Copy and paste the program code into part 1(f)(i) in the evidence document.

[2]

(ii)

Test your program twice with the file names:

StackData.txt SecondStack.txt

Take a screenshot of the output(s).

Save your program.

Copy and paste the screenshot into part 1(f)(ii) in the evidence document.

[2]

Question 6

2 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.

Part (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]
Topic relevance

Why this question appears here

60% assigned-topic match · Programming › Structured programming

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9618_s25_qp_42.pdf

Keep practising this topic