sorting; binary search; algorithms in · pdf filecity of london academy 1 sorting; binary...

37
City of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to try to locate the name NIGEL in the following alphabetical list. Clearly indicate how you chose your pivots and which part of the list is being rejected at each stage. 1. Bhavika 2. Clive 3. Elizabeth 4. John 5. Mark 6. Nicky 7. Preety 8. Steve 9. Trevor 10. Verity (Total 4 marks) 2. 650 431 245 643 455 134 710 234 162 452 (a) The list of numbers above is to be sorted into descending order. Perform a Quick Sort to obtain the sorted list, giving the state of the list after each pass, indicating the pivot elements. (5) The numbers in the list represent the lengths, in mm, of some pieces of wood. The wood is sold in one metre lengths. (b) Use the first-fit decreasing bin packing algorithm to determine how these pieces could be cut from the minimum number of one metre lengths. (You should ignore wastage due to cutting.) (4) (c) Determine whether your solution to part (b) is optimal. Give a reason for your answer. (2) (Total 11 marks) 3. Hajra (H) Vicky (V) Leisham (L) Alice (A) Nicky (N) June (J) Sharon (S) Tom (T) Paul (P) The table shows the names of nine people. (a) Use a quick sort to produce the list of names in ascending alphabetical order. You must make your pivots clear. (4) (b) Use the binary search algorithm on your list to locate the name Paul. (4) (Total 8 marks)

Upload: buituyen

Post on 12-Mar-2018

241 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 1

SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS

1. Use the binary search algorithm to try to locate the name NIGEL in the following alphabetical list.

Clearly indicate how you chose your pivots and which part of the list is being rejected at each

stage.

1. Bhavika

2. Clive

3. Elizabeth

4. John

5. Mark

6. Nicky

7. Preety

8. Steve

9. Trevor

10. Verity

(Total 4 marks)

2. 650 431 245 643 455 134 710 234 162 452

(a) The list of numbers above is to be sorted into descending order. Perform a Quick Sort to

obtain the sorted list, giving the state of the list after each pass, indicating the pivot

elements. (5)

The numbers in the list represent the lengths, in mm, of some pieces of wood. The wood is sold in

one metre lengths.

(b) Use the first-fit decreasing bin packing algorithm to determine how these pieces could be

cut from the minimum number of one metre lengths. (You should ignore wastage due to

cutting.) (4)

(c) Determine whether your solution to part (b) is optimal. Give a reason for your answer. (2)

(Total 11 marks)

3.

Hajra

(H)

Vicky

(V)

Leisham

(L)

Alice

(A)

Nicky

(N)

June

(J)

Sharon

(S)

Tom

(T)

Paul

(P)

The table shows the names of nine people.

(a) Use a quick sort to produce the list of names in ascending alphabetical order.

You must make your pivots clear. (4)

(b) Use the binary search algorithm on your list to locate the name Paul. (4)

(Total 8 marks)

Page 2: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 2

4. 41 28 42 31 36 32 29

The numbers in the list represent the weights, in kilograms, of seven statues. They are to be

transported in crates that will each hold a maximum weight of 60 kilograms.

(a) Calculate a lower bound for the number of crates that will be needed to transport the

statues. (2)

(b) Use the first-fit bin packing algorithm to allocate the statues to the crates. (3)

(c) Use the full bin algorithm to allocate the statues to the crates. (2)

(d) Explain why it is not possible to transport the statues using fewer crates than the number

needed for part (c). (2)

(Total 9 marks)

5. A builder is asked to replace the guttering on a house. The lengths needed, in metres, are

0.6, 4.0, 2.5, 3.2, 0.5, 2.6, 0.4, 0.3, 4.0 and 1.0

Guttering is sold in 4 m lengths.

(a) Carry out a quick sort to produce a list of the lengths needed in descending order. You

should show the result of each pass and identify your pivots clearly. (5)

(b) Apply the first-fit decreasing bin-packing algorithm to your ordered list to determine the

total number of 4 m lengths needed. (4)

(c) Does the answer to part (b) use the minimum number of 4 m lengths? You must justify your

answer. (2)

(Total 11 marks)

Page 3: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 3

6.

An algorithm is described by the flowchart shown in the diagram above.

(a) Given that S = 25 000, complete the table in the answer book to show the results obtained at

each step when the algorithm is applied.

You may not need to use all the lines in this table

Page 4: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 4

S T R R>0? Output

(5)

This algorithm is designed to model a possible system of income tax, T, on an annual salary, £S.

(b) Write down the amount of income tax paid by a person with an annual salary of £ 25 000. (1)

(c) Find the maximum annual salary of a person who pays no tax. (1)

(Total 7 marks)

7. 32 45 17 23 38 28 16 9 12 10

The numbers in the list above represent the lengths, in metres, of ten lengths of fabric. They are to

be cut from rolls of fabric of length 60m.

(a) Calculate a lower bound for the number of rolls needed. (2)

(b) Use the first-fit bin packing algorithm to determine how these ten lengths can be cut from

rolls of length 60m. (4)

(c) Use full bins to find an optimal solution that uses the minimum number of rolls. (3)

(Total 9 marks)

Page 5: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 5

8. Miri

Jessie

Edward

Katie

Hegg

Beth

Louis

Philip

Natsuko

Dylan

(a) Use the quick sort algorithm to sort the above list into alphabetical order. (5)

(b) Use the binary search algorithm to locate the name Louis. (4)

(Total 9 marks)

9. Max Lauren John Hannah Kieran Tara Richard Imogen

(a) Use a quick sort to produce a list of these names in ascending alphabetical order. You must

make your pivots clear. (5)

(b) Use the binary search algorithm on your list from part (a) to try to locate the name „Hugo‟. (4)

(Total 9 marks)

10. 29 52 73 87 74 47 38 61 41

The numbers in the list represent the lengths in minutes of nine radio programmes. They are to be

recorded onto tapes which each store up to 100 minutes of programmes.

(a) Obtain a lower bound for the number of tapes needed to store the nine programmes. (2)

(b) Use the first-fit bin packing algorithm to fit the programmes onto the tapes. (3)

(c) Use the first-fit decreasing bin packing algorithm to fit the programmes onto the tapes. (3)

(Total 8 marks)

Page 6: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 6

11.

An algorithm is described by the flow chart shown above.

(a) Given that x = 54 and y = 63, complete the table below to show the results obtained at each

step when the algorithm is applied.

You may not need to use all of these rows.

It may not be necessary to complete all boxes in each row.

Start

Let A = 0

Input x, y

x = x - 1

Is = 0?x

Output A

Stop

x = x ÷ 2

y = y2

No

No

Yes

Yes

Is even?

x A = A + y

Page 7: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 7

A x y x even? x = 0 ?

(7)

(b) State what the algorithm achieves. (2)

(Total 9 marks)

Page 8: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 8

12. Use the binary search algorithm to try to locate the name NIGEL in the following alphabetical list.

Clearly indicate how you chose your pivots and which part of the list is being rejected at each

stage.

1. Bhavika

2. Clive

3. Elizabeth

4. John

5. Mark

6. Nicky

7. Preety

8. Steve

9. Trevor

10. Verity (Total 4 marks)

13. 52 48 50 45 64 47 53

The list of numbers above is to be sorted into descending order. Perform a bubble sort to obtain

the sorted list, giving the state of the list after each completed pass. (Total 4 marks)

Page 9: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 9

14.

An algorithm is described by the flow chart shown in the figure above.

(a) Complete the table below recording the results of each step as the algorithm is applied.

(Notice that values of A, B, C and D are to be given to 3 decimal places, and the values of E

to 1 significant figure.)

You may not need to use all the rows in this table.

Let = 0

Let = (1 + 2, to 3 decimal places.

Let = (1 –

n

A

B

5) ÷

÷ 2, to 3 decimal places.

Let = + 1n n

Let = , to 3 decimal places.Let

C AD =

, to 3 decimal places.B

Let ( ) ÷E = C – D 5, to 1 significant figure

Output E

n

n

Start

Stop

Isn > 4?

Yes

No

Page 10: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 10

A B n C D E

(8)

(b) Write down the output from the algorithm. (1)

(Total 9 marks)

15.

Ali 74

Bobby 28

Eun-Jung 63

Katie 54

Marciana 54

Peter 49

Rory 37

Sophie 68

The table shows the marks obtained by students in a test. The students are listed in alphabetical

order. Carry out a quick sort to produce a list of students in descending order of marks. You

should show the result of each pass and identify your pivots clearly. (Total 5 marks)

16. 650 431 245 643 455 134 710 234 162 452

(a) The list of numbers above is to be sorted into descending order. Perform a Quick Sort to

obtain the sorted list, giving the state of the list after each pass, indicating the pivot

elements. (5)

The numbers in the list represent the lengths, in mm, of some pieces of wood. The wood is sold in

one metre lengths.

(b) Use the first-fit decreasing bin packing algorithm to determine how these pieces could be

cut from the minimum number of one metre lengths. (You should ignore wastage due to

cutting.) (4)

Page 11: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 11

(c) Determine whether your solution to part (b) is optimal. Give a reason for your answer. (2)

(Total 11 marks)

17. 45, 56, 37, 79, 46, 18, 90, 81, 51

(a) Using the quick sort algorithm, perform one complete iteration towards sorting these

numbers into ascending order. (2)

(b) Using the bubble sort algorithm, perform one complete pass towards sorting the original

list into descending order. (2)

Another list of numbers, in ascending order, is

7, 23, 31, 37, 41, 44, 50, 62, 71, 73, 94

(c) Use the binary search algorithm to locate the number 73 in this list. (4)

(Total 8 marks)

18.

1. Glasgow

2. Newcastle

3. Manchester

4. York

5. Leicester

6. Birmingham

7. Cardiff

8. Exeter

9. Southampton

10. Plymouth

A binary search is to be performed on the names in the list above to locate the name Newcastle.

(a) Explain why a binary search cannot be performed with the list in its present form. (1)

(b) Using an appropriate algorithm, alter the list so that a binary search can be performed. State

the name of the algorithm you use. (4)

(c) Use the binary search algorithm on your new list to locate the name Newcastle. (4)

(Total 9 marks)

Page 12: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 12

19.

The diagram above describes an algorithm in the form of a flow chart, where a is a positive

integer.

List P, which is referred to in the flow chart, comprises the prime numbers 2, 3, 5, 7, 11, 13, 17, ...

(a) Starting with a = 90, implement this algorithm. Show your working in the table below.

You may not need to use all the rows in this table.

START

Input a

Is an integer?

c

Output b

Is = ?a b

END

Increase tonext integer

in List

b

P

Let =a c

YES

YES

NO

NO

Let = First number in List b P

Let =c ab

List : 2, 3, 5, 7, 11, 13, …P

Page 13: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 13

a b c Integer? Output

List

a = b?

(7)

(b) Explain the significance of the output list. (2)

(c) Write down the final value of c for any initial value of a. (1)

(Total 10 marks)

20. Nine pieces of wood are required to build a small cabinet. The lengths, in cm, of the pieces of

wood are listed below.

20, 20, 20, 35, 40, 50, 60, 70, 75

Planks, one metre in length, can be purchased at a cost of £3 each.

(a) The first fit decreasing algorithm is used to determine how many of these planks are to be

purchased to make this cabinet. Find the total cost and the amount of wood wasted. (5)

Planks of wood can also be bought in 1.5 m lengths, at a cost of £4 each. The cabinet can be built

using a mixture of 1 m and 1.5 m planks.

(b) Find the minimum cost of making this cabinet. Justify your answer. (4)

(Total 9 marks)

21. The following list gives the names of some students who have represented Britain in the

International Mathematics Olympiad.

Roper (R), Palmer (P), Boase (B), Young (Y), Thomas (T), Kenney (K), Morris (M),

Halliwell (H), Wicker (W), Garesalingam (G).

(a) Use the quick sort algorithm to sort the names above into alphabetical order.

Page 14: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 14

(5)

(b) Use the binary search algorithm to locate the name Kenney. (4)

(Total 9 marks)

22. 25 22 30 18 29 21 27 21

The list of numbers above is to be sorted into descending order.

(a) (i) Perform the first pass of a bubble sort, giving the state of the list after each exchange.

(ii) Perform further passes, giving the state of the list after each pass, until the

algorithm terminates. (5)

The numbers represent the lengths, in cm, of pieces to be cut from rods of length 50 cm.

(b) (i) Show the result of applying the first fit decreasing bin packing algorithm to this

situation.

(ii) Determine whether your solution to (b) (i) has used the minimum number of 50 cm

rods. (4)

(Total 9 marks)

23. This question should be answered on the page below.

Start

A = 1

B =

Is anBinteger?

Yes

Yes

Print A

Is = 60?A

End

No

No

A A = + 160A

Page 15: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 15

Implement the algorithm given by the flow chart above and state what the algorithm actually

produces. (Total 5 marks)

Sheet for use in answering this question

Is B = an integer?

A Yes or No A Yes or No

1 31

2 32

3 33

4 34

5 35

6 36

7 37

8 38

9 39

10 40

11 41

12 42

13 43

14 44

15 45

16 46

17 47

18 48

19 49

20 50

21 51

22 52

23 53

24 54

25 55

26 56

27 57

28 58

29 59

30 60

What the algorithm produces:

…………………………………………………………………………………………………

…………………………………………………………………………………………………

…………………………………………………………………………………………………

A

60

Page 16: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 16

MARK SCHEME

1. = 6 Nicky M1

reject top of list

= 9 Trevor A1

reject bottom of list

= 8 Steve A1

reject bottom of list

[7] = 7 Preety A14

reject

Nigel not in list [4]

2. (a) E.g:

650 431 245 643 455 710 234 162 452 134 M1

650 643 710 455 431 245 234 162 452 134 A1

650 710 643 455 431 245 452 234 162 134 A1 ft

710 650 643 455 431 452 245 234 162 134 A1 ft

710 650 643 455 452 431 245 234 162 134 A1

5

(b) Bin 1 710 + 245 Bin 3 643 + 162 + 134 Bin 5 431 M1A1

Bin 2 650 + 234 Bin 4 455 + 452 A1A1(ft)4

(c) = 4.116 5 bins needed optimal M1A1(ft)2

[11]

3. (a)

H V L A N J S T P (N) M1

H L A J N V S T P (A, T) A1

A H L J N S P T V (L, P) A1 ft

A H J L N P S T V (J)

A H J L N P S T V A1 cso 4

2

101

2

107

2

87

1000

4116

Page 17: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 17

Note

1M1: quick sort, pivots, p, chosen and two sublists one <p one >p.

1A1: first pass correct and next pivots chosen correctly/consistently.

2A1ft: second pass correct, next pivots correctly/consistently chosen.

3A1: all correct, cso.

(b) 1st choice Nicky, reject 1 – 5 M1 A1

2nd

choice Tom, reject 8 – 9 A1

3rd

choice Sharon, reject 7

4th

choice 6 Paul name found A1 cso4

Note

1M1: binary search on what they think is a alphabetical list, choosing

pivot, rejecting half list.

1A1: first pass correct, condone „sticky‟ pivot here, bod generous

2A1: second pass correct, pivot rejected.

3A1: cso.

Note: If incorrect list in (a) mark (b) as a misread.

Alternative solutions

Middle right

H V L A N J S T P (N) M1

H L A J N V S T P (A T) A1

A H L J N S P T V (L P) A1ft

A H J L N P S T V (J)

A H J L N P S T V A1cso

list sorted

Middle left

H V L A N J S T P (N) M1

H L A J N V S T P (L S) A1

H A J L N P S V T (A V) A1ft

A H J L N P S T V (H)

A H J L N P S T V A1cso

1 95

2

6 9

7.5 82

6 7

6.5 72

Page 18: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 18

First

H V L A N J S T P (H) M1

A H V L N J S T P (V) A1

A H L N J S T P V (L)

A H J L N S T P V (N) A1ft

A H J L N S T P V (S)

A H J L N P S T V A1cso

[8]

4. (a) e.g. total weight is 239, lower bound is so 4 bins. M1 A12

Note

1M1: Any correct statement, must involve calculation

1A1: cao (accept 4 for both marks)

(b) Bin 1 : 41 Bin 4 : 36 M1 A1

Bin 2 : 28 + 31 Bin 5 : 32 A13

Bin 3 : 42 Bin 6 : 29

Note

1M1: Bins 1 and 2 correct and at least 6 values put in bins

1A1: Bins 1, 2, 3 and 4 correct.

2A1: All correct

Misread in (b) First Fit Decreasing

Bin 1: 42 Bin 2: 41 Bin 3: 36 Bin 4: 32 28 Bin 5: 31 29

(Remove up to two A marks if earned – so M1 max in (b) if first 4

bins correct.)

(c) Full Bins : 28 + 32 31 + 29 M1 A12

The other 3 items (42, 41, 36) require 3 separate bins

Note

1M1: Attempt to find two full bins and allocate at least 6 values

1A1: cao

(d) There are 5 items over 30. No two of these 5 can be paired B2, 1, 02

in a bin, so at least 5 bins will be required.

Note

1B1: Correct argument may be imprecise or muddled (bod gets B1)

2393.98

60

Page 19: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 19

2B1: A good, clear, correct argument. (They have answered

the question „why?‟) [9]

5. (a)

0.6 4.0 2.5 3.2 0.5 2.6 0.4 0.3 4.0 1.0 2.6

4.0 3.2 4.0 2.6 0.6 2.5 0.5 0.4 0.3 1.0 3.2 0.4 M1

4.0 4.0 3.2 2.6 0.6 2.5 0.5 1.0 0.4 0.3 4.0 0.5 A1

4.0 4.0 3.2 2.6 0.6 2.5 1.0 0.5 0.4 0.3 2.5 A1ft

4.0 4.0 3.2 2.6 2.5 0.6 1.0 0.5 0.4 0.3 1.0 A1ft

4.0 4.0 3.2 2.6 2.5 1.0 0.6 0.5 0.4 0.3 A1 cso 5

Notes

1M1 Pivot, p, chosen. List sorted, >p, p.

<p or <p, p, >p. If only choosing 1

pivot per iteration M1 only

1A1 1st pass correct and chosen next two

pivots correctly for sublists >1

2A1ft 2nd

pass correct and chosen next two

pivots correctly for sublists >1

3A1ft 3rd

pass correct and next pivot for

sublist >1 chosen correctly.

4A1 cso.

Misread in part (a)

• If they have misread a number at

the start of part (a), so genuinely miscopied and got for example 0.1

instead of 1.0 then mark the whole

question as a misread – removing the

last two A or B marks earned. This

gives a maximum total of 9.

• If they misread their own numbers

during the course of part (a) then count

it as an error in part (a) but mark parts

(b) and (c) as a misread. So they would

lose marks in (a) for the error and then

the last two A or B marks earned in (b)

and (c) – giving a maximum of 8 or maybe

7 marks depending on how many marks

they lose in (a).

The most popular misread is the one listed above – where

1.0 has changed to 0.1 giving

Page 20: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 20

4.0 4.0 3.2 2.6 2.5 0.6 0.5 0.4 0.3 0.1 at the end of (a) for

this one (b) and (c)

are:

(b) Length 1: 4

Length 2: 4

Length 3: 3.2 0.6 left column & 1.0 in place M1

Length 4: 2.6 1.0 0.4 0.6 & 0.5 A1

Length 5: 2.5 0.5 0.3 0.4 A1

All correct (c.s.o) A14

Note

Length 1: 4

Length 2: 4

Length 3: 3.2 0.6 0.1

Length 4: 2.6 0.5 0.4 0.3

Length 5: 2.5

(c) 19.1/4 = 4.775 so 5 lengths needed, accept

total is 19.1m, or refer to 0.9 „spare . B1

Yes, the answer to (b) does use the minimum

number of bins. DB12

Note

18.2/4 = 4.55 so 5 bins, or total is 18.2 or 1.8 „spare‟

Yes answer in (b) uses the minimum number of bins.

Alternate

Choosing middle left

0.6 4.0 2.5 3.2 0.5 2.6 0.4 0.3 4.0 1.0 (pivot 0.5)

0.6 4.0 2.5 3.2 2.6 4.0 1.0 0.5 0.4 0.3 (pivots 3.2, 0.4)

4.0 4.0 3.2 0.6 2.5 2.6 1.0 0.5 0.4 0.3 (pivots 4.0, 2.5)

4.0 4.0 3.2 2.6 2.5 0.6 1.0 0.5 0.4 0.3 (pivot 0.6)

4.0 4.0 3.2 2.6 2.5 1.0 0.6 0.5 0.4 0.3

4.0 4.0 3.2 2.6 2.5 1.0 0.6 0.5 0.4 0.3

Page 21: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 21

Choosing first

0.6 4.0 2.5 3.2 0.5 2.6 0.4 0.3 4.0 1.0 (pivot 0.6)

4.0 2.5 3.2 2.6 4.0 1.0 0.6 0.5 0.4 0.3 (pivots 4.0, 0.5)

4.0 2.5 3.2 2.6 4.0 1.0 0.6 0.5 0.4 0.3 (pivots 2.5, 0.4)

4.0 3.2 2.6 4.0 2.5 1.0 0.6 0.5 0.4 0.3 (pivot 3.2)

4.0 4.0 3.2 2.6 2.5 1.0 0.6 0.5 0.4 0.3

4.0 4.0 3.2 2.6 2.5 1.0 0.6 0.5 0.4 0.3

OR (alternate choosing first)

0.6 4.0 2.5 3.2 0.5 2.6 0.4 0.3 4.0 1.0 (pivot 0.6)

4.0 2.5 3.2 2.6 4.0 1.0 0.6 0.5 0.4 0.3 (pivots 4.0, 0.5)

4.0 4.0 2.5 3.2 2.6 1.0 0.6 0.5 0.4 0.3 (pivots 2.5, 0.4)

4.0 4.0 3.2 2.6 2.5 1.0 0.6 0.5 0.4 0.3 (pivots 3.2)

4.0 4.0 3.2 2.6 2.5 1.0 0.6 0.5 0.4 0.3

4.0 4.0 3.2 2.6 2.5 1.0 0.6 0.5 0.4 0.3

Sorting into ASCENDING order (full marks if then reversed, otherwise MISREAD)

Middle left

0.6 4.0 2.5 3.2 0.5 2.6 0.4 0.3 4.0 1.0 (pivot 0.5)

0.4 0.3 0.5 0.6 4.0 2.5 3.2 2.6 4.0 1.0 (pivots 0.4, 3.2)

0.3 0.4 0.5 0.6 2.5 2.6 1.0 3.2 4.0 4.0 (pivots 2.5, 4.0)

0.3 0.4 0.5 0.6 1.0 2.5 2.6 3.2 4.0 4.0 (pivot 0.6)

0.3 0.4 0.5 0.6 1.0 2.5 2.6 3.2 4.0 4.0

Middle right

0.6 4.0 2.5 3.2 0.5 2.6 0.4 0.3 4.0 1.0 (pivot 2.6)

0.6 2.5 0.5 0.4 0.3 1.0 2.6 4.0 3.2 4.0 (pivots 0.4, 3.2)

0.3 0.4 0.6 2.5 0.5 1.0 2.6 3.2 4.0 4.0 (pivots 0.5, 4.0)

0.3 0.4 0.5 0.6 2.5 1.0 2.6 3.2 4.0 4.0 (pivot 2.5)

0.3 0.4 0.5 0.6 1.0 2.5 2.6 3.2 4.0 4.0 (pivot 1.0)

First (1)

0.6 4.0 2.5 3.2 0.5 2.6 0.4 0.3 4.0 1.0 (pivot 0.6)

0.5 0.4 0.3 0.6 4.0 2.5 3.2 2.6 4.0 1.0 (pivots 0.5, 4.0)

0.4 0.3 0.5 0.6 2.5 3.2 2.6 1.0 4.0 4.0 (pivots 0.4, 2.5)

0.3 0.4 0.5 0.6 1.0 2.5 3.2 2.6 4.0 4.0 (pivot 3.2)

0.3 0.4 0.5 0.6 1.0 2.5 2.6 3.2 4.0 4.0

First (2)

0.6 4.0 2.5 3.2 0.5 2.6 0.4 0.3 4.0 1.0 (pivot 0.6)

0.5 0.4 0.3 0.6 4.0 2.5 3.2 2.6 4.0 1.0 (pivots 0.5, 4.0)

0.4 0.3 0.5 0.6 2.5 3.2 2.6 1.0 4.0 4.0 (pivots 0.4, 2.5)

0.3 0.4 0.5 0.6 1.0 2.5 3.2 2.6 4.0 4.0 (pivot 3.2)

0.3 0.4 0.5 0.6 1.0 2.5 2.6 3.2 4.0 4.0 [11]

Page 22: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 22

6. (a)

S T R R>0? Output

25000 0 17000 Y Line 1

3400 Line 2

7000 Line 3

Y Line 4

4450 Line 5

–5000 Line 6

n Line 7

4450

Lines 1 & 2: M1A1

Lines 3-7: M1A1

Output correct: A15

(b) Tax on £25 000 is £4450 B1ft1

(c) Tax free sum = £8000: B11 [7]

7. (a) M1 A12

Note

1M1: Their 230 divided by 60, some evidence

of correct method 3.8 enough.

1A1: cso 4.

(b) Bin 1: 32 17 9 M1 A1

Bin 2: 45 12 A1

Bin 3: 23 28 A14

Bin 4: 38 16

Bin 5: 10

needed4so38.360

230

Page 23: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 23

Note

1M1: Use of first fit. Probably 32, 45 and

17 correctly placed.

1A1: 32, 45, 17, 23, 38 and 28 placed correctly

2A1: 32, 45, 17, 23, 38, 28, 16, 9 placed correctly.

3A1: cao

Special case for (b) misread using first fit decreasing.

Give M1A1 (max)

Bin 1: 45 12

Bin 2: 38 17

Bin 3: 32 28

Bin 4: 23 16 10 9

M1 for placing 45, 38, 32, 28 and 23 correctly

A1 for cao.

(c) e.g. Bin 1: 32 28

Bin 2: 38 12 10 M1 A1

Bin 3: 45 9

Bin 4: 23 17 16 A13

Note

1M1: Use of full bin – at least one full bin

found and 5 numbers placed.

1A1: 2 full bins found

Eg [32+28 and 38+12+10] [23+28+9 and 16+12+32]

[32+28 and 23+16+12+9] [38+12+10 and 23+28+9]

2A1: A 4 bin solution found. [9]

8. (a)

M J E K H B L P N D B M1 1A1

B M J E K H L P N D H

B E D H M J K L P N D L 2A1ft

Page 24: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 24

B D E H J K L M P N (E) K P

B D E H J K L M N P (J) N 3A1ft

B D E H J K L M N P (M)

Sort completed 4A15

Note

1M1: quick sort, pivots, p, identified,

two sublists one <p one >p.

If choosing one pivot only per iteration,

M1 only.

1A1: first pass correct, next pivot(s)

chosen consistently.

2A1ft: second pass correct, next pivot(s)

chosen consistently

3A1ft: third pass correct, next pivot(s)

chosen consistently

4A1: cso List re-written or end statement

made or each element been chosen

as a pivot.

(b) Katie reject left M1

Natsuko reject right 1A1

Miri reject right 2A1ft

7 = Louis name found 3A14

Note

1M1: binary search, choosing pivot rejecting

half list.

If using unordered list then M0.

If choosing J M1 ony

1A1: first two passes correct, condone

„sticky‟pivots here, bod.

2A1ft: third pass correct, pivots rejected.

62

101

92

107

82

87

Page 25: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 25

3A1: cso, including success statement.

Special case

If just one letter out of order, award

maximum of M1A1A0A0 [9]

9. (a) e.g.

M L J H K T R I M1

J H I K M L T R A1

H J I K M L R T A1ft

H I J K L M R T A1ft

H I J K L M R T A1cso 5

Note

1M1: quick sort, pivots, p, chosen and two sublists one <p one >p.

If choosing 1 pivot per iteration only M1 only.

1A1: first pass correct and next pivots chosen correctly/consistently.

2A1ft: second pass correct, next pivots correctly/consistently chosen.

3A1ft: third pass correct, next pivots correctly/consistently chosen.

4A1: all correct, cso.

(b) Sort complete.

1st choice 5 Lauren reject right M1 A1

2nd

choice 3 John reject right

3rd

choice 2 Imogen reject right A1ft

4th

choice 1 Hannah reject

List now empty so Hugo not in list A14

Note

1M1: binary search, choosing pivot, rejecting half list. If using unsorted

list, M0. Accept choice of K for M1 only.

1A1: first pass correct, condone „sticky‟pivot here, bod.

2A1ft: second pass correct, pivot rejected.

3A1: cso. [9]

10. (a) = 5.02 so 6 tapes. Ml

2

81

2

41

2

21

100

502

Page 26: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 26

Al 2

1M1 (502 ±40) ÷ 100 (maybe implicit)

1A1: cao 6 tapes

(b) Bin l: 29, 52 Bin 5: 47,38 Ml

Bin 2: 73 Bin 6: 61

Bin 3: 87 Bin 7: 41 Al

Bin 4: 74 Al 3

1M1 Bin 1 correct and at least 8 values put in bins

1A1: Condone one error, (e.g. extra, omission, „balanced‟ swap).

2A1: All correct

(c) Binl: 87 Bin 4: 61,38 M1

Bin 2: 74 Bin 5: 52,47 A1

Bin 3: 73 Bin6: 41,29 Al 3

1M1 Bin 1 correct and at least 8 values put in bins

1A1: Condone one error, (e.g. extra, omission, „balanced‟ swap).

2A1: All conect [8]

Natsuko reject right 1A1

11.

(a)

A x y x even? x = 0?

0 54 63 Y M1A1

27 126 N

126 26 N A1ft

13 252 N

378 12 N M1

6 504 Y

3 1008 N A1ft

1386 2 N

1 2016 N

3402 0 Y A1

A = 3402 B1ft7

(b) The product xy. B2,1,02 [9]

82

87

Page 27: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 27

12. = 6 Nicky – reject top of list. M1

= 9 Trevor – reject bottom of list A1

= 8 Steve – reject bottom of list A1

[7] = 7 Preety – reject A1

Nigel not in list [4]

13. e.g. 52 48 50 45 64 47 53 M1

52 50 48 54 47 53 45

52 50 54 48 53 47 45 A1

52 54 50 53 48 47 45

64 52 53 50 48 47 45 A1ft

64 53 52 50 48 47 45 A1 4

No further changes – list sorted

M1 Bubble sort – 1st pass complete – end term 64 or 45,

consistent L R or R L shuffle, Quick etc gets M0

A1 First 2 passes correct} condone shrinking list

A1ft Next 2 passes correct (if L R next pass} condone shrinking list

A1 Final pass and final statement/rewritten list cso – must see whole list [4]

Notes

Bubble R L

52 48 50 45 64 47 53 M1

64 52 48 50 45 53 47

64 53 52 48 50 45 47 A1

64 53 52 50 48 47 45 A1

No further changes – list sorted A1

2

101

2

107

2

87

Page 28: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 28

Misreads – sorting into ascending order

(note – if candidates reverse list full credit is gained.

L R (ascending – misread) MR

52 48 50 45 64 47 53 M1

48 50 45 52 47 53 64

48 45 50 47 52 53 64 A1

45 48 47 50 52 53 64

45 47 48 50 52 53 64 A1

No further changes – list sorted A1

(4-2 for misread)

R L

52 48 50 45 64 47 53 M1

45 52 48 50 47 64 53

45 47 52 48 50 53 64 A1

45 47 48 52 50 53 64

45 47 48 50 52 53 64 A1

No further changes – list sorted A1

(4-2 for misread)

14. A B n C D E M1

1.618 –0.618 1 1.618 –0.618 1 A1 A1 3

2 2.618 0.382 1 M1 A1ft

3 4.236 –0.236 2 A1ft

4 6.854 0.146 3 A1

5 11.089 –0.090 5 A1 5

Output : 1, 1, 2, 3, 5 A1ft 1 [9]

15. e.g. 4

74

74

74

74

74

74

28

63

63

68

68

68

63

54

68

63

63

54

68

54

54

54

54

54

49

28

49

49

37

49

28

37

37

68

37

37

28

28

28

54

54

63

68

M1

A1

A1ft

A1

49

37

(28)

sort complete

Page 29: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 29

Ali, Sophie, Eun–Jung, {Katie + Marciana}, Peter, Rory, Bobby A1

M1 Pivot clear list > P >. Bubble sort etc. M0

A1 1st pass correct, next pivots correctly selected

consistently

A1ft 2nd

+ 3rd

passes correct, pivots for next pan selected

consistently each time. Penalise fragmented list here

(or lists rewritten or all chosen as pivots)

A1 c.s.o. + stop statement (o.e.). Penalise non-sig no.

errors here. Penalise “sloppyness” here

A1 c.a.o. accept c.a. even if MR [5]

Alternative correct answers

(i)

(ii)

(iii)

1st in list

(iv)

74

74

74

74

28

63

68

68

63

68

63

54

54

54

28

54

54

49

54

49

37

49

28

37

68

37

37

28

54

63

68

M1

A1

A1ft

49

37 (54)

74

74

74

74

28

63

68

68

63

54

63

54

68

54

54

54

54

49

28

49

37

49

28

37

68

37

37

28

54

63

74

M1

A1

A1ft

49

28 (54)

74

74

74

74

28

63

68

68

63

68

63

54

54

54

28

54

49

54

28

49

37

49

49

28

37

68

37

37

37

28

54

63

74

M1

A1

A1ft

54

49

28 (68)

(37)

Page 30: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 30

Ali, Sophie, Eun-Jung, Katie + Marciana, Peter, Rory, Bobby

MISREADS (–2 for MR)

(a)

(b)

(c)

(d)

74

74

74

28

28

63

68

68

68

63

63

54

63

63

54

54

54

54

54

54

54

54

49

54

54

54

54

49

49

37

49

49

49

49

49

37

37

68

37

37

37

37

37

68

68

28

28

74

28

63

(68) 54

54

49

(37)

M1

A1ft

A1

74

28

28

28

28

54

37

37

63

49

49

54

37

54

54

54

54

49

74

63

37

63

74

68

68

68

68

74

54

49

37

M1

A1

A1ft

63

68 (54)

MR

74

28

28

28

28

49

37

37

63

37

49

54

54

54

74

54

49

63

74

63

37

54

63

74

68

68

68

68

68

74

54

49

37

68

M1

A1

A1ft

54

63

(28)

MR

74

28

28

28

28

28

54

49

37

37

63

49

37

49

54

37

54

54

54

49

74

63

37

63

74

68

68

68

68

74

54

54

49

28

M1

A1

A1ft

63

74

MR

Page 31: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 31

If candidates reverse list then restore full marks.

names or numbers

Bobby, Rory, Peter, Katie + Marciana, Eun-Jung, Sophie, Ali

16. (a) E.g. M1 A1 A1ft A1ft A1 5

(b) Bin 1 710 + 245 Bin 3 643 + 162 + 134 Bin 5 431 M1 A1

Bin 2 650 + 234 Bin 4 455 + 452 A1ft A1 4

(c) eg.

= 4.116 5 bins needed optimal M1 A1ft 2

[11]

17. (a) eg. 45 37 18 56 79 90 81 51

or 37 18 56 79 46 90 81 51

or 45 37 46 18 56 79 90 81 M1A1 2

(b) 56 45 79 46 37 90 81 51 18

or 90 45 56 37 79 46 18 81 51 M1A1 2

(c) = 6 value 44 discard top M1

= 9 value 71 discard top A1

= 11 value 94 discard bottom A1

list reduces to 10th

value. This is 73 so

73 has been located as the 10th

value A1 4 [8]

74

28

28

28

28

49

37

37

63

37

49

54

54

54

74

54

54

49

63

63

37

54

74

68

68

68

68

74

54

49

28

M1

A1

A1ft

63

74 (54)

MR

650650650710710

431643710650650

245710643643643

643455455455455

455431431431452

710245245452431

234234452245245

162162234234234

452452162162162

134134134134134

1000

4116

46

45

51

2

111

2

117

2

1110

Page 32: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 32

18. (a) The list is not in alphabetical order B1 1

(b) Use of Bubble Sort or Quick Sort M1

e.g.

Bubble sort

No more changes

Quick sort

No sublists > 2 and no more changes

A1 A1ft

No more changes No sublists > 2 + no more changes A1cso 4

(c) 1 2 3 4 5 6 7 8 9 10

B C E G L M N P S Y

= 6 Manchester discard first half of list and pivot M1 A1

= 9 Southampton discard last half of list and pivot

= 8 Plymouth discard last half of list and pivot A1ft

Final term 7 Newcastle word found at 7 A1cso 4 [9]

19. (a)

a b c Integer? Output

list a = b?

90 2 45 Yes 2 No M1

45 2 22.5 No A1

45 3 15 Yes 3 No A1ft

G

B

B

B

B

B

B

N

G

C

C

C

C

C

M

N

G

E

E

E

E

Y

M

N

G

G

G

G

L

Y

M

N

L

L

L

B

L

Y

M

N

M

M

C

C

L

Y

M

N

N

E

E

E

L

Y

P

P

S

P

P

P

P

Y

S

P

S

S

S

S

S

Y

1 pass

2 pass

3 pass

4 pass

5 pass

6 pass

st

nd

rd

th

th

th

G

B

B

B

B

B

B

N

G

G

C

C

C

C

M

N

C

G

E

E

E

Y

M

E

E

G

G

G

L

Y

L

L

L

L

L

B

L

N

N

N

M

M

C

C

M

M

M

N

N

E

E

Y

S

P

P

P

S

S

S

P

S

S

S

P

P

P

Y

Y

Y

Y

1 pass

2 pass

3 pass

4 pass

5 pass

6 pass

st

nd

rd

th

th

th

2

]110[

2

]107[

2

]87[

Page 33: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 33

15 2 7.5 No M1

15 3 5 Yes 3 No A1

5 2 2.5 No

5 3 1 No M1

5 5 1 Yes 5 Yes

Output list: 2,3,3,5 A1ft 7

(b) Gives the prime factorisation of a B2, 1, 0 2

(c) C = 1 B1 1 [10]

20. (a) Bin 1 – 75+20

Bin 2 – 70 +20 M1

Bin 3 – 60+40 A1

Bin 4 – 50+35 A1

Bin 5 – 20

5 Planks needed: cost £15 A1

Wastage = 5+10+0+15+80 = 110cm A1 5

(b) Bin 1 (1.5m) – 75 + 70 Bin 1 (1m) –75 + 20 M1

Bin 2 (1.5m) – 60 + 50 + 40 or Bin 2 (1.5m) –70 + 60 + 20

Bin 3 (1m) – 35 + 20 + 20 + 20 Bin 3 (1.5m) –50 + 40 + 35 + 20 A1

Cost £11 A1

1.5m lengths better value than 1m lengths to use as many as possible A1 4 [9]

21. (a) e.g.

M1

A1

A1 ft

A1 ft

A1 ft

5

(b) = 6 Palmer; reject Palmer Young M1 A1

= 3 Halliwell; reject Boase Halliwell A1

3

2

R

B

B

B

B

P

H

G

G

G

B

G

H

H

H

Y

K

K

K

K

T

R

R

M

M

K

P

P

P

P

M

Y

M

R

R

H

T

T

T

T

W

M

Y

W

W

G

W

W

Y

Y

2

110

2

15

Page 34: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 34

= 5 Morris; reject Morris

List reduces to Kenney – name found, search complete A1 4 [9]

22. (a) (i) le ft to right or right to le ft

25 22 30 18 29 21 27 21 25 22 30 18 29 21 27 21 M1

25 30 22 18 29 21 27 21 25 22 30 18 29 27 28 21

25 30 22 29 18 21 27 21 25 22 30 29 18 27 21 21

25 30 22 29 21 18 27 21 25 30 22 29 18 27 21 21

25 30 22 29 21 27 18 21 30 25 22 29 18 27 21 21 A1 (pass)

(ii) 25 30 22 29 21 27 21 18 30 29 25 22 27 18 21 21

30 25 29 22 27 21 21 18 30 29 27 25 22 21 18 21

30 29 25 27 22 21 21 18 30 29 27 25 22 21 21 18

30 29 27 25 22 21 21 18 30 29 27 25 22 21 21 18

30 29 27 25 22 21 21 18

(b) (i) rod 1 30 18

2 29 21

3 27 22 M1 (to the 22)

4 25 21 A1 2

(ii) 193 50 = 3.86, 4 rods needed, so minimum M1 A1 2 [9]

23. Is B = an integer?

A Yes or No A Yes or No

1 Yes 31 No

2 Yes 32 No

3 Yes 33 No

4 Yes 34 No

5 Yes 35 No

6 Yes 36 No

7 No 37 No

8 No 38 No

9 No 39 No

10 Yes 40 No

11 No 41 No

12 Yes 42 No

13 No 43 No

14 No 44 No

15 Yes 45 No

16 No 46 No

17 No 47 No

18 No 48 No

19 No 49 No

2

54

A

60

Page 35: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 35

20 Yes 50 No

21 No 51 No

22 No 52 No

23 No 53 No

24 No 54 No

25 No 55 No

26 No 56 No

27 No 57 No

28 No 58 No

29 No 59 No

30 Yes 60 Yes

M1

A3 (1 eeoo)

What the algorithm produces:

The algorithm produces all the factors of 60 B18 [8]

EXAMINERS’ REPORTS

1. No Report available for this question.

2. No Report available for this question.

3. This proved a good starter and was well answered by many candidates with around 55% getting full marks. The quick

sort was well handled although some candidates did not choose their pivots consistently. A few candidates did not

select a pivot when they had a two element sublist in the correct order – often HJ, and a minority sorted the list into

reverse alphabetical order. It was alarming that some candidates only selected one pivot per iteration, so, in effect, just

dealing with one sublist at a time. Candidates must show that they are selecting one pivot, per sublist, per iteration; that

is what makes this algorithm so powerful. A number of candidates did not have the final list in alphabetical order.

Many candidates in part (b) lost marks for failing to reject the pivot and number of candidates attempted to use the

original, unsorted list. Some, who tried for a more „minimalist‟ solution, did not make their pivot choice clear, or the

order in which they chose pivots.

4. This was a good source of marks for well-prepared candidates with over 75% gaining at least 7 marks, though the final

part challenged all but the most able.

Part (a) was almost always completed correctly.

Part (b) was often well done, although some used first fit decreasing and 29 was sometimes either omitted from the list

or changed to 39.

Most candidates were able to complete part (c) correctly but a few only listed one full bin.

In part (d) many incorrectly stated that the full bin solution was optimal, others made some vague reference to the

statues being too heavy, relatively few attempted a valid numerically based answer and managed to express it clearly.

5. Many candidates scored at least 8 marks here. In part (a) a minority produced an ascending list and failed to reverse it.

Some candidates did not choose their pivots consistently, swapping between middle right and middle left pivots. The

decimals here caused some problems and even though the original list was printed in the answer booklet, a surprising

number of candidates initially lost one item or changed one, most commonly 1.0 became 0.1. Some candidates found

only one pivot per row, with some not explicitly choosing pivots when sublists of length 2 happened to be in order –

most frequently the two 4.0s and the 1.0, 0.6 at the end. Good presentation, with a list spread evenly, in columns, across

the page, helps here. (Vertical listing is rarely successful). Part (b) was generally well done, the two most popular errors

being to put 0.6 in bin 5 or 0.4 in bin 5. A significant number who had sorted the numbers into increasing order in part

(a) proceeded to use a “first fit increasing” method here. In part (c) most candidates calculated the lower bound

correctly. Other candidates correctly stated that since the five largest items were over half a bin in size they could not

share a bin, so at least 5 bins would be needed. A few simply stated „yes‟ without justification, gaining no credit.

6. This question proved accessible to almost all, with very many perfect solutions seen, an improvement in performance

compared with previous examinations. There were only a handful of arithmetic errors here. Most candidates

successfully completed the first few steps of the algorithm. The majority of errors arose from writing down the incorrect

(size of) answer, e.g. –500 instead of –5000. There were some who inserted too many entries in the output column.

Quite a few inserted an expression rather than an amount in then T column (e.g. 0.2R). Despite errors in the output,

most realised that this was the amount they had to show for the amount of income tax paid, earning a follow through

mark in part (b). In part (c) many stated that the maximum was £7999.99 rather than the £8000.

Page 36: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 36

7. This was often a good source of marks for candidates. Most were able to calculate the lower bound getting 3.8 and

therefore 4 bins. Most candidates applied first fit correctly, although some candidates did not offer each item to each bin

in turn, starting with bin 1 each time, so often the 9 was the first item to be misplaced. Some candidates wasted time by

replacing each letter by a number, or explaining in lengthy detail the steps they took to place each item. Not all

candidates realised that they should fill as many bins as possible when using full bin, most found one full bin, but only

the best found two.

8. This was generally well done. A disappointingly large number of candidates only chose one pivot per iteration, rather

than choosing one pivot per sublist, and some candidates used lengthy methods of presentation that isolated each sublist

in turn, making it difficult to see if they were choosing more than one pivot per iteration. The examiners would advise

candidates to refrain from showing this unnecessary detail and simply indicate the pivots selected at each iteration.

Some candidates did not select a pivot where the sublist was of order two, with the two items being in the correct order,

and some did not consistently pick „middle left‟ or „middle right‟ when the sublist was of even order. Candidates are

reminded that when the items are being transferred to the next line, the order of the items should be preserved, so if item

Y is to the left of item X in the current line, neither of them being a pivot, then Y should be to the left of X in the next

line. The best candidates allowed each item to become a pivot before declaring the sort complete. Some candidates did

not check that their final list was in alphabetical order. In part (b) some candidates tried to apply the algorithm to the

original unsorted list given at the start of (a) and others did not discard the pivot at each stage, but generally the binary

search was very well done. A few candidates selected J as the first pivot, the specification makes it clear that candidates

must take the „middle right‟ where necessary.

9. Part (a) was done with mixed success. The majority of candidates gained full marks or three marks. The most common

errors were to have HIJ after the second pass and neglecting to choose a pivot on the third pass with the entry MR. Most

knew their alphabet, but not all. There was a temptation to go into too much detail about the choice of pivot, to the

extent that examiners were not always sure that more than one pivot was being considered per iteration. It is an

important feature of the quick sort that the number of pivots can potentially double at each iteration, so the selection of

multiple pivots must be clearly shown. Some candidates did not abbreviate the names, by using the initial letter and this

slowed them down.

Part (b) was usually very well done. The most common errors were not rejecting the pivot and not making a decision

when Hannah was left. Some candidates added Hugo to the list and then found him, others confused Hannah and Hugo.

10. This proved an accessible first question and was well answered by many candidates. Some candidates probably spent

too long on this question, drawing out very neat and accurate bar graphs in (b) and (c), where numbers in bins were

perfectly acceptable. Most candidates calculated the lower bound correctly in part (a) although some attempted a full

bin solution and others divided by 9, some having calculated 5.02 rounded down to 5. Apart from the usual omissions of

data, part (b) was usually well answered, the most common slips being to swap the 38 and the 41, or to use the 52 to start

off the second bin. First–Fit increasing was disappointingly often seen in part (c), but those who used the correct

algorithm were usually successful with the only common error being misplacing the 38.

11. Although there were many very good responses seen many candidates seemed to get into difficulty by the end of the

second line. This question requires a methodical, accurate and diligent approach and the examiners were surprised at

the number of candidates who found difficulty following the instructions. 126 was often seen in the second line of A,

the 26 in x was often omitted, as was the 12, some candidates changed the A or y entries too early, or too late, and some

candidates entered superfluous „yes‟ and „no‟ entries in the last two columns. Many candidates compressed their entries

– so that they were no longer „in line‟, others repeated entries, others wrote more than one entry in each box; this made

it difficult to determine the stage at which the candidates were changing the entries. Only the best candidates were able

to give the correct answer in part (b), with „the value of A when x = 0‟, and „LCM‟ being the most popular incorrect

answers – although HCF, HCM and LCF were also seen.

12. This proved a good starter question for the candidates with many gaining full marks. Some candidates were inconsistent

in their pivot choice, the specification requires that they round up. Some incorrectly retained the pivot each time – often

leading to a situation where they selected Nicky twice, once as the first pivot and once as the final pivot. Some

candidates insisted on placing Nigel in the list – or locating the position in which Nigel should be added to the list. The

binary search algorithm is both used to locate an item in the list and to demonstrate its absence. A few candidates

confused binary search and quick sort.

13. This proved a good starter question for the candidates, with the vast majority scoring full marks. Only a few candidates

sorted the list into ascending order, and very few incorrect methods were seen, but a disappointing number of

candidates did not seem to be aware that a bubble sort should be performed consistently in one direction. Amongst

those candidates using the correct method, more marks were lost by those misreading their own writing and changing

one number into another than those lost making errors in applying the algorithm. Some candidates omitted a „stop‟

statement. Candidates were asked to give the state of the list after each pass, but many showed each exchange and some

each comparison, which wasted time, many of these candidates needed to use additional sheets to show all of this

working and many got into time difficulties later on in the paper.

14. Most candidates completed the table but many did not precisely follow the instructions or else had difficulty in using

their calculator correctly. This was therefore disappointingly done. Many candidates did not obey the directions relating

to accuracy, stating an incorrect number of decimal places or significant figures or making rounding errors. Some very

careless calculator work was seen, the values of D should have alternated in sign, but were often negative throughout

Page 37: SORTING; BINARY SEARCH; ALGORITHMS IN  · PDF fileCity of London Academy 1 SORTING; BINARY SEARCH; ALGORITHMS IN GENERAL; FLOW CHARTS 1. Use the binary search algorithm to

City of London Academy 37

and many candidates had difficulty in calculating values for E, either omitting the bracket, or the square root, or both.

Very few listed all the E values as the output – with most stating only their final E value.

15. The vast majority of candidates showed that they understood the concept of quick sort, with very few bubble sorts seen.

Most candidates chose to start with one of the 54‟s as a pivot and a number of candidates were unsure what to do with

the second 54. Some chose 2 pivots initially, or created an incorrect order where the two 54s were next to each other.

However, most candidates dealt well with this situation. Other common errors were: not identifying a pivot towards the

end of the quick sort, where two numbers were already in the correct order, fragmenting the list rather than selecting

pivots concurrently and the regularly seen re-ordering of the sub-lists. Many candidates did not produce a list of

students in order.

16. Some very good answers were seen to part (a), but many candidates produced disappointing attempts. Poor presentation

and lack of concentration accounted for most errors in part (a); there was inconsistent choice of pivots, numbers that

disappeared from the list, numbers that mutated into other numbers and, of course, numbers being reordered in the list.

A large minority sorted the list into ascending order. A number of candidates are only selecting one pivot per pass,

which rather defeats the object of a quick sort. Only a very few Bubble sorts were seen. Candidate would help

themselves hugely by not fixing the position of the pivots until the line after they are selected, this would avoid the need

to try to cram numbers into the ever-decreasing space formed by their previously chosen pivots. Candidates could then

use the whole width of the line each time. Part (b) was usually well done. Some used the first fit algorithm and many put

134 into bin 5 rather than bin 3. Part (c) was often well attempted with the majority of candidates giving a clear,

arithmetical argument.

17. This was generally well done. Many candidates completed the quick sort, wasting time. Some candidates did not

understand the difference between an exchange and a pass in a bubble sort. Most candidates carried out the search well,

but many did not give the location of the value. A large number are still assuming that the item is in the list, making

statements such as „down to one item so found‟. A surprisingly large minority of candidates used the mean of the end

numbers in the remaining list to create a „pivot‟ which is unacceptable.

18. This question was often well answered. Most candidates correctly competed part (a), although a very few stated that the

list should be in ascending rather than alphabetical order. Most could correctly name and use a suitable sorting

algorithm in part (b), although some did not make their stopping statement clear and a few used a shuttle sort (not in this

specification) stating that it was a bubble sort. A surprisingly large minority confused the order of the alphabet with S

and P (and then M and N) most frequently transposed. Part (c) was usually well done but candidates must make their

pivots – and the order in which they select their pivots, clear. Candidates must remember to discard their pivots and note

that the specification instructs them to „round up‟. Once again the stopping/found statement was sometimes missing,

and some candidates assumed the presence of N, stating that once they had got down to 1 term only, that term must be

N.

19. Most candidates were able to make some progress with this question and for a number it was a rich source of marks. In

part (a) the most common error was a failure to „reset‟ the list to 2 after answering „no‟. A surprisingly large number of

candidates did not seem to understand what was meant by the word „integer‟. In part (b) only the most able were able to

recognise the list as the prime factorisation of a, and poor knowledge/understanding of the terms prime, factor and

multiple. Most candidates who completed part (a) correctly were able to answer part (c) correctly.

20. Many candidates scored full marks in part (a); however some candidates used the values in ascending order scoring

zero. There was no need to use a formal sort to put the list in order. Many candidates gave the cost of the wasted wood

rather than the cost of the five planks. In part (b) many candidates found an optimal solution, but many then went on to

consider just the amount of wood wasted, rather than showing that the cost depended upon the value for money of each

plank and therefore maximising the number of 1.5m lengths used.

21. Many candidates were able to gain full marks on this question. The most common errors in part (a) were in re-ordering

the letters in the sub-lists and choosing the pivots inconsistently. A surprising number of candidates seemed unsure of

the alphabet. Part (b) was well done by the majority of candidates. A surprising number tried to use an unsorted list for

their search, gaining no marks and others omitted to discard the pivot. The commonest error was in failing to select

Morris after correctly selecting Palmer then Halliwell. A few candidates did not make the order in which they selected

the pivots clear making it impossible to give credit.

22. Most candidates were able to complete the bubble sort correctly, although a number of shuttle sorts were seen from a

few candidates. A number of candidates did not complete a final pass, (or stated that they had performed a final pass

and found no further exchanges). The majority were able to complete the bin packing but a number were unable to show

that they had used a minimum number of bins, once again the lower bound would have helped here.

23. No Report available for this question.