11Hard
0/4

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.

[4]
PreviousNext

Computational thinking Questions

  1. GCSE
  2. /Computer Science
  3. /Computational thinking