Question 1
1 markThe array Values[1:20] holds 20 numbers.
Highest ← Values[1]
FOR Index ← 2 TO 20
IF Values[Index] > Highest
THEN
Highest ← Values[Index]
ENDIF
NEXT IndexExplain why the FOR loop starts at 2 and not at 1.
Model answer
Highest already holds Values[1], so comparing Values[1] with Highest would be pointless; the loop only needs to check the remaining elements, 2 to 20.
Explanation
Starting at 1 would still give the right answer, but it wastes one comparison. Starting at 2 only works because Highest was initialised to the first element.
Mark scheme
-
1 mark
Values[1] has already been used as the starting value of Highest, so it does not need to be compared (with itself)