Algorithms Worked Solutions — Further Maths Maths

Fully worked, step-by-step solutions to Further Maths Algorithms questions. See exactly how to solve problems on sorting, bubble-sort, quick-sort, pivots.

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?

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
The list 5, 2, 7, 3, 65,\ 2,\ 7,\ 3,\ 6 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. How many swaps are made in the first pass?

Worked solution

  1. Write down the list to be sorted

    L=5, 2, 7, 3, 6L=5,\ 2,\ 7,\ 3,\ 6

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

  2. State the list at the end of pass 1

    after pass 1: 2, 5, 3, 6, 7\text{after pass }1:\ 2,\ 5,\ 3,\ 6,\ 7

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

  3. State the number of swaps made in the first pass

    swaps in pass 1=3\text{swaps in pass }1=3

    This is the required number of swaps.

Answer
33
Question 3
2 markseasy
The list 9, 4, 6, 2, 8, 19,\ 4,\ 6,\ 2,\ 8,\ 1 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. How many comparisons are made in the first pass?

Worked solution

  1. Write down the list to be sorted

    L=9, 4, 6, 2, 8, 1L=9,\ 4,\ 6,\ 2,\ 8,\ 1

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

  2. Pass 1: compare every adjacent pair from left to right

    comparisons=5,swaps=5\text{comparisons}=5,\quad\text{swaps}=5

    This pass compares the first 6 items, making 5 swaps.

  3. State the list at the end of pass 1

    after pass 1: 4, 6, 2, 8, 1, 9\text{after pass }1:\ 4,\ 6,\ 2,\ 8,\ 1,\ 9

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

  4. State the number of comparisons made in the first pass

    comparisons in pass 1=5\text{comparisons in pass }1=5

    This is the required number of comparisons.

Answer
55
Question 4
2 markseasy
The list 6, 2, 9, 4, 76,\ 2,\ 9,\ 4,\ 7 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?

Worked solution

  1. Write down the list to be sorted

    L=6, 2, 9, 4, 7L=6,\ 2,\ 9,\ 4,\ 7

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

  2. State the list at the end of pass 1

    after pass 1: 2, 6, 4, 7, 9\text{after pass }1:\ 2,\ 6,\ 4,\ 7,\ 9

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

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

    2, 6, 4, 7, 92,\ 6,\ 4,\ 7,\ 9

    This is the list produced by pass 1.

Answer
2, 6, 4, 7, 92,\ 6,\ 4,\ 7,\ 9
Question 5
2 markseasy
The list 7, 3, 9, 1, 5, 87,\ 3,\ 9,\ 1,\ 5,\ 8 is to be sorted into ascending order. A quick sort is used. The first item of each sub-list is chosen as the pivot. The items smaller than the pivot are written, in their original order, to the left of the pivot and the items larger than the pivot are written, in their original order, to its right, so the pivot reaches its final position. In each pass a pivot is chosen from every sub-list containing two or more items; a sub-list containing a single item is already in place and no pivot is chosen from it. Which of the following is the list after the first pass?

Worked solution

  1. Write down the list to be sorted

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

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

  2. State the list at the end of pass 1

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

    The 1 pivot(s) chosen in this pass are now in their final places.

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

    3, 1, 5, 7, 9, 83,\ 1,\ 5,\ 7,\ 9,\ 8

    This is the list produced by pass 1.

Answer
3, 1, 5, 7, 9, 83,\ 1,\ 5,\ 7,\ 9,\ 8

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