Revise Computingrevisecomputing.co.uk
Free student revisionSee questionsFor schoolsSchool enquiry
Free revisionSee questionsFor schoolsSchool enquiry
Knowledge/A Level/H446/02 Algorithms and programming/Thinking ahead/Determine the preconditions for devising…

Determine the preconditions for devising a solution to a problem

Determine the preconditions for devising a solution to a problem.

2.1.2 Thinking ahead

Thinking ahead — Note 2 of 4

For a description of a program, candidates need to be able to determine what additional conditions they need to know before they can produce a solution, and how this information may affect the solution.

What you need to know

Preconditions are requirements that must be true before an algorithm or subroutine is run. Identifying them in advance avoids errors and makes code simpler and easier to reuse.

What to know

  • Example: binary search requires the list to be sorted; a function that calculates an average requires a non-empty list.
  • Preconditions can be checked inside the subroutine, or documented so that the calling code is responsible for meeting them.
  • Stating preconditions clearly makes subroutines easier to reuse, because other programmers know what the subroutine expects.
  • Thinking ahead also means identifying what extra information is needed before a solution can be produced, and how it will affect the solution.

Key terms

Exam tipCommon mistake

Precondition

A condition that must be true before a subroutine or algorithm is run for it to work correctly.

  • Exam tip: For a given scenario, state the precondition AND explain what would go wrong if it was not met.
← Previous noteIdentify the inputs and outputs for a given situation2.1.2 Thinking aheadNext note →The nature, benefits and drawbacks of caching2.1.2 Thinking ahead

Back to Thinking ahead

Thinking ahead

Note 2 of 4

  1. 1Identify the inputs and outputs for a given situation
  2. 2Determine the preconditions for devising a solution to a problem
  3. 3The nature, benefits and drawbacks of caching
  4. 4The need for reusable program components
Topic overview