Data Structures (AQA GCSE Computer Science)

Exam Questions

17 mins10 questions
11 mark

A programmer has started to write a program using Python.

Their program is shown in Figure 6.

The program should generate and output 10 numbers, each of which is randomly selected from the numbers in a data structure called numbers.

The program uses the random module.

For example, random.randrange(0, 8) would generate a random integer between 0 and 7 inclusive.

One possible output from the finished program would be 11, 14, 14, 42, 2, 56, 56, 14, 4, 2

  • Line numbers are included but are not part of the program.

Figure 6

1 import random
2 numbers = [ 11, 14, 56, 4, 12, 6, 42, 2 ]
3 count = 0
4 while count < 10:
5   count = count + 1
6   number = random.randrange(0, 8
7   print(numbers[count])

What type of data structure is the variable numbers?

Did this page help you?

21 mark

Identify one choice that best defines a ‘data structure’.

  • A system for compiling code into a machine-readable format

  • A process of encrypting data for secure storage

  • A software program designed to analyse data patterns

  • A way of organising and storing data in a computer

Did this page help you?

31 mark

Identify one choice that IS NOT an example of a data structure.

  • Array

  • Field

  • List

  • Record

Did this page help you?

41 mark

Define the term ‘field’ in a database

Did this page help you?

11 mark

Figure 13

1 arr[0] ← 'c'
2 arr[1] ← 'b'
3 arr[2] ← 'a'
4 FOR i ← 0 TO 1
5     FOR j ← 0 TO 1
6         IF arr[j + 1] < arr[j] THEN
7            temp ← arr[j]
8            arr[j] ← arr[j + 1]
9            arr[j + 1] ← temp
10         ENDIF
11      ENDFOR
12 ENDFOR

An earlier attempt at writing the algorithm in Figure 13 had different code for lines 4 and 5.

Lines 4 and 5 of the pseudocode were:

FOR i ←  0 TO 2 
    FOR j ←  0 TO 2

Explain why the algorithm did not work when the value 2 was used instead of the value 1 on these two lines.

Did this page help you?

23 marks

Explain the difference between a record and a field in a database.

Provide an example to illustrate your answer.

Did this page help you?

32 marks

Describe two advantages of using a database over a text file for storing large amounts of data.

Did this page help you?

11 mark

Figure 8 shows an algorithm, written using pseudocode, that uses a RECORD data structure for storing information about a film.

Each record stores four pieces of information about a film:

  • film title

  • certificate (eg 12A, PG)

  • year the film was made

  • if the film is currently being shown at a cinema

There are records for three films and these films are stored alphabetically in an array called filmCollection.

The pseudocode outputs the title of the newest of the three films.

  • Part of the algorithm has been replaced by the label L1.

Figure 8

RECORD Film
   title : String
   certificate : String
   year : Integer
   beingShown : Boolean
ENDRECORD


hulk ← Film('Hulk', '12A', 2005, False)
ironMan ← Film('Iron Man', '12A', 2008, False)
antMan ← Film('Ant-Man', '12A', 2015, False)
filmCollection ← [antMan, hulk, ironMan]
year ← 0
position ← 0


FOR i ← 0 TO L1
   IF filmCollection[i].year > year THEN
      year ← filmCollection[i].year
      position ← i
   ENDIF
ENDFOR

OUTPUT filmCollection[position].title, ' is the newest film'

Write a pseudocode statement that updates the antMan record to show that the film is currently being shown at the cinema.

Did this page help you?

24 marks

A program is being written to simulate a computer science revision game in the style of bingo.

At the beginning of the game a bingo ticket is generated with nine different key terms from computer science in a 3 x 3 grid. An example bingo ticket is provided in Figure 15.

Figure 15

CPU

ALU

Pixel

NOT gate

Binary

LAN

Register

Cache

Protocol

The player will then be prompted to answer a series of questions

If an answer matches a key term on the player’s bingo ticket, then the key term will be marked off automatically

Figure 16 shows an incomplete Python program to create a bingo ticket for a player.

The programmer has used a two-dimensional array called ticket to represent a bingo ticket.

The program uses a subroutine called generateKeyTerm. When called, the subroutine will return a random key term, eg "CPU", "ALU", "NOT gate" etc.

Complete the Python program in Figure 16 by filling in the five gaps.

  • Line numbers are included but are not part of the program.

Figure 16

1 ticket = [["","",""],["","",""],["","",""]]
2 i = 0
3 while i < 3:
4     j = ____
5     while j < 3:
6         ticket[ ____ ][ ____ ] = generateKeyTerm()
7 ______________
8 ______________

Did this page help you?

32 marks

A school has a database to store information about students, including their student ID, name, age, and grades.

The database is structured using records and fields.

The school needs to frequently search and sort through student data.

Explain why a database is more suitable than an array for this purpose.

Did this page help you?