Big problems become manageable when you break them into small parts. A function is a named, reusable part that takes inputs and returns a result.
🪓 Decomposition
Decomposition splits a problem into smaller sub-problems. Abstraction hides detail you do not need. Each piece becomes a function you can test on its own and reuse.
function area(w, h):
return w * h
area(4, 5) = 20
area(area(2, 3), 2) = 6 · 2 = 12
🖼️ See it
Break a large problem into small functions that each do one job. Each can be written, tested and reused on its own.
📥 Parameters, return values and scope
A parameter is a variable in the function’s definition; an argument is the value passed in. A local variable exists only inside its function, while a global variable is visible everywhere.
function double(x): return x * 2
function addTax(p): return p + p / 10
double(7) = 14
addTax(50) = 55
double(addTax(10)) = double(11) = 22
One function, one job. Short functions are easier to name, test and reuse.
✏️ Quick check · 1 of 7
Decomposition
Decomposition means:
Divide the problem.
✏️ Quick check · 2 of 7
Local variable
A local variable:
Local = inside.
✏️ Quick check · 3 of 7
Return
The return statement:
Result back.
✍️ Type your answer · 4 of 7
function area(w, h): return w * h.
What is area(4, 5)?
Enter an exact answer, without rounding.
Substitute.
✍️ Type your answer · 5 of 7
function double(x): return x * 2.
What is double(7)?
Enter an exact answer, without rounding.
Substitute.
✍️ Type your answer · 6 of 7
function addTax(p): return p + p / 10.
What is addTax(50)?
Enter an exact answer, without rounding.
Add 10%.
✍️ Type your answer · 7 of 7
Use double() and addTax() as above.
What is double(addTax(10))?
Enter an exact answer, without rounding.
Work from the inside out.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5
A parameter is:
Question 2 of 5
Why use functions?
Question 3 of 5
Abstraction means:
Question 4 of 5
Calling a function means:
Question 5 of 5
A function with no return value is often used to:
Lesson 2 · Algorithms
↕️ Sorting Algorithms
Sorted data is much easier to search. Different sorting methods trade simplicity against speed.
🫧 Bubble sort
Bubble sort compares neighbouring items and swaps them if they are in the wrong order. After each full pass the largest remaining item has “bubbled” to the end.
[5, 2, 4, 1]
pass 1: 5↔2 → [2,5,4,1]; 5↔4 → [2,4,5,1]; 5↔1 → [2,4,1,5] 3 swaps
pass 2: 4↔1 → [2,1,4,5] 1 swap
pass 3: 2↔1 → [1,2,4,5] 1 swap
n items: at most n − 1 passes, n(n−1)/2 comparisons
4 items → 6 comparisons in the worst case
🖼️ See it
Each pass swaps neighbours that are out of order, so the largest value “bubbles” to the end.
✋ Insertion and merge sort
Insertion sort takes each item and slides it into its place in the sorted part. Merge sort splits the list in halves, sorts each and merges them, which is much faster for big lists.
merge [3,1] and [4,2] (each sorted first)
[1,3] and [2,4] → [1,2,3,4]
merge sort of 8 items splits log₂ 8 = 3 times
Simple is not always slow: bubble sort is fine for a handful of items, but it grows badly for large lists.
✏️ Quick check · 1 of 7
Bubble sort
In bubble sort, after the first complete pass the:
Bubbles rise.
✏️ Quick check · 2 of 7
Merge sort
Merge sort works by:
Divide and conquer.
✍️ Type your answer · 3 of 7
Bubble sort on [5, 2, 4, 1]. In pass 1, 5 is compared with 2, 4 and 1 and swapped each time.
How many swaps happen in pass 1?
Enter an exact answer, without rounding.
Trace the pass.
✍️ Type your answer · 4 of 7
After pass 1 the list is [2, 4, 1, 5]. Pass 2 only needs to compare the first 3 items.
How many swaps happen in pass 2?
Enter an exact answer, without rounding.
Trace again.
✍️ Type your answer · 5 of 7
A bubble sort compares n(n − 1)/2 pairs in the worst case.
How many comparisons for 10 items?
Enter an exact answer, without rounding.
Use the formula.
✍️ Type your answer · 6 of 7
Merge sort splits a list of 8 items into halves repeatedly until each part has 1 item.
How many times can it halve (log₂ 8)?
Enter an exact answer, without rounding.
Keep halving.
✍️ Type your answer · 7 of 7
The two sorted lists [1, 3] and [2, 4] are merged.
What is the third item in the merged list?
Enter an exact answer, without rounding.
Take the smaller front item each time.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5
Which sort is usually fastest on a large list?
Question 2 of 5
A swap means:
Question 3 of 5
An already sorted list is sorted by bubble sort (with an early exit) in:
Question 4 of 5
Sorting a list makes which operation faster?
Question 5 of 5
Insertion sort is like:
Lesson 3 · Hardware
⚙️ Boolean Logic & Gates
All digital hardware is built from logic gates that combine on/off signals. Truth tables list every possible input.
🚪 The basic gates
AND outputs 1 only if both inputs are 1. OR outputs 1 if at least one input is 1. NOT flips its input. XOR outputs 1 if the inputs differ.
A B | AND OR XOR
0 0 | 0 0 0
0 1 | 0 1 1
1 0 | 0 1 1
1 1 | 1 1 0
NOT 1 = 0
🖼️ See it
AND needs both inputs on; OR needs at least one; XOR needs exactly one.
🧱 Combining gates
Gates can be combined into circuits. With n inputs a truth table has 2ⁿ rows.
Q = (A AND B) OR NOT C
A=1, B=1, C=1: 1 OR 0 = 1
A=0, B=1, C=1: 0 OR 0 = 0
3 inputs → 2³ = 8 rows
NAND = NOT(AND): 1 NAND 1 = 0
NAND gates are universal: any circuit can be built from NAND gates alone.
✏️ Quick check · 1 of 7
XOR
XOR outputs 1 when:
Different.
✏️ Quick check · 2 of 7
AND gate
An AND gate outputs 1 only when:
Both.
✍️ Type your answer · 3 of 7
A = 1, B = 1 and the gate is AND.
What is the output (0 or 1)?
Enter an exact answer, without rounding.
Check both.
✍️ Type your answer · 4 of 7
A = 1, B = 0 and the gate is OR.
What is the output?
Enter an exact answer, without rounding.
Any 1.
✍️ Type your answer · 5 of 7
A = 1, B = 1 and the gate is XOR.
What is the output?
Enter an exact answer, without rounding.
Same inputs give 0.
✍️ Type your answer · 6 of 7
Q = (A AND B) OR NOT C with A = 0, B = 1 and C = 1.
What is Q?
Enter an exact answer, without rounding.
Work part by part.
✍️ Type your answer · 7 of 7
A circuit has 3 inputs.
How many rows does its truth table have?
Enter an exact answer, without rounding.
2 to the power of inputs.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5
NOT 0 equals:
Question 2 of 5
Which gate outputs 1 unless both inputs are 1?
Question 3 of 5
A truth table shows:
Question 4 of 5
Which gate corresponds to “either or both”?
Question 5 of 5
Logic gates are made from:
Lesson 4 · Data
🗜️ Compression & Storage
Compression makes files smaller so they store and travel faster. Some methods lose nothing, while others discard detail you will not miss.
📉 Lossless and lossy
Lossless compression (ZIP, PNG) can rebuild the original exactly. Lossy compression (JPEG, MP3) throws away detail people are unlikely to notice for a much smaller file.
Compression saves storage and download time by removing repetition (lossless) or detail people barely notice (lossy).Each unit is 1 000 times the one before (some systems use 1 024).
📀 File sizes
Uncompressed image size = width × height × colour depth (bits). Divide by 8 for bytes.
Lossy files cannot be restored to the original. Keep a lossless master copy.
✏️ Quick check · 1 of 7
Lossless
Which format is lossless?
No detail lost.
✏️ Quick check · 2 of 7
Lossy
Lossy compression:
Loses data.
✍️ Type your answer · 3 of 7
Compress AAAAABBBCC with run-length encoding to 5A3B2C.
How many characters is the compressed form?
Enter an exact answer, without rounding.
Count them.
✍️ Type your answer · 4 of 7
An image is 100 × 100 pixels with 24 bits per pixel.
How many bytes is it uncompressed?
Enter an exact answer, without rounding.
Pixels × bits ÷ 8.
✍️ Type your answer · 5 of 7
RLE: decode 3X2Y.
How many characters are in the decoded text?
Enter an exact answer, without rounding.
Add the counts.
✍️ Type your answer · 6 of 7
A sound lasts 2 s with 44 100 samples/s and 16 bits per sample (mono).
How many bytes is it?
Enter an exact answer, without rounding.
Samples × bits ÷ 8.
✍️ Type your answer · 7 of 7
A file is 30 MB and is compressed to 6 MB.
What is the compression ratio?
Enter an exact answer, without rounding.
Original ÷ compressed.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5
Compression is used so files:
Question 2 of 5
JPEG is mainly used for:
Question 3 of 5
RLE works best on:
Question 4 of 5
A higher bit depth gives:
Question 5 of 5
Which is the best choice for a legal document archive?
Lesson 5 · Data
🗄️ Databases & SQL
Databases store large amounts of structured data so it can be searched quickly. SQL is the language used to ask questions of them.
📋 Tables, records and fields
A table holds records (rows) made of fields (columns). A primary key uniquely identifies each record.
students
id name year mark
1 Aisha 9 72
2 Ben 9 55
3 Chen 10 88
4 Dara 9 91
4 records, 4 fields, primary key = id
🖼️ See it
SELECT name FROM students WHERE grade = 9; returns Amy and Cara. Each row is a record and each column a field.
🔎 SQL queries
SELECT chooses fields, FROM names the table, WHERE filters rows, ORDER BY sorts and COUNT counts.
SELECT name FROM students WHERE year = 9
→ Aisha, Ben, Dara (3 rows)
SELECT name FROM students WHERE mark > 70
→ Aisha, Chen, Dara (3 rows)
SELECT COUNT(*) FROM students WHERE year = 9 AND mark >= 70
→ 2
SELECT AVG(mark) FROM students → (72+55+88+91)/4 = 76.5
Always use WHERE with UPDATE and DELETE, or they affect every row.
✏️ Quick check · 1 of 7
Primary key
A primary key is a field that:
Unique.
✏️ Quick check · 2 of 7
SELECT
The SQL keyword to choose which fields to show is:
Choose.
✍️ Type your answer · 3 of 7
The students table has 4 records. SELECT name FROM students WHERE year = 9.
How many rows are returned?
Enter an exact answer, without rounding.
Count year 9 rows.
✍️ Type your answer · 4 of 7
SELECT name FROM students WHERE mark > 70.
How many rows are returned?
Enter an exact answer, without rounding.
Only marks above 70.
✍️ Type your answer · 5 of 7
SELECT COUNT(*) FROM students WHERE year = 9 AND mark >= 70.
What is the result?
Enter an exact answer, without rounding.
Both conditions must hold.
✍️ Type your answer · 6 of 7
SELECT AVG(mark) FROM students.
What is the average, as a decimal?
Enter an exact answer, without rounding.
Sum ÷ count.
✍️ Type your answer · 7 of 7
A table has 5 fields and 20 records.
How many data values are stored in total?
Enter an exact answer, without rounding.
Fields × records.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5
A row in a table is called a:
Question 2 of 5
Which clause filters rows?
Question 3 of 5
Which SQL sorts results from largest to smallest mark?
Question 4 of 5
Why use a database instead of a text file?
Question 5 of 5
Storing a date of birth in a field called dob is an example of:
Lesson 6 · Security
🔐 Encryption & Cybersecurity
Encryption scrambles data so only the right people can read it. Understanding simple ciphers explains the ideas behind modern security.
🏛️ Caesar cipher
A Caesar cipher shifts each letter a fixed number of places along the alphabet. It is easy to break because there are only 25 shifts and letter frequencies give it away.
shift 3: A→D B→E C→F … X→A Y→B Z→C
HELLO → KHOOR
shift 1: C → D
shift 5: Y → D (Y,Z,A,B,C,D)
only 25 possible keys → can be brute-forced
🖼️ See it
Only someone who knows the key can turn the ciphertext back into the message. Modern encryption works the same way with far harder keys.
🛡️ Threats and defences
Common threats are malware, phishing, brute-force attacks and social engineering. Defences include strong passwords, two-factor authentication, updates, firewalls and backups.
password of 6 lowercase letters: 26⁶ = 308 915 776
add 10 digits and 26 capitals (62 symbols): 62⁶ ≈ 56.8 billion
2FA: password + code on your phone
Hashing stores a fingerprint of a password rather than the password itself.
✏️ Quick check · 1 of 7
Symmetric
In symmetric encryption:
Same.
✏️ Quick check · 2 of 7
2FA
Two-factor authentication is:
Two different ways.
✏️ Quick check · 3 of 7
Social engineering
Social engineering attacks:
People.
✍️ Type your answer · 4 of 7
A Caesar cipher uses a shift of 1.
What does the letter C become? (Give its position in the alphabet: A = 1.)
Enter an exact answer, without rounding.
Shift one place on.
✍️ Type your answer · 5 of 7
A Caesar cipher uses a shift of 3.
What position does the letter Z (position 26) become? (A = 1)
Enter an exact answer, without rounding.
Wrap around the alphabet.
✍️ Type your answer · 6 of 7
A PIN uses 5 digits from 0 to 9.
How many different PINs are possible?
Enter an exact answer, without rounding.
10 choices for each digit.
✍️ Type your answer · 7 of 7
A Caesar cipher has how many useful shifts (not 0 and not 26)?
Give the number.
Enter an exact answer, without rounding.
Count the shifts.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5
Why is a Caesar cipher weak?
Question 2 of 5
Malware is:
Question 3 of 5
A brute-force attack:
Question 4 of 5
Storing hashed passwords is better than plain text because:
Question 5 of 5
Keeping software up to date helps because:
Final Challenge
🏆 12-Question Challenge Quiz
Questions from every topic in this course. Pick an answer for each one, then hit Check My Answers.
0 / 12
💪 Keep practicing — go back through the lessons and retake the quiz!
Q1 · Functions & Decomposition
An argument is:
Q2 · Functions & Decomposition
A function with no return value is often used to:
Q3 · Sorting Algorithms
The first step of bubble sort is to compare:
Q4 · Sorting Algorithms
Insertion sort is like:
Q5 · Boolean Logic & Gates
What is 1 AND 0?
Q6 · Boolean Logic & Gates
Logic gates are made from:
Q7 · Compression & Storage
Which method rebuilds the original exactly?
Q8 · Compression & Storage
Which is the best choice for a legal document archive?
Q9 · Databases & SQL
SELECT * FROM students returns:
Q10 · Databases & SQL
Storing a date of birth in a field called dob is an example of: