AQA GCSE · Question 14 · Fundamentals of algorithms
Figure 16 shows an incomplete algorithm, represented using pseudo-code, designed to output the highest or lowest results of a vote. The programmer has used a two-dimensional array called results to store the genre and the number of votes for each genre. Parts of the algorithm are missing and have been replaced with the labels L1 to L3.
Figure 16
SUBROUTINE showResults(method, numberOfGenres)
results ← [['Pop', 'Post-Punk', 'Techno', 'Metal', 'Dance'],
['7', '19', '14', '1', '9']]
pos ← 0
high ← -1
IF method = 'HIGHEST' THEN
FOR i ← 0 TO numberOfGenres - 1
Votes ← STRING_TO_INT(results[L1][i])
IF votes > high THEN
high ← votes
pos ← L2
ENDIF
ENDFOR
ELSE
OUTPUT 'not yet working'
ENDIF
IF high ≠ -1 THEN
OUTPUT results[0][pos], ' with ', results[1][pos]
ENDIF
ENDSUBROUTINE
OUTPUT 'Show the genre with the HIGHEST or LOWEST number of votes? '
method ← USERINPUT
showResults(L3, 5)
State what should be written in place of the labels L1 to L3 in the algorithm.
Figure 16 shows an incomplete algorithm, represented using pseudo-code, designed to output the highest or lowest results of a vote. The programmer has used a two-dimensional array called results to store the genre and the number of votes for each genre. Parts of the algorithm are missing and have been replaced with the labels L1 to L3.
Figure 16
SUBROUTINE showResults(method, numberOfGenres)
results ← [['Pop', 'Post-Punk', 'Techno', 'Metal', 'Dance'],
['7', '19', '14', '1', '9']]
pos ← 0
high ← -1
IF method = 'HIGHEST' THEN
FOR i ← 0 TO numberOfGenres - 1
Votes ← STRING_TO_INT(results[L1][i])
IF votes > high THEN
high ← votes
pos ← L2
ENDIF
ENDFOR
ELSE
OUTPUT 'not yet working'
ENDIF
IF high ≠ -1 THEN
OUTPUT results[0][pos], ' with ', results[1][pos]
ENDIF
ENDSUBROUTINE
OUTPUT 'Show the genre with the HIGHEST or LOWEST number of votes? '
method ← USERINPUT
showResults(L3, 5)
State what should be written in place of the labels L1 to L3 in the algorithm.
How to approach this question
Full Answer
Common mistakes
Practice the full AQA GCSE Computer Science Paper 1 Python
31 questions · hints · full answers · grading
Expert