8Hard
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]

Algorithms Questions

Practise Edexcel GCSE Computer Science Algorithms with exam-style questions for GCSE Computer Science. 100 questions 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, matched to the Edexcel GCSE Computer Science (1CP2) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Algorithms