5 An algorithm is designed to find the smallest numeric value from an input sequence and count how many numeric values have been input. An example of an input sequence is: 23, AB56, 17, 23ZW, 4, 10, END Numeric input values are all integers and non-numeric input is ignored, except for the string "END" which is used to terminate the sequence. The algorithm is expressed in pseudocode as shown: DECLARE NextInput : STRING DECLARE Min, Count, Num : INTEGER Min ← 999 Count ← 0 REPEAT INPUT NextInput IF IS_NUM(NextInput) = TRUE THEN Num ← STR_TO_NUM(NextInput) IF Num > Min THEN Min ← Num ENDIF Count ← Count & 1 ENDIF UNTIL NextInput ← "END" OUTPUT "The minimum value is ", Min, " and the count was ", Count
- (a)The pseudocode contains three errors due to the incorrect use of operators. Identify each error and state the correction required. 1 2 3[3]
- (b)(i)The algorithm is tested with a different test data sequence. The sequence contains a mix of integer and non-numeric values. It is terminated correctly but the algorithm produces unexpected results. Explain the problem with the algorithm.[2]
- (b)(ii)Give a sequence of four test data values that could be input to demonstrate the problem. Value 1 Value 2 Value 3 Value 4[2]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2023). The mark or mark type is shown in brackets.
- [1] Error 1: `Num > Min` should be `Num < Min`
- [1] Error 2: `Count & 1` should be `Count + 1`
- [1] Error 3: `NextInput ← "END"` should be `NextInput = "END"`
- [1] If all the numeric input values are greater than the initial value of Min (999) / if there are no numeric values in the sequence
- [1] Then the minimum will be given as 999 (and not one of the input values) / initial Min value is not updated
- [1] A sequence of mixed non-numeric and numeric values where all numeric values are greater than 999 (e.g., 1325, DOG, 7868, 7615)
- [1] Terminated by END
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →