2.3.1 Algorithms - Sorting
2.3.1 Algorithms - Sorting
Fig. 1
A computer program is required to keep track of the scores for each competition. The user will enter the number
of players, and the name of each player, in that competition to a maximum of 10.
(i) The programmer has decided to use a bubble sort to sort the players’ scores in descending order of score.
(ii) Despite the disadvantages, the programmer has decided to use a bubble sort for the players’ scores.
Identify the characteristic of this problem that minimises the disadvantages of a bubble sort.
[1]
(iii) Write a procedure, sortScores, to perform a bubble sort on the global array scores to sort the players’
scores into descending numeric order.
A procedure, insertionSort, has been written to sort an array numbers. The procedure is incomplete.
procedure insertionSort()
for count = 0 to numbers.length - 1
position = ........................................................
while position > 0 and numbers[position] < numbers[position-1]
temp = .......................................................
numbers[position-1] = ........................................
numbers[position] = temp
position = ...................................................
endwhile
next count
endprocedure
[4]
Fig. 4.1
Show how a bubble sort would sort the data in Fig. 4.1.
[6]
[3]
(ii) Demonstrate an insertion sort to place the following numbers into descending numerical order.
12 7 4 5 26
[4]
Total 13
Total 6
Examiner's Comments
1 mark per correct row after row 1 in Do not allow swap(ped) or pivots
sequence to max 4
Examiner's Comments
Total 7