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 |
SET count TO 3
SET result TO 1
WHILE count > 0 DO
SET result TO result * 2
SET count TO count - 1
END WHILE
SEND result TO DISPLAYSET num TO 37
SET steps TO 0
WHILE num > 1 DO
SET num TO num DIV 2
SET steps TO steps + 1
END WHILE
SEND steps TO DISPLAYRECEIVE mark FROM (INTEGER) KEYBOARD
IF mark > 50 THEN
SEND 'Pass' TO DISPLAY
ELSE
SEND 'Fail' TO DISPLAY
END IFA 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?
SET found TO FALSE
SET i TO 0
WHILE i < LENGTH(items) AND found = FALSE DO
IF items[i] = target THEN
SET found TO TRUE
ELSE
SET i TO i + 1
END IF
END WHILE
IF found = TRUE THEN
SEND i TO DISPLAY
ELSE
SEND 'Not found' TO DISPLAY
END IFfirst and last mark the part of the list still being searched.SET first TO 0
SET last TO LENGTH(items) - 1
SET found TO FALSE
WHILE first <= last AND found = FALSE DO
SET mid TO (first + last) DIV 2
IF items[mid] = target THEN
SET found TO TRUE
ELSE
IF items[mid] < target THEN
SET first TO mid + 1
ELSE
SET last TO mid - 1
END IF
END IF
END WHILE[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
SET swapped TO FALSE
FOR i FROM 0 TO 4 DO
IF items[i] > items[i + 1] THEN
SET temp TO items[i]
SET items[i] TO items[i + 1]
SET items[i + 1] TO temp
SET swapped TO TRUE
END IF
END FOR
UNTIL swapped = FALSESET items[i] TO items[i + 1]
SET items[i + 1] TO 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 Problem solving for Pearson Edexcel International GCSE Computer Science (4CP0). 🎉
Your stars: 0 / 0
Next: more International GCSE Computer Science · Edexcel lessons and games on the International GCSE Computer Science · Edexcel page.
→ Back to International GCSE Computer Science · Edexcel
Specification points and sources for this lesson are listed at the bottom of the page.
The specification points and sources behind this lesson.