A brief note on Standard Algorithms and Validation . Read it before a test. Try each question at the end before you open its answer.
The standard methods Totalling: Total ← 0 before the loop; Total ← Total + Value inside. Counting: Count ← 0 before the loop; Count ← Count + 1 inside, often inside an IF. Maximum and minimum: start with the first value (or a value beyond every possible one); replace it with any larger (or smaller) value. Average: Total / Count, once, after the loop. Searching and sorting Linear search: compare each item in turn from the first; stop at a match or at the end. It works on any list. Bubble sort: compare neighbours; swap if out of order; one pass puts the largest value at the end; repeat until a pass makes no swaps. A swap needs a temporary variable: Temp ← A, A ← B, B ← Temp. For n n n items a pass makes at most n − 1 n - 1 n − 1 comparisons. Validation (is it sensible?): range, length, type, presence, format, check digit. Verification (was it entered as intended?): visual check, double entry check. A validation loop repeats the input with a message until the data is acceptable. Practice with new numbers
A program to try The program totals six race times, counts the times under 60 60 60 seconds and finds the fastest, starting with the first value.
Read it first. Then run it. Which line would you change to find the slowest time?
1. Add a seventh time of 55. Predict the three results before you run it.
Mistakes to avoid Resetting a total or a count inside the loop. Starting a maximum at 0 0 0 when the values can be negative. A swap without Temp. Calling a double entry check validation. It is verification. Check yourself The inputs are 3 3 3 , 11 11 11 , 6 6 6 and 8 8 8 . What are the total, the count of values over 5 5 5 , and the average? Stuck? Show a hint Show the answerA list of 12 12 12 names does not contain the name you want. A linear search runs through it. How many comparisons does it make? Stuck? Show a hint Show the answerA password must have at least 10 10 10 characters. Which check is this? Stuck? Show a hint Show the answerSort 3 , 1 , 2 3, 1, 2 3 , 1 , 2 with one sweep of neighbour swaps. What do you get? Stuck? Show a hint Show the answerSources Cambridge International, IGCSE Computer Science 0478 syllabus (2026, 2027 and 2028), unit 7, parts 4 and 5.