Question bank › A-level › A-level Computer Science › Fundamentals of data structures

Arrays, records, files and abstract data types

10 questions45 marksabout 55 min

Answer on paper first, then reveal the mark scheme one mark at a time.

1Core4 marks

(a) Explain the difference between a static data structure and a dynamic data structure. [2]

(b) A stack is described as a LIFO data structure and a queue as a FIFO data structure. Explain what is meant by each of these terms. [2]

2Core3 marks

A software library provides a Stack as an abstract data type (ADT) with the operations Push, Pop, Peek and IsEmpty. The library documentation does not say how the stack is stored in memory.

(a) Explain what is meant by an abstract data type. [1]

(b) Explain two benefits to a programmer of using the stack as an ADT rather than writing code that works directly on the array or linked list that stores it. [2]

3Standard4 marks

The two-dimensional array Temps shown in the diagram stores the midday temperature (°C) at a weather station. Each row holds five readings. Elements are accessed as Temps[row][col] and indexing starts at 0.

(a) State the value of Temps[2][3]. [1]

The following algorithm is applied to Temps.

best ← 0
bestRow ← -1
FOR r ← 0 TO 3
  total ← 0
  FOR c ← 0 TO 4
    IF Temps[r][c] > 10 THEN
      total ← total + Temps[r][c]
    ENDIF
  ENDFOR
  IF total > best THEN
    best ← total
    bestRow ← r
  ENDIF
ENDFOR
OUTPUT bestRow, best

(b) State the values output by the algorithm. [2]

(c) State how many times the condition Temps[r][c] > 10 is evaluated when the algorithm runs. [1]

Tempscol 0col 1col 2col 3col 4row 0121591411row 1813171016row 219712186row 3111410920
Stuck on Arrays, records, files and abstract data types?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Hard5 marks

A one-dimensional array Rainfall holds 30 real values: the rainfall in mm recorded on each day of a month. The first element is Rainfall[0].

Write an algorithm, using pseudo-code, that:

  • calculates the mean daily rainfall for the month
  • counts how many days had rainfall greater than the mean
  • finds the index of the first day that had the highest rainfall
  • outputs the count and the index.

You must not use any built-in functions for the mean, maximum or counting. [5]

5Standard5 marks

A gym stores details of its members in a file. Each member is stored using the record structure below.

RECORD Member
  MemberID    : ?
  Surname     : String
  DateJoined  : Date
  MonthlyFee  : ?
  IsStudent   : ?
ENDRECORD

(a) Using the gym example, explain the difference between a field and a record. [2]

(b) State the most suitable data type for MonthlyFee and for IsStudent. [2]

(c) Membership IDs look like 004719. Explain why MemberID should be stored as a string rather than an integer. [1]

6Standard5 marks

The text file orders.txt contains the four lines below. Each line holds a product code, a quantity and a unit price, separated by commas.

A17,3,2.50
B04,10,0.75
A22,1,12.00
C09,4,3.20

The following algorithm processes the file. SPLIT(s, ",") returns an array of the parts of string s, starting at index 0. SUBSTRING(0, 0, s) returns the first character of s.

total ← 0
count ← 0
OPENFILE "orders.txt" FOR READING
WHILE NOT EndOfFile("orders.txt")
  line ← READLINE("orders.txt")
  parts ← SPLIT(line, ",")
  cost ← STRING_TO_INT(parts[1]) * STRING_TO_REAL(parts[2])
  IF SUBSTRING(0, 0, parts[0]) = "A" THEN
    count ← count + 1
  ENDIF
  total ← total + cost
ENDWHILE
CLOSEFILE "orders.txt"
OUTPUT total, count

(a) State the values of total and count that are output. [2]

(b) Explain why the functions STRING_TO_INT and STRING_TO_REAL are needed. [1]

(c) The company plans to store the same orders in a binary file instead. Describe two differences between a text file and a binary file. [2]

7Hard5 marks

A shop stores its stock in a binary file of fixed-length records. Each record has the fields below.

FieldStorage
ItemIDinteger, 4 bytes
Descriptionexactly 20 characters, 1 byte per character
Pricereal, 8 bytes
InStockBoolean, 1 byte

The file has no header, and the first byte of the file is at byte position 0. Records are numbered 1, 2, 3, …

(a) Calculate the size of one record in bytes. [1]

(b) Calculate the byte position of the first byte of record number 250. Show your working. [2]

(c) The file is 1 650 000 bytes long. Calculate how many records it holds. [1]

(d) Explain why storing the records with a fixed length allows record 250 to be read without reading records 1 to 249. [1]

8Hard4 marks

A fitness app records a GPS reading every few seconds while a user is running. The number of readings in a session is not known in advance; most sessions produce between 200 and 3000 readings, but a few produce over 20 000. When the session ends, the readings are processed in order and individual readings are often looked up by position.

A developer is deciding between a static data structure (an array declared with 10 000 elements) and a dynamic data structure (a linked list that grows as readings arrive).

Discuss the advantages and disadvantages of each option for this app. [4]

9Core4 marks

For each situation, state the name of the most suitable abstract data type. Choose from: stack, linear queue, priority queue, graph, tree, dictionary.

(a) Storing the bus stops in a city and the routes that link pairs of stops, so that journeys can be planned. [1]

(b) Holding patients in a hospital emergency department so that the most seriously ill patient is seen next, regardless of arrival time. [1]

(c) Storing the previous web pages visited in a browser so that the Back button returns to the most recently visited page. [1]

(d) Looking up the English translation of a French word, where each French word appears only once. [1]

10Stretch6 marks

The 3 × 3 array Grid has the initial contents shown in the diagram. Elements are accessed as Grid[row][col], starting at index 0.

FOR i ← 0 TO 1
  FOR j ← i + 1 TO 2
    temp ← Grid[i][j]
    Grid[i][j] ← Grid[j][i]
    Grid[j][i] ← temp
  ENDFOR
ENDFOR
FOR i ← 0 TO 2
  temp ← Grid[i][0]
  Grid[i][0] ← Grid[i][2]
  Grid[i][2] ← temp
ENDFOR

(a) Show the contents of Grid after the first (nested) loop has finished. [2]

(b) Show the contents of Grid after the whole algorithm has finished, and state what the algorithm does to any square array. [2]

(c) A student changes the first two lines to FOR i ← 0 TO 2 and FOR j ← 0 TO 2. Explain the effect this has on the result of the whole algorithm. [2]

Grid (initial contents)col 0col 1col 2row 0582row 1719row 2364

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session