5 missions. Guess, learn, then check. Your place is saved.
The specification points and sources are listed under the lesson: see Sources.
Make a guess: Why does the Tube map ignore real distances, yet still work?
Beck's map is an abstraction. It removes detail a traveller does not need (true distances, tunnel shapes) and keeps what they do need (the lines, the order of stations and where to change), so planning a journey splits into simple sub-problems: which line, where to change, where to get off.
Make a guess: How can you find a bug without running the program?
| Symbol | Meaning |
|---|---|
| Rounded rectangle (terminator) | Start or Stop |
| Parallelogram | Input or output |
| Rectangle | Process, such as a calculation |
| Diamond | Decision: two exits, Yes/No or True/False |
| Rectangle with double sides | Subroutine (a separate sub-program) |
| Arrow (flow line) | The direction control flows |
count ← 3
result ← 1
WHILE count > 0
result ← result * 2
count ← count - 1
ENDWHILE
OUTPUT resultnum ← 37
steps ← 0
WHILE num > 1
num ← num DIV 2
steps ← steps + 1
ENDWHILE
OUTPUT stepsmark ← STRING_TO_INT(USERINPUT)
IF mark > 50 THEN
OUTPUT 'Pass'
ELSE
OUTPUT 'Fail'
ENDIFA dry run follows the algorithm by hand, recording every variable and output in a trace table. Where a value or output differs from what it should be, you have found the logic error and its line, without running anything.
Make a guess: How can 20 checks find one name among a million?
found ← False
i ← 0
WHILE i < LEN(items) AND found = False
IF items[i] = target THEN
found ← True
ELSE
i ← i + 1
ENDIF
ENDWHILE
IF found = True THEN
OUTPUT i
ELSE
OUTPUT 'Not found'
ENDIFfirst and last mark the part of the list still being searched.first ← 0
last ← LEN(items) - 1
found ← False
WHILE first ≤ last AND found = False
mid ← (first + last) DIV 2
IF items[mid] = target THEN
found ← True
ELSE IF items[mid] < target THEN
first ← mid + 1
ELSE
last ← mid - 1
ENDIF
ENDWHILE[3, 8, 11, 15, 19, 24, 27, 31, 36, 40, 44, 52, 58, 63, 70]
| Linear search | Binary search | |
|---|---|---|
| Data must be sorted? | No | Yes |
| Most checks for 15 items | 15 | 4 |
| Most checks for 1,000 items | 1,000 | 10 |
| Code | Simpler | More complex |
A binary search on the sorted names checks the middle one and discards half of the list each time. Twenty halvings are enough, because 2^20 = 1,048,576 is more than 1,000,000. A linear search might need all 1,000,000 checks.
Make a guess: Why is it called a bubble sort?
REPEAT
swapped ← False
FOR i ← 0 TO 4
IF items[i] > items[i + 1] THEN
temp ← items[i]
items[i] ← items[i + 1]
items[i + 1] ← temp
swapped ← True
ENDIF
ENDFOR
UNTIL swapped = Falseitems[i] ← items[i + 1]
items[i + 1] ← items[i]In each pass, swaps carry the largest unsorted item along the list until it reaches its place at the end, like a bubble rising to the top of a drink. Each pass bubbles one more item into place, and a pass with no swaps shows the list is sorted.
Make a guess: Why does a fast sort start by chopping a list into pieces?
| Bubble sort | Merge sort | |
|---|---|---|
| Large lists | Slow: hundreds of thousands of comparisons for 1,000 items | Fast: under 9,000 comparisons for 1,000 items |
| Memory | Sorts in place, little extra memory | Needs extra memory for the split lists |
| Code | Simple | More complex |
| Nearly sorted list | Quick if only a few items are out of place | Still splits and merges everything |
Merge sort splits a list until every piece holds one item, and a single item is already sorted. Merging two sorted lists takes at most one comparison per item placed, so 1,000 items need under 9,000 comparisons, where a bubble sort can need hundreds of thousands.
You've worked through Fundamentals of algorithms for AQA GCSE Computer Science (8525). 🎉
Your stars: 0 / 0
Next: test yourself in the Verify stage.
→ Back to GCSE Computer Science · AQA
Specification points and sources for this lesson are listed at the bottom of the page.
The specification points and sources behind this lesson.