What you'll learn
This revision guide covers all testable content on programming and data structures for Edexcel GCSE Computer Science. You'll master how programs store and manipulate collections of data using arrays, lists, and records, understand when to use each structure, and learn to implement them correctly in code. These concepts underpin practical programming tasks in both Paper 1 and the programming project.
Key terms and definitions
Array — A data structure that stores a fixed number of elements of the same data type, accessed using an index number.
List — A dynamic data structure that can grow or shrink in size, storing elements that can be accessed, added, or removed.
Index — The numeric position of an element within an array or list, starting from 0 in most programming languages.
Two-dimensional array — An array arranged in rows and columns, accessed using two index values (like a table or grid).
Record — A data structure that groups together related data items of different types under one name (also called a tuple or struct).
Field — An individual data item within a record, each with its own identifier and data type.
File handling — The process of reading data from or writing data to an external file for permanent storage.
Data structure — An organized way of storing and managing data in a computer program to enable efficient access and modification.
Core concepts
Arrays
An array is a fundamental data structure that stores multiple values of the same type in a single variable. Each element occupies a numbered position (index) starting from 0.
One-dimensional arrays:
- Declare with a fixed size:
scores = [0, 0, 0, 0, 0] - Access elements using square brackets:
scores[0] = 85 - Useful for storing lists like test scores, temperatures, or player names
- Cannot change size once created
- All elements must be the same data type
Two-dimensional arrays:
- Organized in rows and columns like a spreadsheet
- Accessed with two indices:
grid[row][column] - Declaration:
seatingPlan = [["", "", ""], ["", "", ""], ["", "", ""]] - First index selects the row, second selects the column
- Common uses: grids, boards for games, tables of data
Key operations:
- Traversing (looping through):
for i in range(len(scores)): - Searching for values
- Finding maximum/minimum values
- Calculating totals or averages
- Sorting elements
Lists
A list is more flexible than an array because it can change size during program execution. Lists are the primary dynamic data structure at GCSE level.
List operations you must know:
Adding elements:
.append(item)— adds to the end of the list.insert(index, item)— adds at a specific position
Removing elements:
.remove(item)— removes first occurrence of the value.pop(index)— removes and returns element at index.pop()— removes and returns last element
Accessing elements:
- Direct access:
names[2] - Length:
len(names) - Checking membership:
if "Sarah" in names:
Other operations:
.sort()— arranges in ascending order.reverse()— reverses order- Slicing:
names[1:4]— extracts portion of list
Lists vs Arrays:
- Lists grow and shrink dynamically
- Arrays have fixed size
- Both use zero-based indexing
- Both store ordered collections
Records and data abstraction
A record (or tuple in Python) groups related data items that may have different data types. This models real-world entities effectively.
Structure:
student = ("John Smith", 15, "10B", [78, 82, 91])
This record contains:
- Field 0: name (string)
- Field 1: age (integer)
- Field 2: form group (string)
- Field 3: test scores (list)
Accessing fields:
- By index:
studentName = student[0] - Unpacking:
name, age, form, scores = student
Practical uses:
- Storing customer details (name, address, account number)
- Maintaining inventory items (product code, description, quantity, price)
- Recording game characters (username, level, health, position)
Arrays of records: Combine structures to handle multiple complex entities:
students = [
("John Smith", 15, "10B"),
("Maya Patel", 16, "10A"),
("Carlos Rivera", 15, "10B")
]
Access using two indices: students[0][1] gets John's age (15).
File handling
Programs need to save data permanently to files and load it back when needed. File handling involves opening, reading, writing, and closing files.
Writing to a text file:
file = open("scores.txt", "w")
file.write("Player1,850\n")
file.write("Player2,920\n")
file.close()
Reading from a text file:
file = open("scores.txt", "r")
lines = file.readlines()
file.close()
for line in lines:
print(line.strip())
File modes:
"r"— read mode (file must exist)"w"— write mode (creates new file or overwrites existing)"a"— append mode (adds to end of existing file)
Processing file data:
- Open the file in appropriate mode
- Read data (
.read(),.readline(),.readlines()) - Process data (split strings, convert types, store in structures)
- Close the file to free system resources
CSV files: Comma-separated values store structured data:
Name,Age,Score
Alice,16,94
Ben,15,87
Parse by splitting each line on commas:
parts = line.split(",")
name = parts[0]
age = int(parts[1])
score = int(parts[2])
String manipulation
Strings behave like lists of characters, supporting similar operations crucial for processing text data.
Key operations:
- Length:
len(message) - Concatenation:
fullName = firstName + " " + lastName - Accessing characters:
firstLetter = name[0] - Slicing:
name[0:4]extracts first 4 characters - Case conversion:
.upper(),.lower() - Finding substrings:
.find("text")returns index or -1
String methods:
.strip()— removes whitespace from both ends.split(delimiter)— creates list from string.replace(old, new)— substitutes text.isdigit()— checks if all characters are digits.isalpha()— checks if all characters are letters
Traversing strings:
for char in password:
if char.isdigit():
digitCount = digitCount + 1
Searching and sorting algorithms
Understanding how to find data and arrange it in order is essential for efficient programs.
Linear search:
- Checks each element sequentially from start to end
- Works on unsorted data
- Stops when item found or end reached
- Time increases linearly with data size
def linearSearch(items, target):
for i in range(len(items)):
if items[i] == target:
return i
return -1
Binary search:
- Only works on sorted data
- Repeatedly divides search area in half
- Much faster for large datasets
- Requires sorted input
def binarySearch(items, target):
low = 0
high = len(items) - 1
while low <= high:
mid = (low + high) // 2
if items[mid] == target:
return mid
elif items[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
Bubble sort:
- Repeatedly steps through list
- Compares adjacent pairs
- Swaps if in wrong order
- Continues until no swaps needed
Key points:
- You must know when to use each algorithm
- Binary search requires sorted data but is faster
- Linear search works on any data but slower for large lists
- Understand time efficiency concepts
Worked examples
Example 1: Array manipulation (4 marks)
Question: A program stores daily temperatures for a week in an array called temps. Write code to calculate and display the average temperature. Show how the array is declared with sample data.
Mark scheme answer:
temps = [18, 20, 19, 22, 21, 20, 18] # 1 mark - declaration with data
total = 0 # 1 mark - initialise accumulator
for temp in temps:
total = total + temp # 1 mark - loop and accumulation
average = total / len(temps)
print(average) # 1 mark - calculate and output average
Examiner notes: Award marks for correct array declaration, proper accumulation within a loop structure, and correct average calculation. Accept different loop styles (e.g., for i in range(len(temps))).
Example 2: List operations (5 marks)
Question: A cinema booking system uses a list to store customer names. Write code that:
- Creates an empty list called
bookings - Adds three customer names
- Removes the second customer
- Displays how many bookings remain
Mark scheme answer:
bookings = [] # 1 mark - create empty list
bookings.append("Sarah Jones") # 1 mark - add first name
bookings.append("Michael Chen")
bookings.append("Aisha Ahmed") # all three additions
bookings.pop(1) # 1 mark - remove second element (index 1)
# OR bookings.remove("Michael Chen")
print("Bookings remaining:", len(bookings)) # 2 marks - display count with label
Examiner notes: Accept .remove() or .pop() for deletion if correct. Award final 2 marks for using len() function and appropriate output statement.
Example 3: File handling (6 marks)
Question: Write a program that reads student names and scores from a file called "results.txt" where each line contains a name and score separated by a comma (e.g., "Tom,78"). Store the data in a suitable structure and calculate the average score.
Mark scheme answer:
file = open("results.txt", "r") # 1 mark - open in read mode
lines = file.readlines() # 1 mark - read all lines
file.close() # 1 mark - close file
total = 0
count = 0
for line in lines: # 1 mark - loop through lines
parts = line.strip().split(",") # 1 mark - split on delimiter
score = int(parts[1]) # convert to integer
total = total + score
count = count + 1
average = total / count # 1 mark - calculate average
print("Average score:", average)
Examiner notes: Award marks for correct file operations, parsing CSV data with .split(), type conversion, and average calculation. Accept alternative valid approaches like storing in lists before processing.
Common mistakes and how to avoid them
Confusing array/list indices — Remember that indices start at 0, not 1. The first element is
items[0], and the last isitems[len(items)-1]. Drawing out array positions helps visualize this.Forgetting to close files — Always include
file.close()after file operations. Not closing files can cause data loss or lock files. Make this the final step in any file handling code.Using append() on arrays instead of lists — Arrays have fixed size and don't support
.append(). If you need to add elements dynamically, use a list. Check whether the question specifies array or list.Incorrect loop bounds in 2D arrays — For a 2D array
grid[rows][columns], the outer loop should iterate through rows (range(len(grid))) and inner loop through columns (range(len(grid[0]))). Test with small examples first.Not converting string data from files — Data read from files is always string type. Use
int()orfloat()to convert numbers before calculations:score = int(parts[1]). Forgetting this causes type errors.Off-by-one errors in binary search — When calculating the middle position, use integer division:
mid = (low + high) // 2. Updatelowandhighcorrectly:low = mid + 1orhigh = mid - 1, never includemiditself after checking it.
Exam technique for "Programming and Data Structures"
Identify the data structure required — Questions often hint at what to use: "fixed number" suggests array, "add and remove" suggests list, "rows and columns" means 2D array. Underline these clues before writing code.
Show all steps in file handling — For file questions, always write the open, process, and close steps even if they seem obvious. Each step typically earns a separate mark. Use clear variable names like
fileordataFile.Annotate complex code with comments — In longer questions (5+ marks), add brief comments explaining key sections. This helps examiners follow your logic and may earn method marks even if code has minor errors.
Test boundary cases mentally — For search/sort algorithms, quickly check: what happens with empty list? Single element? Target not found? This helps catch logical errors before submitting.
Quick revision summary
Data structures organize program data efficiently. Arrays store fixed-size collections with zero-based indexing; lists allow dynamic resizing with methods like .append() and .pop(). Two-dimensional arrays use row and column indices for grid data. Records group related fields of different types. File handling requires opening, processing, and closing files in appropriate modes. String manipulation uses list-like operations. Linear search works on any data; binary search requires sorted data but is faster. Master when to use each structure and practice common operations.