Data Structures & Arrays (Edexcel GCSE Computer Science)

Revision Note

James Woodhouse

Expertise

Computer Science

What is a data structure?

  • A data structure is a way of storing and organising data under one identifier so that it can be accessed and used efficiently

  • There are a wide range of data structures in Computer Science, however, the exam only requires knowledge of:

    • Strings

    • Arrays

    • Records

Strings

What is a string?

  • A string is a sequence of characters

  • Speech marks can often identify something as a string

  • Examples of strings include:

    • "Hello worlds"

    • "ABC"

    • "@#!%"

  • It is important to choose the correct data type for a given situation to ensure accuracy and efficiency in the program

  • Data types can be changed within a program, this is called casting

Records

What is a database?

  • A Database is an organised collection of data

  • It allows easy storage, retrieval, and management of information

  • A database is useful when working with large amounts of data, databases are stored on secondary storage

  • A database is often stored on remote servers so multiple users can access it at the same time, useful for online systems

  • Data can be sorted and searched efficiently, making use of more advanced structures

  • They are more secure than text files

  • A database uses fields and records to organise how it stores data

What are fields & records?

  • A field is one piece of information relating to one person, item or object

  • A field is represented in a database by a column,

  • A record is a collection of fields relating to one person, item or object

  • A record is represented in a database by a row

Text files

  • A text file is useful when working with small amounts of data, text files are stored on secondary storage and 'read' in to a program when being used

  • They are used to store information when the application is closed

  • Each entry is stored on a new line or separated with a special identifier, for example a comma (',')

  • It can be difficult in text files to know where a record begins and ends

8-records-to-store-data

Arrays

  • An array is useful when working with small amounts of data, arrays are stored in main memory (RAM)

  • They are used to store information when the application is in use

  • Can be more efficient and much faster to search than working with text files

1-Dimensional Arrays

What is an array?

  • An array is an ordered, static set of elements in a fixed-size memory location

  • An array can only store 1 data type

  • A 1D array is a linear array

  • Indexes start at 0, known as zero-indexed

1d-array-example

Concept

Python

Create

scores = []

Creates a blank array

scores = [12, 10, 5, 2, 8]

Creates an array called scores with values assigned

Assignment

colours[4] = "Red"

 Assigns the colour "Red" to index 4 (5th element)

Example in Python

Creating a one-dimensional array called ‘array’ which contains 5 integers.

  • Create the array with the following syntax:
    array = [1, 2, 3, 4, 5]

  • Access the individual elements of the array by using the following syntax:
    array[index]

  • Modify the individual elements by assigning new values to specific indexes using the following syntax:
    array[index] = newValue

  • Use the len function to determine the length of the array by using the following syntax:
    len(array)

  • In the example the array has been iterated through to output each element within the array. A for loop has been used for this

Python

# Creating a one-dimensional array
array = [1, 2, 3, 4, 5]

# Accessing elements of the array
print(array[0])   # Output: 1
print(array[2])   # Output: 3

# Modifying elements of the array
array[1] = 10
print(array)      # Output: [1, 10, 3, 4, 5]

# Iterating over the array
for element in array:
    print(element)

# Output:
# 1
# 10
# 3
# 4
# 5

# Length of the array
length = len(array)
print(length)     # Output: 5

2-Dimensional Arrays

What is a 2-dimensional array?

  • A 2D array extends the concept on a 1D array by adding another dimension

  • A 2D array can be visualised as a table with rows and columns

  • When navigating through a 2D array you first have to go down the rows and then across the columns to find a position within the array

2d-array-example

Concept

OCR exam reference

Python

Create

array players[3,3]

players = [],[]

Creates a blank 2D array with 3 elements (0-2)

Creates a blank 2D array

players = ["Rob","Paul","Hayley"],[10, 5, 8] 

players = ["Rob","Paul","Hayley"],[10, 5, 8] 

Creates a 2D array called players with values assigned

Assignment

players[0,1] = "Holly"

players[0][1] = "Holly"

 Assigns the name "Holly" to index 0, 1 (1st row, 2nd column) - replaces "Paul"

Example in Python

Python

# Initialising a 2D array with 3 rows and 3 columns, with the specified values
array_2d = [[1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]]

# Accessing elements in the 2D array
print(array_2d[0][0])  # Output: 1
print(array_2d[1][2])  # Output: 6

Exam Tip

In the exam, the question will always give an example to demonstrate which order the array is being read from.

Some questions can be X,Y and others can be Y, X. Always refer to the example before giving your answer!

Worked Example

A parent records the length of time being spent watching TV by 4 children

Data for one week (Monday to Friday) is stored in a 2D array with the identifier minsWatched.

The following table shows the array

 

Quinn

Lyla

Harry

Elias

0

1

2

3

Monday

0

34

67

89

78

Tuesday

1

56

43

45

56

Wednesday

2

122

23

34

45

Thursday

3

13

109

23

90

Friday

4

47

100

167

23

Write a line of code to output the number of minutes that Lyla watched TV on Tuesday [1]  

Write a line of code to output the number of minutes that Harry watched TV on Friday [1]

Write a line of code to output the number of minutes that Quinn watched TV on Wednesday [1]  


Answers 

  • print(minsWatched[1,1] or print(minsWatched[1][1]

  • print(minsWatched[2,4] or print(minsWatched[2][4]

  • print(minsWatched[0,2] or print(minsWatched[0][2]

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

James Woodhouse

Author: James Woodhouse

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.