Session XP: 0
Spec 1.2.2, 6.3.1Paper 1 and Paper 2

Data Structures & Arrays

1D arrays, 2D arrays, records, and how data structures appear in programs. Jun 2022 Q5(a)(i)/(ii) tested arrays directly.

—
Best score
—
Last attempt
Best attempt progress
0
XP earned
Watch first — Craig 'n' Dave
Craig 'n' Dave · Edexcel 1CP2Data structures and arrays (12:46)
Craig 'n' Dave · Edexcel 1CP2The use of data types and casting (10:09)
Craig 'n' Dave · Edexcel 1CP2Using one and two-dimensional structured data types (14:35)
Key facts

Arrays — fill in the table

Indexing typically starts at 0 in most languages. (Jun 2022 Q5(a)(i): "Array" or "List" both accepted. Q5(a)(ii): colours[1] = "Yellow".)

TermDefinition
1D array
2D array

Records and other structures — fill in the table

PointDetail
Record
Arrays vs records
Array of records
Files

Data types — must know these — fill in the table

Data typeExample
Integer
Real/Float
Boolean
String
Character

Choosing the wrong data type causes bugs — e.g. storing "42" as a string means you cannot do arithmetic on it.

Strings, 2D arrays and why (spec 1.2.2, 6.3.1) — fill in the table

PointDetail
Need for data structures
String
2D array
Example
Iteration
Iterating over data structures
nums = [4, 8, 15]
total = 0
for n in nums:
    total = total + n
print(total)             # 27

grid = [[1, 2, 3], [4, 5, 6]]
for row in grid:
    for item in row:
        print(item)
Exam questions — 6 questions · 10 marks · from real 1CP2 past papers
1 markArray definitionPaper 1 · spec 1.2.2 (1CP2 Jun 2022 Q5(a)(i) style)

What type of data structure stores a collection of items of the same data type, accessed by index?

A Record
B File
C Array
D Boolean
2 marksArray indexingPaper 1 · spec 1.2.2 (1CP2 Jun 2022 Q5(a)(ii) style)

An array is defined as: colours = ["Red", "Green", "Blue", "Yellow", "Purple"] What is the value of colours[1]? And what index does "Purple" have? (2 marks)

Hint: Remember: index 0 = first element. Count from 0.
+20 XP
2 marksRecord vs arrayPaper 1 · spec 1.2.2

Explain the difference between an array and a record as data structures. (2 marks)

Hint: Key distinction: arrays = same data type. Records = can have different data types (fields). Give an example for each.
+20 XP
1 markBoolean data typePaper 2 · spec 6.3.1

A program needs to store whether a light switch is on or off. Which data type is most appropriate?

A Integer
B String
C Real
D Boolean
1 mark2D arraysPaper 1 · spec 1.2.2

grid = [[1, 2, 3], [4, 5, 6]] What is the value of grid[1][2]?

A 2
B 3
C 6
D 5
3 marksIterating over a listPaper 2 · spec 6.2.2

The list nums holds [4, 8, 15]. Write Python that adds up every item in nums and prints the total. (3 marks)

Hint: Set a total before the loop, then add each item as the loop visits it.
+30 XP
Quick recall flashcards

Module complete! 🎉

Score loading...

⚡ +10 XP