Skip to content

Course home

Sign up

Develop code

EasyMediumHard
12345678910111213141516171819
Question 6

An algorithm is designed to sort a 2D array of runners by their marathon times in ascending order.

1 # runners has the format [runnerID, name, raceTime]
2
3 PROCEDURE bubbleSortRunners()
4     SET temp TO []
5     FOR i FROM 0 TO LENGTH(runners) - 1 DO
6         FOR j FROM 0 TO LENGTH(runners) - 1 DO
7             IF runners[j, 2] > runners[j + 1, 2] THEN
8                 SET temp TO runners[j]
9                 SET runners[j] TO runners[j + 1]
10                SET runners[j + 1] TO temp
11            END IF
12        END FOR
13    END FOR
14 END PROCEDURE

The algorithm currently contains an error on line 6 that causes an 'index out of bounds' error when it is run.

Give a new line of code that will correct the error on line 6.

[1]
Markscheme

Develop code Questions

  1. GCSE
  2. /Computer Science
  3. /Develop code

51 exam-style questions on Edexcel GCSE Computer Science Develop code, covering Decomposition and abstraction to solve problems, Read, write, analyse and refine programs, Converting algorithms into programs, Techniques for readable, maintainable code, Identifying and correcting program errors, and Evaluating program fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank