Skip to main content
A-LevelComputer ScienceData types and structures9618/42 · May/June 2022 · Q223 Marks

A 2D array stores data entered by a user.

  1. (a)The main program declares a 2D array of 10 by 10 integer elements. The array is initialised with a random number between 1 and 100 in each element. Write program code for the main program.[4]
  2. (b)(i)The following bubble sort pseudocode algorithm sorts the data in the first dimension of the 2D array into ascending numerical order. ArrayLength ← 10 FOR X ← 0 TO ArrayLength - 1 FOR Y ← 0 TO ArrayLength - 2 FOR Z ← 0 TO ArrayLength - Y - 2 IF ArrayData[X, Z] > ArrayData [X, Z + 1] THEN TempValue ← ArrayData[X, Z] ArrayData[X, Z] ← ArrayData[X, Z+1] ArrayData[X, Z + 1] ← TempValue ENDIF NEXT Z NEXT Y NEXT X Amend your main program by writing program code to implement the bubble sort algorithm after the initialisation of the array elements. You must not use any built-in sorting functions for your programming language.[5]
  3. (b)(ii)Write program code for a procedure to output all the values in the 2D array. The values should be output as a 2D grid, with values in rows and columns. Call the procedure before and after your bubble sort code.[3]
  4. (b)(iii)Test your program. Take a screenshot to show the output.[1]
  5. (c)(i)The following pseudocode function uses recursion to perform a binary search in the first row of the array, for the value SearchValue in the array SearchArray. The function returns -1 if the item was not found, or it returns the index where it is found. There are six incomplete statements. FUNCTION BinarySearch(SearchArray, Lower, Upper, SearchValue)RETURNS INTEGER IF Upper >= Lower THEN Mid ← (Lower + (Upper - 1)) DIV IF SearchArray[0, Mid] RETURN ELSE IF SearchArray[0, Mid] > SearchValue THEN RETURN BinarySearch(SearchArray, Mid - 1, SearchValue) ELSE RETURN BinarySearch(SearchArray, Mid + 1, SearchValue) ENDIF ENDIF ENDIF RETURN ENDFUNCTION Note: the arithmetic operator DIV performs integer division, e.g. the result of 10 DIV 3 will be 3. Write program code for the recursive function BinarySearch().[8]
  6. (c)(ii)In the main program, test the function BinarySearch() twice, outputting the returned value each time. One test should be for a number that is in the first line of the array. One test should be for a number that is not in the first line of the array. Take a screenshot to show the output.[2]

Mark scheme

Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.

  1. [4] 1 mark per mark point • in main local 2D array declared • ... with 10 x 10 integer elements • initialising all array elements to a number... • ...that is random between 1 and 100 (allow inclusive or exclusive)
  2. [5] 1 mark per mark point • 1st outer loop (dimension 1) • 2nd loop (dimension 2) • inner for loop for all second dimension • Selection statement ... • ...swapping the numbers correctly
  3. [3] 1 mark per mark point • procedure header (and end where appropriate) • Outputting all 10 × 10 values with each 2nd dimension on a complete line • Calling procedure before and after bubble sort
  4. [1] 1 mark for output showing array unsorted and then sorted on 1 of the dimensions e.g.
  5. [1] Completed statement: DIV 2
  6. [1] Completed statement: IF SearchArray[0, Mid] = SearchValue THEN
  7. [1] Completed statement: RETURN Mid
  8. [1] Completed statement: RETURN BinarySearch(SearchArray, Lower, Mid - 1, SearchValue)
  9. [1] Completed statement: RETURN BinarySearch(SearchArray, Mid + 1, Upper, SearchValue)
  10. [1] Completed statement: RETURN -1
  11. [1] Function declaration taking appropriate parameters and recursive calls
  12. [1] Remainder of the function is accurate including appropriate DIV operator
  13. [2] 1 mark per mark point • screenshot outputting the index when Number is found • screenshot outputting -1 with a Number not found e.g.

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 →

About this question

Topic
Data types and structures, A-Level Computer Science (syllabus 9618). Structured question, 23 marks.
Source
A-Level Computer Science, May/June 2022 Paper 4 Variant 2, question 2.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep