Skip to main content
A-LevelComputer ScienceData types and structures9618/41 · Oct/Nov 2023 · Q227 Marks

A linear queue is implemented using the 1D array, Queue. The index of the first element in the array is 0.

  1. (a)(i)Write program code to declare: • Queue — a global array with space to store 50 IDs of type string • HeadPointer — a global variable to point to the first element in the queue, initialised to -1 • TailPointer — a global variable to point to the next available space in the queue, initialised to 0. Save your program as Question2_N23. Copy and paste the program code into part 2(a)(i) in the evidence document.[2]
  2. (a)(ii)The procedure Enqueue () takes a string parameter. If the queue is full, the procedure outputs a suitable message. If the queue is not full, the procedure inserts the parameter into the queue and updates the relevant pointer(s). Write program code for Enqueue(). Save your program. Copy and paste the program code into part 2(a)(ii) in the evidence document.[4]
  3. (a)(iii)The function Dequeue() checks if the queue is empty. If the queue is empty, the function outputs a suitable message and returns the string "Empty". If the queue is not empty, the function returns the first element in the queue and updates the relevant pointer(s). Write program code for Dequeue(). Save your program. Copy and paste the program code into part 2(a)(iii) in the evidence document.[4]
  4. (b)A shop sells computer games. Each game has a unique identifier (ID) of string data type. The text file QueueData.txt contains a list of game IDs. The procedure ReadData() reads the data from the text file and inserts each item of data into the array Queue. Write program code for the procedure ReadData(). Save your program. Copy and paste the program code into part 2(b) in the evidence document.[6]
  5. (c)(i)Some game IDs appear in the text file more than once. The program needs to total the number of times each game ID appears in the text file. The record structure RecordData has the following fields: • ID — a string to store the game ID • Total — an integer to store the total number of times that game ID appears in the text file. Write program code to declare the record structure RecordData. If you are writing in Python, include attribute declarations as comments. Save your program. Copy and paste the program code into part 2(c)(i) in the evidence document.[2]
  6. (c)(ii)The global 1D array Records stores up to 50 items of type RecordData. The global variable NumberRecords stores the number of records currently in the array Records and is initialised to 0. Write program code to declare Records and NumberRecords. If you are writing in Python, include attribute declarations as comments. Save your program. Copy and paste the program code into part 2(c)(ii) in the evidence document.[2]
  7. (c)(iii)The pseudocode algorithm for the procedure TotalData(): • uses Dequeue () to remove an ID from the queue • checks whether a RecordData with the returned ID exists in Records • increments the total for that ID in the record if the ID already exists • creates a new record and stores it in Records if the ID does not exist. PROCEDURE TotalData() DECLARE DataAccessed : STRING DECLARE Flag : BOOLEAN DataAccessed ← Dequeue() Flag ← FALSE IF NumberRecords = 0 THEN Records[NumberRecords].ID ← DataAccessed Records[NumberRecords].Total ← 1 Flag ← TRUE NumberRecords ← NumberRecords + 1 ELSE FOR X ← 0 TO NumberRecords – 1 IF Records[X].ID = DataAccessed THEN Records[X].Total ← Records[X].Total + 1 Flag ← TRUE ENDIF NEXT X ENDIF IF Flag = FALSE THEN Records[NumberRecords].ID ← DataAccessed Records[NumberRecords].Total ← 1 NumberRecords ← NumberRecords + 1 ENDIF ENDPROCEDURE Write program code for the procedure TotalData(). Save your program. Copy and paste the program code into part 2(c)(iii) in the evidence document.[5]
  8. (d)The procedure OutputRecords() outputs the ID and total of each record in Records in the format: ID 1234 Total 4 Write program code for OutputRecords(). Save your program. Copy and paste the program code into part 2(d) in the evidence document.[1]
  9. (e)(i)The main program needs to: • call ReadData() • call TotalData() for each element in the queue • call OutputRecords(). Write program code for the main program. Save your program. Copy and paste the program code into part 2(e)(i) in the evidence document.[2]
  10. (e)(ii)Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 2(e)(ii) in the evidence document.[1]

Mark scheme

Marking points from the official mark scheme (Oct/Nov 2023). The mark or mark type is shown in brackets.

  1. [2] One mark each
  2. • (Global) array with identifier Queue with (minimum) 50 elements (of type string)
  3. • TailPointer (integer) initialised to 0, HeadPointer (integer) initialised to -1
  4. [4] One mark each
  5. • Procedure Enqueue() header (and close where appropriate) with one (string) parameter
  6. • Checking if queue is full and outputting suitable message
  7. • ... otherwise inserting parameter to next space
  8. • ... increment TailPointer and set HeadPointer to 0 if first item (HeadPointer = -1)
  9. [4] One mark each to max 4
  10. • Function header Dequeue() (and end where appropriate) with no parameter
  11. • Checking if empty ...
  12. • ... outputting suitable message and returning "Empty"
  13. • (otherwise) incrementing head pointer
  14. • returning next value (at head pointer before incrementing)
  15. [6] One mark each to max 6
  16. • Procedure header ReadData() with no parameters
  17. • Opening file ...
  18. • ... and closing file
  19. • Looping until EOF/set amount
  20. • Reading in each value
  21. • ... calling Enqueue () with each value
  22. • Use of exception handling with appropriate output
  23. [2] One mark each
  24. • Declaration of record type/class RecordData
  25. • ID as a string and total as an Integer
  26. [2] One mark each
  27. • (global) 1D Array named Records of type RecordData
  28. • (global) NumberRecords declared as integer and initialised to 0
  29. [5] One mark each to max 5
  30. • Incrementing NumberRecords each time (twice) a new record is added
  31. • Procedure header (and end) and using Dequeue() and storing/using return value
  32. • Checking if NumberRecords is 0 and creating a new record with ID and total as 1: IF NumberRecords = O THEN Records [NumberRecords].ID ← DataAccessed Records [NumberRecords].Total ← 1 Flag ← TRUE
  33. • Looping through all array elements to find matching ID and incrementing total if found FOR X ← 0 TO NumberRecords – 1 Check Python loop end IF Records[X].ID = DataAccessed THEN Records [X].Total ← Records(X).Total + 1 Flag ← TRUE ENDIF NEXT X
  34. • Adding new record if record is not found, storing ID and total as 1 IF Flag = FALSE THEN Records [NumberRecords].ID ← DataAccessed Records [NumberRecords].Total ← 1 NumberRecords ← NumberRecords + 1 ENDIF
  35. [1] One mark each
  36. • Looping through all array elements and outputting ID and total in correct format
  37. [2] One mark each
  38. • Calling ReadData() first and OutputRecords() last
  39. • Looping through all queue elements and calling TotalData() for each queue element
  40. [1] One mark for screenshot e.g. ID 1234 Total 1

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, 27 marks.
Source
A-Level Computer Science, Oct/Nov 2023 Paper 4 Variant 1, 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