Algorithms, program constructs and testing
Paper 2 rewards precision. This lesson covers the searches and sorts you must know, the three constructs, and how to design test data that finds bugs.
Lesson overview
What you'll learn in this lesson
Design algorithms, write programs using core constructs, and test and debug them.
Key learning points
- • Searching
- • Sorting
- • The three constructs
- • Testing and error types
This lesson at a glance
- 30 minutes
- 20 parts to scroll through
- 4 quick checks
- Marked quiz at the end
- Gentle pace: short sittings with pauses
Words to know
Scroll down — the lesson carries on below
Watch & discover
Part 1 of 20
Visual introductionPicture this
Algorithms, program constructs and testing
Paper 2 rewards precision. This lesson covers the searches and sorts you must know, the three constructs, and how to design test data that finds bugs.
In a nutshell
Design algorithms, write programs using core constructs, and test and debug them.
Learning cycle
Part 2 of 20
Learning cycle 1 of 2
Part 1 · Searching
A short piece of teaching, then a check to make sure it has landed.
Explore the idea
Part 3 of 20
Learn
Searching
A linear search checks each item in turn: it works on unsorted data and takes on average half the list. A binary search repeatedly halves a sorted list by comparing with the middle item: it is far faster on large data sets but requires the data to be sorted first.
Reset break
Part 4 of 20
Pause
That's sitting 1 of 5 done
Stretch, get a drink, look out of the window. There is no timer and nothing is counting down — your place is saved, so you can come back in five minutes or tomorrow.
Explore the idea
Part 5 of 20
Learn
Sorting
Bubble sort repeatedly swaps adjacent out-of-order items — simple but slow. Merge sort divides the list until each part holds one item, then merges pairs in order — consistently efficient. Insertion sort builds a sorted section one item at a time and is quick on nearly sorted data.
Quick check
Part 6 of 20
Quick check
Part 7 of 20
Reset break
Part 8 of 20
Pause
That's sitting 2 of 5 done
Stretch, get a drink, look out of the window. There is no timer and nothing is counting down — your place is saved, so you can come back in five minutes or tomorrow.
Learning cycle
Part 9 of 20
Learning cycle 2 of 2
Part 2 · The three constructs
A short piece of teaching, then a check to make sure it has landed.
Explore the idea
Part 10 of 20
Learn
The three constructs
Sequence runs statements in order; selection chooses a path with if, else if and else; iteration repeats with a count-controlled for loop or a condition-controlled while loop. Combine these with arrays, records, subprograms and file handling and you can write any GCSE program.
Explore the idea
Part 11 of 20
Learn
Testing and error types
Syntax errors break the rules of the language and stop the program running; logic errors run but give the wrong result. Test data must be normal, boundary and erroneous — and boundary values are where the marks and the real bugs are.
Reset break
Part 12 of 20
Pause
That's sitting 3 of 5 done
Stretch, get a drink, look out of the window. There is no timer and nothing is counting down — your place is saved, so you can come back in five minutes or tomorrow.
Quick check
Part 13 of 20
Quick check
Part 14 of 20
Explore the idea
Part 15 of 20
Worked example
Worked example: validating an age input
A program must accept an age between 11 and 18. Using a while loop, the program repeatedly asks for input while the value is outside the range, so invalid entries cannot pass. Test data should include 15 as normal data, 11 and 18 as boundary data that must be accepted, 10 and 19 as boundary data that must be rejected, and 'twelve' as erroneous data that must be handled without crashing. Testing only normal data would let an off-by-one comparison such as age > 11 pass unnoticed, which is exactly why boundary values are specified.
Reset break
Part 16 of 20
Pause
That's sitting 4 of 5 done
Stretch, get a drink, look out of the window. There is no timer and nothing is counting down — your place is saved, so you can come back in five minutes or tomorrow.
Challenge round
Part 17 of 20
Game · Sort it
Which of these are true?
Drag each card into the right column. Tap a card first if dragging is fiddly.
True
Not true
Challenge round
Part 18 of 20
Game · Recall cards
What must be true before a binary search?
Card 1 of 4
Mastery quiz
Part 19 of 20
Marked quiz
End of lesson quiz: Algorithms, program constructs and testing
4 questions, marked with the reasoning shown. No timer.
1. What must be true before a binary search?
2. Which sort is quickest on nearly sorted data?
3. Which error allows the program to run but gives a wrong answer?
4. Which test data most often exposes an off-by-one mistake?
Lesson round-up
Part 20 of 20
Lesson round-up
Ready when you are
Quiz score
Not sat
Games
Not played
Points this lesson
0
Best run
0 in a row
Luna: 0 out of 4 on the practice checks. Only if you feel up to it — one more?
Ask LunaPart 1 of 20 · Watch & discover
