Past-paper question · 2015 October-November · Paper 21 · Q1(e)

Question 1(e) 2015 · October-November · Paper 21 · 6 marks

Original past-paper question for 1(E)
Original past-paper question for 1(E)
Original past-paper question for 1(E)
Original past-paper question for 1(E)
Original past-paper question for 1(E)
Reveal official mark-scheme answer Official mark-scheme answer for 1(E)Official mark-scheme answer for 1(E)

Official answer for Question 1

Part (e)

Part (e)

Mark as follows:

  • change outer FOR loop to a REPEAT/WHILE loop
  • decrementing the iterations of the FOR loop
  • introduce a Boolean variable NoSwaps (or similar)
  • initialise Boolean variable correctly (inside outer loop and outside inner loop)
  • terminate REPEAT loop when no swaps made
  • leave comparison and swapping code the same
  • change upper limit of inner loop to NumberOfCourses – x (instead of 49)
✓
Example pseudocode:
✓
PROCEDURE SortData(NumberOfCourses)
✓
x ← 0
✓
// NoSwaps ← FALSE
✓
(required for WHILE loop)
✓
REPEAT // WHILE NoSwaps = FALSE
✓
x ← x + 1
✓
NoSwaps ← TRUE
✓
FOR y ← 1 TO NumberOfCourses - x
✓
IF Course[y].CourseFee > Course[y + 1].CourseFee
✓
THEN
✓
NoSwaps ← FALSE
✓
TempRecord ← Course[y]
✓
Course[y] ← Course[y + 1]
✓
Course[y + 1] ← TempRecord
✓
ENDIF
✓
ENDFOR
✓
UNTIL NoSwaps = TRUE
✓
// ENDWHILE
✓
ENDPROCEDURE
✓
[max 6]
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – October/November 2015
✓
9691

Question 21

Mark scheme 9691_w15_ms_21.pdf →

Show text version of question

Question 1

Part (e)

Part (e)

Ravi wants to write a procedure to sort the records in the array Course. The records will

be sorted into ascending order of course fee. The array contains records for each course provided. The remaining array elements contain dummy records.

One of his students has written a sorting algorithm:

PROCEDURE SortData FOR x ← 1 TO 49 FOR y ← 1 TO 49 IF Course[y].CourseFee > Course[y + 1].CourseFee THEN TempRecord ← Course[y] Course[y] ← Course[y + 1] Course[y + 1] ← TempRecord ENDIF ENDFOR ENDFOR ENDPROCEDURE

An integer variable, NumberOfCourses, will contain the number of courses for which data are stored in the array.

Improve the algorithm so that no unnecessary comparisons are made.

PROCEDURE SortData(NumberOfCourses)

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[6]

Question 6

Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Constructs

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9691_w15_qp_21.pdf

Keep practising this topic