Skip to content

Course home

Efficiency of algorithms

Efficiency of algorithms

EasyMedium
123456789
Question 7

An automated quality-control system scans a batch of 5 components to check for defects. A technician implements the following subroutine:

1      SUBROUTINE HasDefect(batch)
2          i ← 0
3          faulty ← false
4          WHILE i < 5
5              IF IsDefective(batch[i]) THEN
6                  faulty ← true
7              ENDIF
8              i ← i + 1
9          ENDWHILE
10         RETURN faulty
11     ENDSUBROUTINE

The technician replaces line 6 with:

RETURN true

She also replaces line 10 with:

RETURN false

Explain how these changes improve the efficiency of the subroutine.

[2]
Markscheme

Efficiency of algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Efficiency of algorithms

15 exam-style questions on AQA GCSE Computer Science Efficiency of algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank