← Back to CS Hub
Topic 1 — Paper 1

Computational Thinking

Algorithms, decomposition, abstraction, searching & sorting — master the foundations of computer science.

0
Activities
0
Correct
0
Streak

πŸ“– Core Theory

Key definitions, concepts, and terminology for Topic 1

πŸ”‘
Key Definitions
Algorithm
A step-by-step set of instructions used to solve a problem or complete a task. Must be unambiguous and produce a result in a finite number of steps.
Decomposition
Breaking a complex problem down into smaller, more manageable sub-problems that are easier to solve individually.
Abstraction
Removing unnecessary detail from a problem to focus on the important information needed to solve it.
Sequence
Instructions executed one after another in order, from top to bottom.
Selection
A decision point in a program where different paths are taken depending on whether a condition is true or false (e.g., IF...ELSE).
Iteration
Repeating a set of instructions either a fixed number of times (count-controlled) or until a condition is met (condition-controlled).
🌍
Real-World Examples & Analogies
Algorithm β€” Making a Cup of Tea β˜• β–Ό

A recipe is a perfect everyday example of an algorithm. Consider making a cup of tea:

  1. Fill the kettle with water
  2. Turn the kettle on
  3. Wait for the water to boil
  4. Put a teabag in a mug
  5. Pour boiling water into the mug
  6. Wait 3 minutes
  7. Remove the teabag
  8. Add milk (optional)

Every step is clear, unambiguous, and the process finishes β€” all the properties of a good algorithm. Notice it also includes sequence (steps in order), selection (optional milk), and iteration (you could say "stir 5 times").

Decomposition β€” Planning a School Trip 🚌 β–Ό

Analogy: Imagine you need to organise a school trip. That's a huge task! Decomposition means breaking it into sub-problems:

  • Transport β€” book a coach, plan the route
  • Permissions β€” send consent forms, collect replies
  • Activities β€” plan the schedule, book tickets
  • Safety β€” risk assessment, first aid kit, staff ratios
  • Budget β€” calculate costs, collect payments

Each sub-problem is now small enough to give to a different person. This is exactly how software developers work β€” they decompose a big program into modules that different team members build independently.

Abstraction β€” The London Underground Map πŸ—ΊοΈ β–Ό

The London Underground map is a famous example of abstraction. The real Tube tunnels twist, turn, and vary in depth underground. But Harry Beck's map removes all that unnecessary detail and shows only what matters: which stations exist and how they connect.

Exam Tip

In the exam, abstraction = removing unnecessary detail. If they ask "What is being abstracted away?", identify what's been left OUT (e.g., real distances, geography). If they ask "What is being kept?", identify what's essential (e.g., station names, connections).

More examples of abstraction:

  • A car dashboard shows speed and fuel β€” you don't need to see every engine component
  • A weather forecast shows temperature and rain chance β€” not atmospheric pressure equations
  • A variable name like playerScore abstracts away the memory address where the data is stored
Sequence, Selection & Iteration β€” Everyday Examples πŸ”„ β–Ό

Sequence is everywhere β€” brushing your teeth (wet brush β†’ apply toothpaste β†’ brush β†’ rinse). The order matters!

Selection is every decision you make: "IF it's raining THEN take an umbrella ELSE wear sunglasses." In Python:

if temperature < 15:
    print("Wear a coat")
else:
    print("T-shirt weather!")

Iteration is any repetition. A count-controlled loop is like doing 20 press-ups (you know in advance how many). A condition-controlled loop is like stirring soup until it boils (you don't know when it will happen).

# Count-controlled (FOR)
for i in range(20):
    print("Press-up", i + 1)

# Condition-controlled (WHILE)
while soup_temp < 100:
    stir()
πŸ“Š
Flowchart Symbols
β¬­ Terminal (Oval)
Marks the START or STOP of a flowchart.
β–­ Process (Rectangle)
An instruction or action to be carried out, e.g., total = total + 1.
β—‡ Decision (Diamond)
A yes/no question that determines which path to follow (selection).
β–± Input/Output (Parallelogram)
Data entering (INPUT) or leaving (OUTPUT) the system.
Key Point

Flowcharts use arrows to show the flow of control. Decision diamonds always have two exits labelled Yes and No.

πŸ”
Searching Algorithms
Linear Search β–Ό

How it works: Start at the first item. Check each item one by one. If found, return its position. If the end is reached without finding it, the item is not in the list.

Key Point

Works on both sorted and unsorted lists. Simple but slow for large datasets — worst case checks every item (O(n)).

Analogy: Linear search is like looking for a specific book on an unsorted bookshelf β€” you start at one end and check each book until you find it. If it's the last book, you've checked every single one.

Walkthrough: Searching for 42 in [10, 23, 42, 7, 15]:

  1. Check index 0: 10 β‰  42 β†’ move on
  2. Check index 1: 23 β‰  42 β†’ move on
  3. Check index 2: 42 = 42 β†’ Found at index 2!

Only 3 comparisons needed here (best case = 1, worst case = all items).

Binary Search β–Ό

How it works: The list must be sorted. Find the middle item. If it matches, return its position. If the target is smaller, discard the right half. If larger, discard the left half. Repeat until found or the list is empty.

Key Point

Much faster than linear search for large datasets — halves the search space each time (O(log n)). But the data must be sorted first.

Analogy: Binary search is like looking up a word in a dictionary. You don't start at page 1 β€” you open to the middle. If your word comes before that page alphabetically, you look in the first half. If after, the second half. Each time you halve the pages to search.

Walkthrough: Searching for 31 in [3, 7, 11, 15, 23, 31, 42]:

  1. low=0, high=6, mid=3 β†’ list[3]=15 β†’ 31 > 15 β†’ search right half
  2. low=4, high=6, mid=5 β†’ list[5]=31 β†’ Found at index 5!

Only 2 comparisons! A linear search would have needed 6. For 1 million items, binary search needs at most 20 comparisons vs 1,000,000 for linear.

πŸ“‹
Sorting Algorithms
Bubble Sort β–Ό

How it works: Compare adjacent pairs. If they are in the wrong order, swap them. Repeat passes through the list until no swaps are needed.

Key Point

Simple to understand and implement. Inefficient for large lists (O(n²)). Good at detecting an already-sorted list (best case O(n)).

Analogy: Imagine bubbles rising in a fizzy drink β€” the largest values "bubble up" to the end of the list with each pass.

Walkthrough: Sorting [5, 3, 8, 1]:

Pass 1: [5,3,8,1] β†’ swap β†’ [3,5,8,1] β†’ ok β†’ [3,5,8,1] β†’ swap β†’ [3,5,1,8]
Pass 2: [3,5,1,8] β†’ ok β†’ [3,5,1,8] β†’ swap β†’ [3,1,5,8]
Pass 3: [3,1,5,8] β†’ swap β†’ [1,3,5,8]
βœ“ Sorted!

Merge Sort β–Ό

How it works: Divide the list in half repeatedly until each sub-list has one item. Then merge the sub-lists back together in order.

Key Point

Much faster than bubble sort for large datasets (O(n log n)). Uses more memory because it creates new sub-lists. A divide-and-conquer algorithm.

Analogy: Imagine sorting a deck of cards by splitting the deck in half again and again until you have single cards, then merging them back in order β€” like a tournament bracket in reverse.

Walkthrough: Sorting [6, 3, 8, 2]:

Split: [6,3,8,2] β†’ [6,3] and [8,2]
Split: [6,3] β†’ [6] and [3]  |  [8,2] β†’ [8] and [2]
Merge: [6]+[3] β†’ [3,6]  |  [8]+[2] β†’ [2,8]
Merge: [3,6]+[2,8] β†’ [2,3,6,8] βœ“

Exam Comparison

Bubble sort is simple but slow (O(nΒ²)), uses no extra memory. Merge sort is fast (O(n log n)) but uses extra memory for sub-lists. Examiners love asking you to compare them.

Insertion Sort β–Ό

How it works: Take each item from the unsorted part and insert it into the correct position in the sorted part. Like sorting playing cards in your hand.

Key Point

Efficient for small or nearly-sorted lists. Works in-place (doesn’t need extra memory). Worst case is O(n²).

Analogy: This is exactly how you sort playing cards in your hand. You pick up one card at a time and slide it into the right position among the cards you're already holding.

Walkthrough: Sorting [5, 2, 8, 1]:

Start: [5] | 2, 8, 1  (5 is the sorted part)
Take 2: insert before 5 β†’ [2, 5] | 8, 1
Take 8: insert after 5 β†’ [2, 5, 8] | 1
Take 1: insert before 2 β†’ [1, 2, 5, 8] βœ“

✏️
Pseudocode Conventions
Variables
Use meaningful names. Assign with ← or = (e.g., total ← 0).
Selection
IF condition THEN ... ELSE ... ENDIF
Count-controlled loop
FOR i ← 1 TO n ... NEXT i
Condition-controlled loop
WHILE condition DO ... ENDWHILE
πŸ“
Worked Example: Putting It All Together

Problem: A teacher wants a program to calculate and display the average score from a class of 30 students. Let's apply computational thinking:

Step 1: Decomposition β–Ό

Break the problem into sub-problems:

  • Get each student's score (input)
  • Add up all the scores (processing)
  • Divide total by 30 to get average (processing)
  • Display the result (output)
Step 2: Abstraction β–Ό

What do we need? Student scores and the count (30). What do we ignore? Student names, subjects, dates β€” they're not needed for calculating an average.

Step 3: Algorithm (Pseudocode) β–Ό
total ← 0
FOR i ← 1 TO 30
    INPUT score
    total ← total + score
NEXT i
average ← total / 30
OUTPUT "The average score is: " + average

This uses sequence (steps run in order), iteration (FOR loop repeats 30 times), and variables (total, score, average). Selection isn't needed here, but we could add it: IF average >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail"

Step 4: Python Code β–Ό
total = 0
for i in range(30):
    score = int(input("Enter score: "))
    total = total + score
average = total / 30
print("The average score is:", average)

πŸ” Explore & Visualise

Step through algorithms and see how they work

πŸ“‹
Trace Table — Linear Search

Searching for 7 in the list: [3, 8, 1, 7, 5, 2]

Stepindexlist[index]Found?
πŸ“‹
Trace Table — Binary Search

Searching for 23 in the sorted list: [3, 7, 11, 15, 23, 31, 42]

Steplowhighmidlist[mid]Action
πŸ“Š
Sorting Visualiser

πŸ“Š
Flowchart Reader

Follow this flowchart and predict the output. What value does it print?

START
count ← 0
num ← 1
num ≤ 5?
↓ Yes
count ← count + num
num ← num + 1
↑ (loop back to decision)
No ↓
OUTPUT count
STOP

🧩 Guided Practice

Apply your knowledge with hints available

πŸ“‚
Categorise: Sequence, Selection, or Iteration

Drag each item into the correct category.

Items to sort:

πŸ”’
Order the Steps: Binary Search

Drag the steps into the correct order.

Available Steps

Correct Order

✏️
Fill in the Blanks: Pseudocode

Complete this linear search algorithm. Click the hint button if you get stuck.

🧠 Retrieval Practice

Test your memory by matching terms with definitions

πŸƒ
Memory Match

Find all 8 matching pairs. Click two cards to flip them.

πŸ“ Exam Practice

Build answers using sentence banks, then reveal the mark scheme

⚑ Challenge

No hints, no help — prove your mastery

Time Remaining:
5:00

πŸ“Š Performance Review

See how you performed across each sub-topic

Overall Performance

0%

Complete activities to see your results