State two factors that may affect the performance of a sorting algorithm.
- (a)State two factors that may affect the performance of a sorting algorithm.[2]
- (b)The given algorithm is a simple bubble sort that arranges a set of scores stored in a one- dimensional array into descending order, and orders the corresponding students' names stored into a two-dimensional array in the same order as the scores. All the arrays are indexed from 1. The contents of both arrays after sorting are shown. Name Score 1 98 2 97 ... 248 5 249 3 1 Smithfield Tom 2 Johnson Jane ... 248 Peters Jade 249 Allen John YearSize ← 249 Flag ← TRUE WHILE Flag = TRUE Flag ← FALSE FOR Student ← 1 TO YearSize - 1 IF Score[Student] < Score[Student + 1] THEN Temp1 ← Score[Student] Temp2 ← Name[Student,1] Temp3 ← Name[Student,2] Score[Student] ← Score[Student + 1] Name[Student,1] ← Name[Student + 1,1] Name[Student,2] ← Name[Student + 1,2] Score[Student + 1] ← Temp1 Name[Student + 1,1] ← Temp2 Name[Student + 1,2] ← Temp3 Flag ← TRUE ENDIF NEXT Student ENDWHILE Write an algorithm, using pseudocode, that will perform the same task using an insertion sort.[6]
Mark scheme
Marking points from the official mark scheme (May/June 2021). The mark or mark type is shown in brackets.
- [2] One mark for each correct marking point (Max 2)
- [2] The initial order of the data
- [2] The number of data items to be sorted
- [2] The efficiency of the sorting algorithm
- [6] One mark for each marking point (max 6)
- [6] MP1 Use of FOR loop to cycle through the whole year group
- [6] MP2 Temporary storage of the score being 'inserted'
- [6] MP3 Temporary storage of the corresponding name elements
- [6] MP4 Use of WHILE loop with correct exit clause
- [6] MP5 Moving of all three elements of data to next array elements
- [6] MP6 Correct updating of counter variable
- [6] MP7 Final insertion of all three data elements
- [6] Example algorithm YearSize ← 249 FOR Student ← 2 to YearSize Temp1 ← Score [Student] Temp2 ← Name [Student,1] Temp3 ← Name [Student,2] Counter ← Student WHILE Counter > 1 AND Score [Counter - 1] < Temp1 Score [Counter] ← Score [Counter - 1] Name [Counter,1] ← Name [Counter - 1,1] Name [Counter,2] ← Name [Counter - 1,2] Counter ← Counter - 1 ENDWHILE Score [Counter] ← Temp1 Name [Counter,1] ← Temp2 Name [Counter,2] ← Temp3 NEXT Student
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →