A-Level Computer Science: Practical Topics Study
Guide (with Python code)
This guide summarizes the main practical programming topics for A-Level Computer Science (9618-style),
with clear explanations, example Python code, and short pseudocode where helpful. Use this as a revision
and practical reference. Each section includes: concept summary, key points, example code, and notes for
exam-style questions.
Arrays & 2D Arrays
Arrays are fixed-size collections indexed by integers. 2D arrays (lists of lists) model tables or grids.
Example Code:
# Example: initialise and print a 2D array (10x10) with random integers import random array
= [[[Link](0,100) for _ in range(10)] for _ in range(10)] for row in array: print('
'.join(str(x) for x in row))
Stacks (LIFO)
Stacks store elements last-in first-out. Key operations: Push, Pop, Peek, IsEmpty. Use arrays with a
pointer for A-level.
Example Code:
# Example: simple stack using a list and pointer Stack = [0]*10 SP = 0 # stack pointer def
Push(val): global SP if SP == len(Stack): return False Stack[SP] = val SP += 1 return True
def Pop(): global SP if SP == 0: return None SP -= 1 return Stack[SP]
Queues (Linear & Circular)
Queues are FIFO. Linear queue may have wasted space; circular queue wraps head/tail indices.
Example Code:
# Example: circular queue of size 5 Queue = [None]*5 Head = 0 Tail = 0 Count = 0 def
Enqueue(x): global Tail, Count if Count == len(Queue): return False Queue[Tail] = x Tail =
(Tail + 1) % len(Queue) Count += 1 return True def Dequeue(): global Head, Count if Count
== 0: return None val = Queue[Head] Head = (Head + 1) % len(Queue) Count -= 1 return val
Linked Lists (Singly)
Linked lists store nodes with data and a pointer to next node. Good for dynamic insert/delete.
Example Code:
# Example: simple linked list node class and append class Node: def __init__(self, data):
[Link] = data [Link] = None head = None def append(val): global head if not head:
head = Node(val) return cur = head while [Link]: cur = [Link] [Link] = Node(val)
Binary Trees & BSTs
Binary Search Trees keep left < parent < right. Key ops: insertion, search, traversals (inorder, preorder,
postorder).
Example Code:
# Example: BST insertion and inorder traversal class Node: def __init__(self, val):
[Link] = val [Link] = None [Link] = None def insert(root, val): if root is None:
return Node(val) if val < [Link]: [Link] = insert([Link], val) else: [Link] =
insert([Link], val) return root def inorder(root): if root: inorder([Link])
print([Link]) inorder([Link])
Recursion vs Iteration
Recursion is when a function calls itself with a base case. Iteration uses loops. Convert between them for
A-level questions.
Example Code:
# Recursive factorial vs iterative def fact_rec(n): if n <= 1: return 1 return n *
fact_rec(n-1) def fact_iter(n): res = 1 for i in range(2, n+1): res *= i return res
File Handling (Text Files)
Reading and writing text files is essential. Use try/except for robustness. Read line by line and parse data
types.
Example Code:
# Example: read pairs of lines (name, score) data = [] with open('[Link]','r') as f:
while True: name = [Link]().strip() if not name: break score =
int([Link]().strip()) [Link]((name, score))
Sorting Algorithms
Understand bubble sort, insertion sort, and one efficient sort (merge or quick). Know time complexities and
write pseudocode.
Example Code:
# Bubble sort example (ascending) def bubble_sort(a): n = len(a) for i in range(n-1): for j
in range(n-1-i): if a[j] > a[j+1]: a[j], a[j+1] = a[j+1], a[j]
Searching Algorithms
Linear search scans sequentially; binary search requires sorted data and halves the search range (log n).
Example Code:
# Binary search (iterative) on sorted list def binary_search(a, target): low, high = 0,
len(a)-1 while low <= high: mid = (low + high)//2 if a[mid] == target: return mid elif
a[mid] < target: low = mid+1 else: high = mid-1 return -1
Object-Oriented Programming (OOP)
Classes, constructors, attributes, methods, inheritance, encapsulation. Use getters/setters for A-level
clarity.
Example Code:
# Example: Employee/Manager class Employee: def __init__(self, id, pay): [Link] = id
[Link] = pay def total_pay(self, hours): return [Link] * hours class
Manager(Employee): def __init__(self, id, pay, bonus_pct): super().__init__(id, pay)
[Link] = bonus_pct def total_pay(self, hours): return super().total_pay(hours) * (1 +
[Link]/100)
Hashing (Basic concepts)
Hash tables map keys to buckets via hash functions. Understand collisions and simple resolution
techniques (chaining).
Example Code:
# Simple chaining hash table using Python dict (conceptual) table = {} def put(key, value):
h = hash(key) % 10 if h not in table: table[h] = [] table[h].append((key, value))
Pseudocode & Exam Techniques
Write clear pseudocode using FUNCTION/PROCEDURE, arrays, loops, and indentation. Explain edge
cases and complexity.
Example Code:
# Pseudocode style example (insertion sort) PROCEDURE InsertionSort(A, n) FOR i = 1 TO n-1
key = A[i] j = i - 1 WHILE j >= 0 AND A[j] > key A[j+1] = A[j] j = j - 1 END WHILE A[j+1] =
key END FOR END PROCEDURE