A logistics distribution hub uses a centralized database storing container profiles in a 2D array named cargo_manifest. Each record in the array has the format [containerID, destination, weight].
The system uses the following pseudocode program to sort the manifest in ascending order of cargo weight:
1 # cargo_manifest has the format [containerID, destination, weight]
2
3 PROCEDURE sortManifest()
4 BEGIN PROCEDURE
5 SET temp TO []
6 FOR i FROM 0 TO LENGTH(cargo_manifest) - 1 DO
7 FOR j FROM 0 TO LENGTH(cargo_manifest) - 2 DO
8 IF cargo_manifest[j][2] > cargo_manifest[j + 1][2] THEN
9 SET temp TO cargo_manifest[j]
10 SET cargo_manifest[j] TO cargo_manifest[j + 1]
11 SET cargo_manifest[j + 1] TO temp
12 END IF
13 END FOR
14 END FOR
15 END PROCEDURE
Describe how the implementation of this bubble sort algorithm could be refined to improve its efficiency.
159 exam-style questions on Edexcel GCSE Computer Science Algorithms, covering Constructs for solving problems, Variables, constants and data structures, Arithmetic, relational and logical operators, Tracing algorithm output with trace tables, Types of error and correcting logic errors, Standard algorithms (sorts and searches), and Evaluating algorithm fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.