ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions

AH Computing Science 2025 Question 4

15 marks · 2-D arrays

Using a programming language of your choice, write the code used to declare a 2-dimensional array called events to store this data. The insertion sort algorithm will be used to sort the events array in descending order of magnitude. Using a programming language of your choice, write the code needed to sort the events array using the insertion sort algorithm. Describe the evidence that should be gathered during testing to demonstrate that the data in the events array has been sorted correctly. Scientists want to spot local clusters of earthquake activity. An earthquake event is local if both the latitude and longitude are five or less from any other event. For example, if the data for the earthquake at index 13 below is analysed, there are four other events (at indices 7, 10, 11 and 12) with a difference of five or less for both latitude and longitude. A 1-dimensional array called clusterSize will be populated with the number of earthquakes local to each location. events index latitude longitude magnitude 0 28.7 128.6 4.6 1 31.7 −104.1 3.1 2 61.9 −149.9 2.5 3 31.6 −104.0 1.9 4 33.0 −115.6 1.58 5 31.6 −104.0 1.5 6 64.5 −147.0 1 7 35.8 0.96 8 33.3 −116.2 0.86 9 34.1 −116.8 0.81 10 38.8 −122.9 0.78 11 38.8 −122.7 0.75 12 38.8 0.75 13 38.8 −122.8 0.51 clusterSize 4 −118.6 −122.8 Using pseudocode, design an algorithm to populate the clusterSize array with a count of the number of earthquakes local to each earthquake event. Once the application is released and has been used successfully for some time, the developers propose rewriting it as an object-oriented programming project with a class for earthquake events and an additional class to hold details of volcanic events. State the type of maintenance required and justify your answer. Explain why both economic and technical feasibility must be considered before implementing the object-oriented version. A program is being developed to help scientists track and analyse earthquake activity around the world. Data is stored about the latitude, longitude and magnitude of all earthquakes. The latitude and longitude identify the location of an earthquake, and the magnitude indicates the strength of the earthquake. This data will be stored in a 2-dimensional array of real numbers called events as shown below. A total of 14 earthquake events have been recorded. latitude longitude magnitude 34.1 −116.8 0.81 33.3 −116.2 0.86 31.6 −104.0 1.5 31.6 −104.0 1.9 38.8 −122.8 0.51 28.7 128.6 4.6 35.8 −118.6 0.96 61.9 −149.9 2.5 38.8 −122.7 0.75 31.7 −104.1 3.1 38.8 −122.8 0.75 64.5 −147.0 1 33.0 −115.6 1.58 38.8 −122.9 0.78

Marking scheme

DECLARE events INITIALLY [ [0.0] * 3 ] * 14 Award 1 mark for correct dimensions and type real indicated. Accept valid declaration of 2D array with correct dimensions and data type in any programming language. See sample solution below. Award 1 mark for fixed loop from 2nd element to last element of array. Award 1 mark for conditional loop with complex condition. Award 1 mark for moving up entire row. Award 1 mark for storing and inserting entire row. FOR outer FROM 1 TO 13 SET currentLat TO events[outer][0] SET currentLong TO events[outer][1] SET currentMag TO events[outer][2] SET inner TO outer WHILE (inner > 0) AND (events[inner-1][2] < currentMag) DO 2nd mark SET events[inner][0] TO events[inner-1][0] SET events[inner][1] TO events[inner-1][1] SET events[inner][2] TO events[inner-1][2] 3rd mark SET inner TO inner - 1 END WHILE SET events[inner][0] TO currentLat SET events[inner][1] TO currentLong SET events[inner][2] TO currentMag END FOR 1st mark 4th mark Expected vs actual output: The expected output from the sort code would be predicted and noted. After the sort has been executed, the contents of the sorted array could be displayed on the screen. A screenshot of this display could be compared with the predicted results to determine whether the sort code is working correctly. Use of breakpoint: The contents of the events array could be inspected (using a break point) before the sort code is executed and then inspected again after it been executed. Screenshots of the before and after contents of the arrays could be presented as evidence to show that the sort code is working correctly. Award 1 mark for inspecting contents of array before sorting. Award 1 mark for outputting/inspecting data after sorting to compare with expected output. See sample solution below. Award 1 mark for nested fixed loop (lines 1 & 5 of the solution below). Award 1 mark for comparison of latitude and longitude differences (line 6). Award 1 mark for count that doesn’t count event itself (line 6). Award 1 mark for updating cluster count in clusterSize array (line 7). 1. start fixed outer loop from 0 to 13 2. set clusterSize[outer] = 0 3. set currentLat = events[outer][0] 4. set currentLong = events[outer][1] 5. start fixed inner loop from 0 to 13 6. if (currentLat – events[inner][0] between 5 and –5 inclusive) and (currentLong – events[inner][1] between 5 and –5 inclusive) and (outer ≠ inner) then 7. 8. 9. end fixed loop 10. end fixed loop set clusterSize[outer] = clusterSize[outer] + 1 end if • perfective maintenance is needed Justification: • the software has been running successfully but new functionality is required to record volcanic activity • the code is being updated to run in an OOP environment by altering the internal structure of existing code using 2D arrays to run with methods and objects Award 1 mark for perfective maintenance. Award 1 mark for suitable justification. Note: only 1 justification is needed. Note: Do not accept adaptive as code is not being updated to take account of external factors. • economic feasibility: Check whether there is a financial benefit in spending money to create a new OO version of the software; if there is no financial gain, the project would not be feasible • technical feasibility: Check whether the skills necessary to develop an OO solution are available amongst the developers otherwise the project would not be feasible Award 1 mark for explanation of the need to consider economic feasibility. Award 1 mark for explanation of the need to consider technical feasibility.

Previous question: AH Computing Science 2025 Question 3

Next question: AH Computing Science 2025 Question 5