Learning Objectives
  • Develop complete algorithms from problem statements.
  • Choose an appropriate representation: pseudocode, flowchart or program code.
  • Combine validation, standard methods and required outputs.
  • Amend an existing algorithm while preserving correct behaviour.
Key Terms
Scenario
A contextual problem statement containing requirements for a solution.
Algorithm design
The process of planning a finite set of steps that meets stated requirements.
Amend
Change an existing algorithm to meet a new or corrected requirement.
Precondition
A condition expected to be true before a process begins.
Postcondition
A condition or result expected after a process finishes.
Completeness
The property that every required case and output has been handled.
Summary diagram
Summary Of The Main Ideas In This Lesson
From Scenario To Algorithm

Begin by extracting requirements, inputs, processes, outputs and storage. Apply abstraction so irrelevant story detail does not enter the design. Decompose a large task into sections before writing detailed steps.

Choose a representation that matches the question. Pseudocode is suitable for detailed logic, a flowchart is useful for visible decision paths and a structure diagram shows the overall decomposition. If program code is requested, only the permitted language or Cambridge pseudocode should be used in the examination.

Building A Complete Solution

Initialise working variables, obtain input, validate where required, perform calculations or standard methods and produce every required output. Consider normal and invalid paths.

Loops need a starting state, a condition and progress toward an exit. Selections need conditions that are mutually clear and cover all required cases. Stored results must be updated at the correct time.

Using Standard Methods

Do not reinvent a search or sort when the scenario clearly requires a standard method. Use the linear-search pattern for sequential matching and bubble-sort pattern for adjacent comparison and swapping.

Totals, counts, maximum, minimum and average can be combined, but each variable must have correct initialisation and update conditions.

Amending Existing Algorithms

An amendment may add a new validation rule, change a boundary, include another output or alter the calculation. First understand the current purpose and identify where the requirement should affect the flow.

Make the smallest coherent change. Adding a discount output may also require a new input, calculation and test. A change in one place can therefore require connected changes elsewhere.

Self-Checking Checklist
Question Check
Does the algorithm meet every requirement? Match each requirement to one or more statements
Are all inputs obtained before use? Trace data dependencies
Are working variables initialised? Check totals, counters, flags, maxima and minima
Can every loop terminate? Check update and exit condition
Are all branches covered? Test true, false and boundary cases
Are outputs produced in the correct place? Check inside versus after loops
Has invalid input been handled? Apply required validation and error messages
Scenario-Based Examination Questions

Paper 2 includes a scenario-based question based on methods and concepts from Topics 7 to 10. Topic 7 skills are central: understanding requirements, designing algorithms, amending logic, choosing test data and tracing results.

Plan before writing. Short annotations or a compact decomposition can prevent missing requirements. After writing, dry-run at least one normal case and one boundary or abnormal case when time permits.

Keeping Within The Syllabus

Algorithms in this volume use the required standard methods and Cambridge-style representations. Full treatment of data types, arrays, procedures, functions, string operations and file handling belongs to Volume 8, although a Topic 7 question may show such constructs in a given algorithm.

The aim here is to solve and check problems, not to memorise code without understanding.

Worked Examples
Competition Scores

Question: Design an algorithm to input ten scores from 0 to 50, reject invalid scores, output the total, average and highest score.

  1. Initialise Total to 0.
  2. For each of ten scores, repeat input until 0 <= Score <= 50.
  3. For the first valid score, set Highest to Score.
  4. Add Score to Total and update Highest when Score is greater.
  5. After all inputs, calculate Average ← Total / 10.
  6. Output Total, Average and Highest.

Answer: The solution combines validation, totalling, maximum and average while preserving correct initialisation.

Amending A Search

Question: A linear search currently reports only Found/Not Found. Amend it to output the first matching position.

  1. Add a Position variable that starts at the first index.
  2. Keep Position updated as the search moves through the list.
  3. Stop at the first match.
  4. When Found is TRUE, output Position; otherwise output Not Found.

Answer: The amendment adds a position result without changing the fundamental sequential search method.

Examination Guidance
  • Underline or list requirements before writing the algorithm.
  • Use the representation requested by the question.
  • Initialise all working variables and handle every required output.
  • Dry-run normal and boundary data to find missing cases.
  • When amending, preserve existing correct behaviour and update connected logic.
Common Mistakes
  • Starting to code before identifying all requirements.
  • Writing only the successful path and ignoring invalid input.
  • Using an unsafe initial value for maximum or minimum.
  • Creating a loop with no progress toward termination.
  • Adding an output without adding the calculation that supplies it.
Knowledge Check

1. What should be done before writing a scenario algorithm?

Answer: Analyse requirements, identify IPO and storage, and decompose the problem.

2. How should a representation be chosen?

Answer: Use the method requested or the one that best communicates the required aspect of the design.

3. What does completeness mean?

Answer: Every required case, process and output has been handled.

4. Why make the smallest coherent amendment?

Answer: It reduces the risk of damaging correct parts while still meeting the new requirement.

5. How can an algorithm be checked quickly?

Answer: Dry-run it with normal and boundary or abnormal data.