Further Maths Algorithms Practice Questions

Free Further Maths Algorithms practice questions with full step-by-step worked solutions. Covers sorting, bubble-sort, quick-sort, pivots. Practise exam-style problems and check your method.

sortingbubble-sortquick-sortpivotsmerge-sortsearching
Further Maths70 questionsStep-by-step solutions
Question 1
2 markseasy
The list 8, 3, 5, 1, 9, 48,\ 3,\ 5,\ 1,\ 9,\ 4 is to be sorted into ascending order. A bubble sort is used. In each pass the adjacent pairs are compared from left to right and are swapped if they are in the wrong order. After the first pass the largest item is in its final place, so each pass compares one fewer pair than the pass before. The sort stops when a pass produces no swaps, or when only one item remains to be placed. Which of the following is the list after the first pass?
Show worked solution

Worked solution

  1. Write down the list to be sorted

    L=8, 3, 5, 1, 9, 4L=8,\ 3,\ 5,\ 1,\ 9,\ 4

    The bubble sort starts from the list in the order given.

  2. State the list at the end of pass 1

    after pass 1: 3, 5, 1, 8, 4, 9\text{after pass }1:\ 3,\ 5,\ 1,\ 8,\ 4,\ 9

    The largest 1 item(s) are now in their final places.

  3. Select the option that gives the list after the first pass

    3, 5, 1, 8, 4, 93,\ 5,\ 1,\ 8,\ 4,\ 9

    This is the list produced by pass 1.

Answer
3, 5, 1, 8, 4, 93,\ 5,\ 1,\ 8,\ 4,\ 9
Question 2
2 markseasy
A flow chart carries out the following instructions. Box 1: let S=0S=0 and K=1K=1. Box 2: replace SS by S+K2S+K^{2}. Box 3: replace KK by K+1K+1. Box 4: if K5K\le 5 return to Box 2; otherwise output SS and stop. State the value that is output by the flow chart.
Show worked solution

Worked solution

  1. Write down the starting values

    S=0,K=1S=0,\quad K=1

    Box 1 initialises the two variables.

  2. Carry out the loop for K=1K=1 to K=5K=5

    K=1S=1; K=2S=5; K=3S=14; K=4S=30; K=5S=55K=1\Rightarrow S=1;\ K=2\Rightarrow S=5;\ K=3\Rightarrow S=14;\ K=4\Rightarrow S=30;\ K=5\Rightarrow S=55

    Box 2 adds K2K^{2} to SS and Box 3 increases KK by one; after this S=55S=55.

  3. Note when the loop stops

    K=6>5output SK=6>5\Rightarrow\text{output }S

    Box 4 sends the flow chart to the output box.

  4. State the value output

    S=55S=55

    This is the value printed by the flow chart.

Answer
5555
Question 3
4 marksintermediate
A flow chart carries out the Euclidean algorithm. Box 1: input the positive integers A=1071A=1071 and B=462B=462. Box 2: let RR be the remainder when AA is divided by BB. Box 3: if R=0R=0, output BB and stop. Box 4: otherwise replace AA by BB and BB by RR, then return to Box 2. State the value that is output by the flow chart.
Show worked solution

Worked solution

  1. Write down the input values

    A=1071,B=462A=1071,\quad B=462

    Box 1 reads in the two positive integers.

  2. Divide 1071 by 462 and record the remainder

    1071=2×462+1471071=2\times 462+147

    The remainder is 147, so A becomes 462 and B becomes 147.

  3. Divide 462 by 147 and record the remainder

    462=3×147+21462=3\times 147+21

    The remainder is 21, so A becomes 147 and B becomes 21.

  4. Divide 147 by 21 and record the remainder

    147=7×21+0147=7\times 21+0

    The remainder is 0, so the algorithm stops.

  5. Note when the flow chart stops

    R=0output B=21R=0\Rightarrow\text{output }B=21

    The last non-zero remainder is the highest common factor.

  6. State the value output

    output=21\text{output}=21

    The flow chart outputs the highest common factor of 1071 and 462.

Answer
2121
Question 4
6 markshard
A flow chart carries out the following instructions. Box 1: input N=13N=13. Box 2: if N=1N=1, output the number of times Box 3 has been carried out and stop. Box 3: if NN is even replace NN by N2\frac{N}{2}, otherwise replace NN by 3N+13N+1; then return to Box 2. State the value that is output by the flow chart.
Show worked solution

Worked solution

  1. Write down the input value

    N=13N=13

    Box 1 reads in the starting value.

  2. Apply Box 3 to N=13N=13 down to N=40N=40

    13402013\to40\to20

    The rule is applied once for each value in this chain.

  3. Apply Box 3 to N=20N=20 down to N=10N=10

    2010520\to10\to5

    The rule is applied once for each value in this chain.

  4. Apply Box 3 to N=5N=5 down to N=16N=16

    51685\to16\to8

    The rule is applied once for each value in this chain.

  5. Apply Box 3 to N=8N=8 down to N=4N=4

    8428\to4\to2

    The rule is applied once for each value in this chain.

  6. Apply Box 3 to N=2N=2

    2 is evenN=22=12\text{ is even}\Rightarrow N=\frac{2}{2}=1

    2 is even, so the halving rule is used.

  7. Note when the flow chart stops

    N=1output the number of times Box 3 was usedN=1\Rightarrow\text{output the number of times Box 3 was used}

    Box 2 stops the flow chart as soon as N=1N=1.

  8. Write out the whole chain of values

    13402010516842113\to40\to20\to10\to5\to16\to8\to4\to2\to 1

    The chain has 9 arrows, one for each use of Box 3.

  9. Count the times the halving rule is used

    even=7,odd=2\text{even}=7,\quad\text{odd}=2

    Every use of the 3N+13N+1 rule is followed by a halving.

  10. Find the largest value reached

    max=40\max=40

    The chain can rise well above its starting value before it falls.

  11. State the number that is output

    output=9\text{output}=9

    Box 3 is carried out 9 times before NN reaches 11.

Answer
99
Question 5
9 markschallenging
A flow chart carries out the Euclidean algorithm. Box 1: input the positive integers A=4935A=4935 and B=3050B=3050. Box 2: let RR be the remainder when AA is divided by BB. Box 3: if R=0R=0, output BB and stop. Box 4: otherwise replace AA by BB and BB by RR, then return to Box 2. State the value that is output by the flow chart.
Show worked solution

Worked solution

  1. Write down the input values

    A=4935,B=3050A=4935,\quad B=3050

    Box 1 reads in the two positive integers.

  2. Carry out the next 2 divisions

    4935=1×3050+1885; 3050=1×1885+11654935=1\times 3050+1885;\ 3050=1\times 1885+1165

    Each time, A is replaced by B and B by the remainder.

  3. Note when the flow chart stops

    R=0output B=5R=0\Rightarrow\text{output }B=5

    The last non-zero remainder is the highest common factor.

  4. List the remainders produced

    1885, 1165, 720, 445, 275, 170, 105, 65, 40, 25, 15, 10, 5, 01885,\ 1165,\ 720,\ 445,\ 275,\ 170,\ 105,\ 65,\ 40,\ 25,\ 15,\ 10,\ 5,\ 0

    The remainders strictly decrease, so the flow chart must terminate.

  5. Count the times Box 2 is carried out

    divisions=14\text{divisions}=14

    One division is done for each pass round the loop.

  6. Check that the output divides both inputs

    4935=5×987,3050=5×6104935=5\times 987,\quad 3050=5\times 610

    The output is a common factor of the two inputs.

  7. Check that no larger common factor exists

    gcd(987,610)=1\gcd\left(987,610\right)=1

    The two quotients share no factor, so 5 is the highest common factor.

  8. Note the order of the Euclidean algorithm

    order log(min(A,B))\text{order }\log\left(\min\left(A,B\right)\right)

    The Euclidean algorithm is extremely fast even for huge inputs.

  9. Recall what a sorted list means

    ascending order: a1a2an\text{ascending order: }a_{1}\le a_{2}\le\cdots\le a_{n}

    Every item must be no larger than the item that follows it.

  10. Recall the number of comparisons in one bubble-sort pass

    pass k makes nk comparisons\text{pass }k\text{ makes }n-k\text{ comparisons}

    Each pass leaves one more item in its final place, so it is one comparison shorter.

  11. Recall the worst case for a bubble sort

    12n(n1) comparisons\tfrac{1}{2}n\left(n-1\right)\text{ comparisons}

    A reversed list forces every possible comparison to be made.

  12. Note the order of a bubble sort

    bubble sort has order n2\text{bubble sort has order }n^{2}

    Doubling the length of the list roughly quadruples the running time.

  13. Note the order of a binary search

    binary search has order logn\text{binary search has order }\log n

    Each pass halves the number of items still under consideration.

  14. Recall the lower bound for a bin-packing problem

    binstotal sizecapacity\text{bins}\ge\left\lceil\frac{\text{total size}}{\text{capacity}}\right\rceil

    No packing can use fewer bins than this, though the bound need not be attainable.

  15. Note that bin-packing algorithms are heuristics

    first-fit need not give the optimal packing\text{first-fit need not give the optimal packing}

    A heuristic gives a good solution quickly but not necessarily the best one.

  16. State the value output

    output=5\text{output}=5

    The flow chart outputs the highest common factor of 4935 and 3050.

Answer
55

Unlock 65 more Algorithms questions

Create a free account to work through every Further Maths Algorithms question with instant step-by-step worked solutions, progress tracking and interactive lessons.

  • Full worked solutions for every question
  • Interactive lessons and instant feedback
  • Track your mastery across every topic
Create a Free Account

No card required · Free forever

More Algorithms practice

Related Decision Maths topics