May/June 2026 Paper 22

2026 · 6 questions · 26 parts · 75 marks

0/75 marks
0Correct0Partial0Wrong26Unattempted
Filters0 active
5(a)Sorting AlgorithmsEasy1 mark
A programmer has defined a global 1D array Numbers of type INTEGER, which can store 1000 integers. The lower bound of the array Numbers is set to 1. Each element of the array has been initialised with a random integer in the range 200 to 99 999.
The programmer has written a bubble sort algorithm to sort the array Numbers into ascending order.
Study algorithm A. Assume all the variables have been correctly declared.
algorithm A:
pseudocode
FOR LoopCounter ← 1 TO 999                 //Outer Loop   FOR Index ← 1 TO 999                    //Inner Loop      IF Numbers[Index] > Numbers[Index + 1] THEN         //Start of block to swap neighbouring elements in the array         Temp ← Numbers[Index]         Numbers[Index] ← Numbers[Index + 1]         Numbers[Index + 1] ← Temp         //End of block to swap neighbouring elements in the array      ENDIF   NEXT IndexNEXT LoopCounter
Describe the change that would have to be made to the bubble sort algorithm (algorithm A) so that the Numbers array would be sorted into descending order.

Answer

0 words
5(b)(i)Sorting AlgorithmsHard4 marks
The programmer rewrites the bubble sort algorithm to make it more efficient.
Study algorithm B. Assume all the variables have been correctly declared.
algorithm B:
pseudocode
Boundary ← 999REPEAT                               //Outer Loop   NoSwaps ← TRUE   FOR Index ← 1 TO Boundary        //Inner Loop      IF Numbers[Index] > Numbers[Index + 1] THEN         //Start of block to swap neighbouring elements in the array         Temp ← Numbers[Index]         Numbers[Index] ← Numbers[Index + 1]         Numbers[Index + 1] ← Temp         //End of block to swap neighbouring elements in the array         NoSwaps ← FALSE      ENDIF   NEXT Index   Boundary ← Boundary - 1UNTIL NoSwaps = TRUE
Explain why the second bubble sort algorithm (algorithm B) is more efficient than the first bubble sort algorithm (algorithm A). Your answer must refer to both the inner and the outer loop.
Inner loop
0 words
Outer loop
0 words
5(b)(ii)Sorting AlgorithmsEasy1 mark
State the situation that will result in the outer loop iterating for the minimum number of times when the second bubble sort algorithm (algorithm B) is used.
5(c)(i)Subroutines Scope Modular ProgrammingMedium2 marks
The programmer has defined a new procedure:
pseudocode
PROCEDURE Swap(Num1 : INTEGER, Num2 : INTEGER)   DECLARE Temp : INTEGER   Temp ← Num1   Num1 ← Num2   Num2 ← TempENDPROCEDURE
The programmer replaces the block of pseudocode in the algorithm that swaps the values in two neighbouring elements in the array with a call to this procedure. The block of code:
pseudocode
Temp ← Numbers[Index]Numbers[Index] ← Numbers[Index + 1]Numbers[Index + 1] ← Temp
is replaced by:
pseudocode
CALL Swap(Numbers[Index], Numbers[Index + 1])
The Swap() procedure will not work as expected when used in the bubble sort algorithm. Explain why the procedure Swap() will not work as expected.

Answer

0 words
5(c)(ii)Subroutines Scope Modular ProgrammingMedium2 marks
Write pseudocode to amend the version of the Swap() procedure given so that it will work as expected. The amended version of the Swap() procedure must not use global variables.
Amended Swap() procedure
0 words