This pseudocode algorithm is intended to input a first name from a user and search for it in a two-dimensional (2D) array. If the name is found, the algorithm outputs all the remaining details for that name. The algorithm will continue to allow other names to be entered for searching, until the user input stops it. 01 DECLARE Contacts : ARRAY[1:500, 1:4] OF REAL 02 DECLARE Row : INTEGER 03 DECLARE Column : INTEGER 04 DECLARE Continue : BOOLEAN 05 DECLARE Stop : BOOLEAN 06 DECLARE FirstName : STRING 07 Continue ← TRUE 08 Stop ← FALSE 09 WHILE Continue 10 Row ← 1 11 OUTPUT "Enter a first name " 12 OUTPUT FirstName 13 REPEAT 14 IF Contacts[Row, 1] = FirstName 15 THEN 16 FOR Column ← 1 TO 4 17 OUTPUT Contacts[Row, 1] 18 NEXT Column 19 Stop ← TRUE 20 ELSE 21 Row ← Row + 1 22 ENDIF 23 NEXT Stop OR Row > 500 24 OUTPUT "Search for another name? (Y or N)" 25 INPUT Answer 26 IF Answer = 'N' OR Answer = 'n' 27 THEN 28 Continue ← TRUE 29 ENDIF 30 ENDWHILE
- (a)Identify the line numbers of five errors in the pseudocode and suggest a correction for each error. Error 1 line number ................................................................................................... Correction .............................................................................................................[5]
- (b)(i)Complete the pseudocode for PROCEDURE NewData PROCEDURE NewData(.. .) FOR RoW 1 ΤΟ FOR Column ← 1 TO 4 INPUT ENDPROCEDURE[4]
- (b)(ii)Write the pseudocode to input the number of new contacts and to use procedure NewData. A variable declaration is not required.[2]
- (c)(i)Explain why the given algorithm may not always give the expected results.[2]
- (c)(ii)Explain how you could improve the algorithm so that the search is more likely to find the required results.[2]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2025). The mark or mark type is shown in brackets.
- [1] Line 01 / DECLARE Contacts : ARRAY[1:500, 1:4] OF REAL should be DECLARE Contacts : ARRAY[1:500, 1:4) OF STRING
- [1] Line 12 / OUTPUT FirstName should be INPUT FirstName
- [1] Line 17/OUTPUT Contacts[Row, 1] should be OUTPUT Contacts[Row, Column]
- [1] Line 23 / NEXT Stop OR Row > 500 should be UNTIL Stop OR Row > 500
- [1] Line 25/26 / Answer variable not declared should be DECLARE Answer : CHAR before line 25
- [1] Line 28 / Continue ← TRUE should be Continue ← FALSE
- [1] MP1 Appropriate parameter in PROCEDURE line
- [1] MP2 Correct index outer loop termination value; must use Number as stated in question
- [1] MP3 Correct array reference in INPUT
- [1] MP4 Correct termination of both loops.
- [4] Example: PROCEDURE NewData (Number : INTEGER) FOR Row ← 1 TO Number FOR Column ← 1 TO 4 INPUT Contacts [Row, Column] NEXT Column NEXT Row ENDPROCEDURE
- [1] MP1 Correct input statement
- [1] MP2 Correct call statement for NewData
- [2] Example: INPUT MyNumber CALL NewData (MyNumber)
- [1] MP1 There may be more than one person with the given first name // The name may not exist/found in the array
- [1] MP2 The search will stop at the first occurrence and output the data for the wrong person
- [1] MP3 If the name is not present there could be no output / the loop will continue.
- [1] MP1 Introduce additional search criteria into the algorithm to make the search more specific to each person in the array
- [1] MP2 such as the last name to go with the first name // ... such as some form of ID number / date of birth / contact number / post code
- [1] MP3 The algorithm should be able to search the whole array to find all available matches
- [1] MP4 by removing the stop variable
- [1] MP5 Use selection to confirm the name has not been found in the whole array
- [1] MP6 If the name is not present, output an appropriate message.
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 →