Past-paper question · 2022 October-November · Paper 22 · Q7(b)

Question 7(b) 2022 · October-November · Paper 22 · 8 marks

Original past-paper question for 7(B)
Original past-paper question for 7(B)
Original past-paper question for 7(B)
Original past-paper question for 7(B)
Reveal official mark-scheme answer Official mark-scheme answer for 7(B)

Official answer for Question 7

Part (b)

✓
One mark per point (Max 8):

Question 8

Question 1

✓
Procedure heading and ending as shown

Question 2

✓
Conditional loop correctly terminated

Question 3

✓
An inner loop

Question 4

✓
Correct range for inner loop

Question 5

✓
Comparison (element J with J+1) in a loop

Question 6

✓
Swap elements in both arrays in a loop

Question 7

✓
'No-Swap' mechanism:
  • Conditional outer loop including flag reset
  • Flag set in inner loop to indicate swap

Question 8

✓
Efficiency (this scenario): terminate inner loop when ErrCode = 999

Question 9

✓
Reducing Boundary in the outer loop
✓
PROCEDURE
✓
SortArrays()
✓
DECLARE
✓
TempInt, J, Boundary : INTEGER
✓
DECLARE
✓
TempStr : STRING
✓
DECLARE
✓
NoSwaps : BOOLEAN
✓
Boundary 499
✓
REPEAT
✓
NoSwaps TRUE
✓
FOR J 1 TO Boundary
✓
IF ErrCode[J]> ErrCode[J+1] THEN
✓
//first swap ErrCode elements
✓
TempInt ErrCode[J]
✓
ErrCode[J] ErrCode[J+1]
✓
ErrCode[J+1] TempInt
✓
//now swap corresponding ErrText elements
✓
TempStr ErrText[J]
✓
ErrText[J] ErrText[J+1]
✓
ErrText[J+1] TempStr
✓
NoSwaps FALSE
✓
ENDIF
✓
NEXT J
✓
Boundary Boundary - 1
✓
UNTIL NoSwaps = TRUE
✓
ENDPROCEDURE

Mark scheme 9618_w22_ms_22.pdf →

Show text version of question

Question 7

Part (b)

Question 7

A teacher is designing a program to perform simple syntax checks on programs written by

students.

Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.

  • Array ErrCode contains integer values that represent an error number in the range 1 to 800.
  • Array ErrText contains string values that represent an error description.

The following diagram shows an example of the arrays.

Index ErrCode ErrText 1 10 "Invalid identifier name" 2 20 "Bracket mismatch" 3 50 "Undeclared variable" 4 60 "Type mismatch in assignment"

…

500 999 <Undefined>

Note:

  • There may be less than 500 error numbers so corresponding elements in both arrays may be
  • unused. Unused elements in ErrCode have the value 999. The value of unused elements in ErrText is undefined.

  • Values in the ErrCode array are stored in ascending order but not all values may be present,

for example, there may be no error code 31.

The teacher has defined two program modules as follows:

Module Description

  • takes two parameters as integers:
  • ○ a line number in the student’s program ○ an error number

  • searches for the error number in the ErrCode array:

OutputError() ○ if found, outputs the corresponding error description and the line number, for example: "Bracket mismatch on line 34" ○ if not found, outputs the line number and a warning, for example: "Unknown error on line 34"

SortArrays() sorts the arrays into ascending order of ErrCode

Question 17

Part (b)

Write an efficient bubble sort algorithm in pseudocode for module SortArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................

[8]

Question 19

Topic relevance

Why this question appears here

92% assigned-topic match · Algorithm design and problem-solving › Algorithms

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9618_w22_qp_22.pdf

Keep practising this topic