A marine biology research team records the migratory distances of tracked whale sharks in a 2D array named shark_telemetry. Each record in the array is structured as [shark_id, tag_code, migration_distance].
The team uses the following unoptimized bubble sort algorithm to sort the records in ascending order of their migration distances:
1 # shark_telemetry has the format [shark_id, tag_code, migration_distance]
2
3 PROCEDURE sortTelemetry()
4 BEGIN PROCEDURE
5 SET swap_var TO []
6 FOR i FROM 0 TO LENGTH(shark_telemetry) - 1 DO
7 FOR j FROM 0 TO LENGTH(shark_telemetry) - 2 DO
8 IF shark_telemetry[j][2] > shark_telemetry[j + 1][2] THEN
9 SET swap_var TO shark_telemetry[j]
10 SET shark_telemetry[j] TO shark_telemetry[j + 1]
11 SET shark_telemetry[j + 1] TO swap_var
12 END IF
13 END FOR
14 END FOR
15 END PROCEDURE
Describe how the implementation of this algorithm can be modified 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.