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
Key facts
Arrays
1D array — a list of items of the same data type stored under one name, accessed by index. Example: colours = ["Red", "Green", "Blue"]. colours[0] = "Red".
2D array — a table of items (rows and columns). Example: grid[2][3] accesses row 2, column 3.
Indexing typically starts at 0 in most languages.
Jun 2022 Q5(a)(i): "Array" or "List" — both accepted. Q5(a)(ii): colours[1] = "Yellow".
Records and other structures
Record — a collection of related fields that may be of different data types. Like a row in a database. Example: a student record with name (string), age (integer), grade (string).
Arrays store items of the same type. Records store items of different types.
Records can be stored in arrays — an array of records creates a database-like structure.
Files are used to store data permanently (as opposed to arrays/records in RAM).
Data types — must know these
Integer — whole numbers (no decimal). Example: 42, -5.
Real/Float — numbers with decimal points. Example: 3.14.
Boolean — True or False only.
String — sequence of characters. Example: "Hello".
Character — a single character. Example: 'A'.
Choosing wrong data type = bugs. E.g. storing "42" as a string means you cannot do arithmetic on it.
Exam questions — 4 questions · 13 marks · from real 1CP2 past papers
1 markArray definition1CP2 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 indexing1CP2 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 array1CP2 style
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 type1CP2 style
A program needs to store whether a light switch is on or off. Which data type is most appropriate?