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.
Practise AQA GCSE Computer Science Efficiency of algorithms with exam-style questions for GCSE Computer Science. 15 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.