A program is being designed in pseudocode. The program contains the following declaration for the global array MyData: DECLARE MyData : ARRAY[1:10000] OF STRING A function FindFirst() is written to search the array for a given string and to return the index of the first element where that string is found, or to return -1 if the string is not found. The function is written in pseudocode as shown: FUNCTION FindFirst(SearchString : STRING) RETURNS INTEGER DECLARE Index, FoundAt : INTEGER FoundAt ← -1 FOR Index ← 1 TO 10000 IF MyData [Index] = SearchString THEN // outer conditional clause IF FoundAt = -1 THEN FoundAt ← Index // inner conditional clause ENDIF ENDIF NEXT Index RETURN FoundAt ENDFUNCTION
- (a)(i)Comment on why the programmer chose –1 as the initial value of FoundAt[1]
- (a)(ii)Explain the purpose of the outer conditional clause.[1]
- (a)(iii)The inner conditional clause ensures that only the index of the first matching element, if any, is returned. Explain how this clause works.[1]
- (b)(i)The pseudocode does not use the most appropriate loop construct. Explain why this is not the most appropriate loop construct.[1]
- (b)(ii)Suggest and justify a more appropriate loop construct that could be used. Construct Justification[2]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2025). The mark or mark type is shown in brackets.
- [1] (a)(i) It is a value that is invalid as an (array) index // not in the range of valid (index) values
- [1] (a)(ii) To test whether the current element / value at index matches the given / search string / data / parameter
- [1] (a)(iii) The value of FoundAt is only updated to the (current) index if it currently stores the initial value / -1 // FoundAt is not updated when it currently stores any value other than -1
- [1] (b)(i) The loop continues after the (first instance) of the search value / string / matching element has been found. Comparisons/tests continue to be made even if the search value / string / matching element has been found
- [2] (b)(ii) Construct: A conditional loop
- [2] (b)(ii) Justification: The loop / search can be terminated as soon as the (first occurrence of) SearchString / required value / required string / matching element is found
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 →