New File
New File
[2]
State whether a binary search or a linear search would be the most appropriate method to search for a specific
card, and justify your answer.
Search method _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Justification
[3]
(b) A programmer is writing a computer program to sort the cards into the correct order (0 to 7).
(i) Show how an insertion sort would sort the array in Fig 4.1 into the correct order. Draw the array after each
move.
[3]
(ii) Describe how a quick sort algorithm works with the data in Fig 4.2.
The worst case scenario for Merge is O(n log(n)) and for Bubble is O(n^2).
Compare the use of a merge sort and a bubble sort on this array, evaluating the performance of each sort,
making reference to the worse case Big O notation.
[9]
When comparing linear and binary search it is possible to look at the best, worst and average number of items in
the array that need to be checked to find the item being searched for. Assume every item in the array is equally
likely to be searched for.
[1]
(c) Assuming an array is sorted give a situation when a linear search would perform better than a binary search.
[1]
Use the values given to show the first three steps for:
[3]
(iii) Explain the difference between binary searching and serial searching.
[2]
(iv) State one advantage and one disadvantage of a binary search compared with a serial search.
[2]
[4]
[3]
(ii) Demonstrate an insertion sort to place the following numbers into descending numerical order.
12 7 4 5 26
[4]
(iii) State one disadvantage of an insertion sort compared with a quick sort.
[1]
(i) Explain why a binary search would not be used for this data.
[2]
(ii) Describe the steps that a serial search would take to find the value 27.
[4]
(iii) Demonstrate the steps needed for a quick sort on these values: (42, 83, 27, 18, 52).
[5]
[4]
[8]
(i) Give the reason why the target integer 8 is not found.
[1]
(ii) Identify and describe an alternative search algorithm that could be used.
[3]
Fig. 4.1
Show how a bubble sort would sort the data in Fig. 4.1.
[6]
Fig. 4.2
[3]
[4]
(ii) Name two sorting algorithms, other than a bubble sort and merge sort.
[2]
array data[16,11]
Fig. 1.1
Karl needs to find out if a number he enters appears in a given row of the array. He is going to use a search
algorithm to do this.
(i) State the name of two different search algorithms that Karl could consider using.
[2]
Algorithm
Description
[5]
The user needs to be able to search for, and find, a specific order number.
State an appropriate search algorithm that could be used, and justify your choice against an alternative Search
algorithm.
Justification
[3]
[3]
(ii) Show how an insertion sort would sort the following data:
[6]
(i) Using Big-O notation state the best case complexity of insertion sort.
[1]
[3]
12 Oscar owns a taxi company. He would like a program to handle taxi bookings from customers.
Some of Oscar’s customers are rated as gold. Customers who are rated as gold are given priority when they
make a taxi booking. Some customers rated as gold are shown here.
Arshad Betty Dave Freddie Harry Jimmy Kanwal Lynn Siad Tommy Will
When a customer makes a booking, Oscar will make use of a binary search to check if they are gold rated.
(i) State the three values that will be set as the midpoints and then checked against ‘Tommy’ on each iteration
of the binary search.
Midpoint 2
Midpoint 3
[3]
Benefit
[2]
(iii) State one other search algorithm that Oscar could have used.
[1]
(iv) State the pre-condition which has been met, which meant that Oscar did not need to use the search
algorithm you stated in the part above.
[1]
Currently the first five numbers before they have been sorted are:
195 584 167 147 158 187 160 125 184 236
Currently the last five numbers before they have been sorted are:
* Discuss how a bubble sort works and how efficient it will be when sorting these 250 000 items into order from
lowest to highest.
(b) State the number of comparisons that will need to be made in the first pass of the bubble sort.
[1]
(c) State the name of one other sorting algorithm that Poppy could have used.
[1]
14(a) The following pseudocode procedure performs an insertion sort on the array parameter.
01 procedure insertionSort(dataArray:byRef)
02 for i = 1 to dataArray.Length - 1
03 temp = dataArray[i]
04 tempPos = i – 1
05 exit = false
06 while tempPos >= 0 and exit == false
07 if dataArray[tempPos] < temp then
08 dataArray[tempPos + 1] = dataArray[tempPos]
09 tempPos = tempPos - 1
10 else
11 exit = true
Compare the use of merge sort, quick sort and insertion sort on an array with a small number of elements, and
on an array with a very large number of elements.
You should make reference to the time complexities of each algorithm using the Big O notation in your answer.
[6]
15(a) Identify one situation where a linear search is more appropriate than a binary search.
[1]
State a different type of loop that could be used instead of the while loop in the given algorithm.
[1]
Tick the worst-case space complexity for a binary and linear search.
Binary Linear
search search
O(log(n))
O(1)
O(n)
Tick the best-case space complexity for a binary and linear search.
Binary Linear
search search
O(log(n))
O(1)
O(n)
Tick the average time complexity for a binary and linear search.
Binary Linear
search search
O(log(n))
O(1)
O(n)
[6]
1 To locate an item (1) in a list (1). The 2 Up to 2 marks for a valid description.
list is in some order (1).
Total 2
b i 1 mark for each set of 2 moves 3 Allow follow through if one move is
incorrect
02174356
01274356 (1)
01247356
01234756 (1)
01234576
01234567 (1)
ii 1 mark per bullet to max 6 6 If no description i.e. the candidate has just
shown the quick sort, max 4 marks.
Uses divide-and-conquer (1)
First item becomes pivot / 2 is the pivot
(1)
Compare each item to the pivot (e.g.
compare 0 to 2, then 1 to 2) (1)
Make two lists, 1 with less than the
pivot… (0, 1) (1)
… 1 with more than the pivot
(7,4,3,5,6) (1)
Quick sort the new lists (1)
Recombine the sub-lists (1)
OR
Example of alternative quicksort method
marks for:
0 marks
No attempt to answer the question or
response is not worthy of credit.
Total 21
Total 6
Total 10
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 12
Examiner's Comments
Total 11
7 a Find the middle point in the list / 21 / 4 Some marks such as the comparison may
element 4 be by implication if the candidate’s logic
Compare it to the value 47, false works
Is 47 greater than middle point, true
New subset is 46-51 / change lower Must refer to the list given in the question
bound to 46 / element 5 i.e. not a generic description
Find the middle of the new subset / 47 /
element 6 Is this value equal to 47, true Examiner's Comments
Search finishes
In general, many candidates had an
understanding of how a binary search
operated. Unfortunately, some gave a
generic description rather than answering
the specific question which required the
candidate to illustrate how a binary search
would operate on a specific data set. Some
candidates drew concise and elegant
diagrams with appropriate annotations that
made their answers much clearer than
those who wrote prose at great length.
Examiner's Comments
Perform a linear search
Many candidates identified a linear search,
Description (Max 2) but fewer could give a full description as to
how a linear search operates. A number of
candidates confused searching with sorting
starting at the first element / each item algorithms.
is checked...
until value is found
or end of list reached and not found
Total 16
Insertion
Quick
Total 15
9 i 1 mark each 2
Examiner's Comment:
Most candidates knew that linear and
binary were the required types of search.
Some confused sorting algorithms with
searching algorithms.
ii If the algorithm name does not match the 5 For binary search, allow movement of
description given then max 4 marks for upper bound and lower bound instead of
description. making sub-lists
Binary
Linear
Examiner's Comment:
Most candidates could describe some
points related to the searching algorithm
they identified, but fewer could go on to
describe the steps in depth.
Total 7
Total 3
11 a i 1 mark for each correct item in bold 3 answers must be in the correct case as
AO1.1 given
(3) e.g. currentData
Examiner’s Comment:
Many candidates found it difficult to apply
the logic required to calculate the correct
solution. Stronger candidates could do so
even if they did not know the algorithm for
insertion sort.
ii 1 mark for contents of each row in table 6 … each row is dependent upon the
AO2.1 preceding row being correct
(6)
Examiner’s Comment:
Some candidates confused insertion sort
with other sorting algorithms, but many
candidates gave good answers in
diagrammatic form. Answers in
diagrammatic form after each pass of the
loop were often far clearer than prose
descriptions. This form of answer should
be encouraged.
b i O(n) 1
AO1.1
(1)
ii 1 mark per bullet to max 3 3 B(ii) dependent upon b(i) being correct
AO1.2 i.e. answers for O(n) only
(3)
The best case is for a sorted list (O(n))
As the number of elements increases Accept appropriate graph for bullet points
… the number of steps increases in a 2 and 3
linear fashion
Examiner’s Comment:
Whilst many candidates had some
knowledge of 'Big O' notation fewer could
apply it correctly within the context given.
Total 13
A02.1
(1)
Total 7
Mark Band 1 – Low Level (1-3 marks) The algorithm is easy to implement as
The candidate demonstrates a basic the number of lines of code is less than
knowledge of bubble sorts with limited other standard sorting algorithms.
understanding shown; the material is basic Although a bubble sort will be able to
and contains some inaccuracies. The sort the items into order, it will take
candidates makes a limited attempt to longer than other sorting algorithms
apply acquired knowledge and due to the number of items and the
understanding to the context provided. The current order or items in the unsorted
candidate provides nothing more than an list.
unsupported assertion.The information is
0 marks
No attempt to answer the question or
response is not worthy of credit.
b 249,999 1
A02.2
(1)
Total 11
14 a Mark Band 3 – High level (7-9 marks) 9 AO1: Knowledge and Understanding
The candidate demonstrates a thorough AO1.1 Indicative content
knowledge and understanding of big O and (2) O(1)
sorting algorithms; the material is generally AO1.2
accurate and detailed. (2) Constant space, does not change
The candidate is able to apply their AO2.1
knowledge and understanding directly and (2) O(n)
consistently to the context provided. AO3.3
Evidence/examples will be explicitly (3) Linear
relevant to the explanation. Same as number of elements
The candidate is able to weigh up the use As number of elements increases so
of the sorting algorithms which results in a does the time/space
supported and realistic judgment as to
whether it is possible to use them in this O(n2)
context.
There is a well-developed line of reasoning polynominal
which is clear and logically structured. The As number of elements increases,
information presented is relevant and time/space increases by *n
substantiated.
O(n log(n))
Mark Band 2 – Mid level (4-6 marks)
The candidate demonstrates reasonable Linearithmic
knoledge and understanding of big O and
sorting algorithms; the material is generally
accurate but at times underdeveloped. AO2: Application
The candidate is able to apply their
knowledge and understanding directly to Space: Merge sort will require more
the context provided although one or two memory usage as the number of
opportunities are missed. elements increases. Insertion will not
Evidence/examples are for the most part require any more space than original.
implicitly relevant to the explanation. Quick will increase but not as much as
The candidate makes a reasonable merge.
attempt to come to a conclusion showing Best time: Insertion increases at the
some recognition of influencing factors that same rate as the number of elements.
would determine whether it is possible to Quick and merge increase at greater
use the sorting algorithms in this context. rate
There is a line of reasoning presented with Worst time: insertion and quick
some structure. The information presented increase significantly by n for each
is in the most part relevant and supported additional item. Merge sort increases
by some evidence less per element.
Log more appropriate for large number
Mark Band 1 – Low Level (1-3 marks) of elements
The candidate demonstrates a basic
knowledge of big O and sorting algorithms AO3: Evaluation
with limited understanding shown; the e.g.
material is basic and contains some
inaccuracies. The candidates makes a Small array – space is not important.
limited attempt to apply acquired Few number of elements. Look for
knowledge and understanding to the consistency.
0 marks
No attempt to answer the question or
response is not worthy of credit.
Total 15
Binary Linear
search search
O(log(n))
O(1) ✓ ✓
O(n)
Best-case space complexity:
Binary Linear
search search
O(log(n))
O(1) ✓ ✓
O(n)
Binary Linear
search search
O(log(n)) ✓
O(1)
O(n) ✓
Total 14