A-level Computer Science revision · Computational thinking

Thinking ahead: inputs, outputs and preconditions

The idea

Thinking ahead means identifying a problem's inputs and outputs, the preconditions that must be true before a subroutine runs (such as a list being sorted for binary search), and planning reusable program components. Caching stores results for reuse.

  1. List the inputs and the required outputs.
  2. State preconditions, e.g. 'the list must be sorted'.
  3. Design subroutines that can be reused.

Watch out If a precondition is documented, the subroutine can assume it rather than check it, making code simpler.

See it worked

Worked example

State a precondition for binary search.

  1. Binary search halves the list each step.
  2. That only works if the data is in order.
  3. Precondition: the list is sorted.

Answer The list must be sorted

Your turn

Question 11 mark

What is a precondition?

Choose one
Question 21 mark

What is an advantage of reusable components?

Choose one
Question 32 marks

Explain one benefit of caching.

Write your answer, then see a model answer
  1. Define caching.
  2. State the benefit.

Answer Results of previous operations are stored so they can be reused quickly instead of being recomputed or fetched again, improving performance.

A-level Computer Science Pro, OCR H446

A-level Computer Science Pro

£119 once

Price rises to £199 on 1 January. Save £80 by joining before then.

At least 12 months of access

By paying you agree to our Terms and get access straight away, which ends your 14-day cancellation right.

No VAT is charged.

Independent practice for OCR A-level Computer Science (H446), not endorsed by OCR.

Privacy · Terms