Data Structures Flashcards

All 16 cards in this deck

What is a record?

A data structure that groups together related items of data (fields) about one thing, e.g. a Car record with the fields make, price and noOfDoors.

What is a field in a record?

A single item of data within a record, e.g. a name or an email address.

True or false? Every field in a record must be of the same data type.

False. Unlike an array, a record can hold fields of different data types.

Give one advantage of storing data about one item in a record rather than in separate variables.

All the related data is kept together under one identifier, so the item can be handled as a single unit, e.g. stored in an array of records or passed to a subroutine as one parameter.

What is an array?

A data structure that holds a collection of values of the same data type under one identifier, with each value accessed by its index.

True or false? In the array scores, the first element is scores[1].

False. Array indexes start at 0, so the first element is scores[0].

How do you store a value in, and read a value from, one element of a 1D array?

e.g. scores ← [0, 0, 0]

Use the array's identifier with the index in square brackets:

  • store: scores[0] ← 10
  • read: OUTPUT scores[0] → 10

How is one element of a 2D array accessed in AQA pseudo-code?

e.g. an array score with 3 rows and 2 columns

With two indexes, each in its own square brackets, row first: score[0][1] is row 0, column 1.

How do you process every element of a 2D array?

e.g. an array with 3 rows and 2 columns

Use nested loops — an outer loop counting through the rows and an inner loop counting through the columns.

In AQA pseudo-code, how do you create an array and fill it with values in one statement?

e.g. an array colours holding red, green and blue

List the values in square brackets: colours ← ['red', 'green', 'blue']. The array has as many elements as values listed (3).

What is a data structure?

An organised collection of values, stored so that the data can be accessed and processed together, e.g. an array or a record.

Why might a program store 30 test marks in an array rather than in 30 separate variables?

All the marks share one identifier, and a loop can use the index to process every element, so the code is shorter and easier to change.

How is a record defined in AQA pseudo-code?

e.g. a Car with a make, a price and a number of doors

Between RECORD Car and ENDRECORD, each field is listed with its data type:
make : String
price : Real
noOfDoors : Integer

In AQA pseudo-code, how is a variable created from a record definition?

e.g. a Car record for a Ford costing £8,000 with 5 doors

Use the record's name with the field values in brackets, in the same order as the fields were defined:
myCar ← Car('Ford', 8000.0, 5)

In AQA pseudo-code, how do you read or change one field of a record?

e.g. the price field of myCar

Use dot notation: the variable's name, a dot, then the field name.

  • read: OUTPUT myCar.price
  • change: myCar.price ← 7500.0

What does LEN return when it is used on an array?

e.g. names ← ['Ali', 'Bea', 'Cai']

The number of elements in the array, here 3. Indexes start at 0, so the last index is LEN(names) - 1, which is 2.