State a precondition for binary search.
- Binary search halves the list each step.
- That only works if the data is in order.
- Precondition: the list is sorted.
Answer The list must be sorted
A-level Computer Science revision · Computational thinking
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.
Watch out If a precondition is documented, the subroutine can assume it rather than check it, making code simpler.
State a precondition for binary search.
Answer The list must be sorted
What is a precondition?
What is an advantage of reusable components?
Explain one benefit of caching.
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
£119 once
Price rises to £199 on 1 January. Save £80 by joining before then.
At least 12 months of access
No VAT is charged.