Skip to content

Course home

Efficiency of algorithms

Efficiency of algorithms

EasyMedium
123456789
Question 1

A programmer implements the subroutine shown in Figure 1 to check if a username is containing a blacklisted phrase.

1      SUBROUTINE IsBlocked(user)
2          blacklist ← ['guest', 'temp', 'bot']
3          i ← 0
4          found ← false
5          WHILE i < 3
6              IF user = blacklist[i] THEN
7                  found ← true
8              ENDIF
9              i ← i + 1
10         ENDWHILE
11         RETURN found
12     ENDSUBROUTINE

Figure 1

He replaces line 7 with:

RETURN true

He also replaces line 11 with:

RETURN false

Explain how the programmer has made the subroutine more efficient.

[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