0% found this document useful (0 votes)
19 views8 pages

2.3.1 Algorithms - Sorting

The document discusses a game called Kidz Arrowz and the need for a computer program to track player scores, utilizing bubble sort for score sorting despite its disadvantages. It also includes tasks related to sorting algorithms, specifically bubble sort and insertion sort, with procedures and examples for implementation. The document outlines the requirements for sorting player scores and strings, as well as the characteristics of sorting algorithms.

Uploaded by

cabae010.304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views8 pages

2.3.1 Algorithms - Sorting

The document discusses a game called Kidz Arrowz and the need for a computer program to track player scores, utilizing bubble sort for score sorting despite its disadvantages. It also includes tasks related to sorting algorithms, specifically bubble sort and insertion sort, with procedures and examples for implementation. The document outlines the requirements for sorting player scores and strings, as well as the characteristics of sorting algorithms.

Uploaded by

cabae010.304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1. A games company has developed a game called Kidz Arrowz.

The players throw an arrow at a target board and


are awarded different points depending on which circle the arrow lands. Fig. 1 shows the board.

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.

Describe the disadvantages of using a bubble sort.

© OCR 2019. 1 of 8 PhysicsAndMathsTutor.com


[2]

(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.

© OCR 2019. 2 of 8 PhysicsAndMathsTutor.com


[6]

(iv) An alternative sorting method is the insertion sort.

A procedure, insertionSort, has been written to sort an array numbers. The procedure is incomplete.

Complete the procedure.

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]

© OCR 2019. 3 of 8 PhysicsAndMathsTutor.com


2. A program needs to sort an array of lowercase strings into descending alphabetic order. An example of the data
is shown in Fig. 4.1.

Fig. 4.1

Show how a bubble sort would sort the data in Fig. 4.1.

[6]

© OCR 2019. 4 of 8 PhysicsAndMathsTutor.com


3.

(i) Describe how an insertion sort is performed.

[3]

(ii) Demonstrate an insertion sort to place the following numbers into descending numerical order.

12 7 4 5 26

[4]

END OF QUESTION PAPER

© OCR 2019. 5 of 8 PhysicsAndMathsTutor.com


Question Answer/Indicative content Marks Guidance

1 i 1 mark per bullet to max 2 2


AO1.2
Bubble sort is an inefficient algorithm… (1)
Meaning it will take more AO2.2
time/processing cycles to sort the list. (1)
Generally outperformed by Insertion Examiner’s Comments
sort/quick sort/ merge sort (accept any
other sensible sorting algorithm) Most candidates identified the inefficiency
The item to be sorted is at the end of of the bubble sort but fewer could expand
the list (and so can only move back upon this.
one place per pass) which is the worst
case scenario for bubble sort.

ii There are only a small number of data 1


items AO2.2 Examiner’s Comments
(1)
Most candidates correctly identified that
that the list to sort was small.

iii 1 mark per bullet to max 6 6


AO1.2
Procedure declaration (2)
Outer loop until no swaps made using AO2.2
flag (1)
Inner loop to iterate through the list… AO3.2
…allowance for largest value at end (in (3)
bounds) Examiner’s Comments
Comparing elements
Swapping elements Those candidates who had learnt the
standard sorting algorithms had little
e.g. difficulty producing good pseudocode for
procedure sortScores() the bubble sort. Unfortunately, many
do candidates had not learnt the code for the
sorted = true standard algorithms.
for j = 0 to 19
if scores[j].totalScore >
scores[j+1].totalScore then
temp = scores[j+1]
scores[j+1] = scores[j]
scores[j = temp
sorted = false endif
next j
until sorted = true
endprocedure

© OCR 2019. 6 of 8 PhysicsAndMathsTutor.com


Question Answer/Indicative content Marks Guidance

iv 1 mark for each completed space 4


AO2.2
procedure insertionSort() (3)
for count = 0 to AO3.2
numbers.length-1 (1)
position = count
while position > 0 and numb
ers[position]<numbers[position- Examiner’s Comments
1]
temp = numbers[position-1] Candidates who were confident in
numbers[position-1] = analysing code often answered
numbers[position] successfully and could calculate the
numbers[position] = temp correct way to index the numbers[ ] array.
position = position-1
endwhile
next count
endprocedure

Total 13

2 1 mark for each correct swap 6


identified/described

Total 6

© OCR 2019. 7 of 8 PhysicsAndMathsTutor.com


Question Answer/Indicative content Marks Guidance

3 i One item at a time / serially … 3


…moved into correct position… Do not allow swap(ped) or pivots
…until all items in list checked
Allow two lists.

One item at a time taken from 1st list…


…and inserted into 2nd list…
…in the correct place.

Examiner's Comments

There were quite a few very muddled


answers to this question, those that were
not muddled, were just plain wrong. A large
proportion of candidates either were
swapping for a bubble sort or using pivots;
neither of which were what was required.

ii 4 Method must be demonstrated somehow -


circles, underlining, description e.g. “insert
12” etc
Must be an insertion sort

1 mark per correct row after row 1 in Do not allow swap(ped) or pivots
sequence to max 4

Examiner's Comments

Those who knew what an insertion sort


was got this correct, a fair percentage used
quick sorts or bubble sorts and as such did
not receive any marks.

Total 7

© OCR 2019. 8 of 8 PhysicsAndMathsTutor.com

Powered by TCPDF (www.tcpdf.org)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy