levo

Algorithms

Bubble sort and merge sort

  • 3 things to know
  • Paper 1

Overview

How a bubble sort passes through a list and when it stops, how a merge sort splits and merges, traced sorts of short lists, comparison counts, and the strengths of each.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Process

How does a bubble sort work?

Process

How does a merge sort work?

Process

Describe the steps of a merge sort on [7, 3, 9, 1].

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    How does a bubble sort work?

    Model answer

    A bubble sort compares each pair of adjacent items in a list. The pair is swapped if the two items are in the wrong order. Passes through the list repeat until a pass makes no swaps.

  2. 2

    How many comparisons does one pass of a bubble sort make on a list of 5 items?

    Model answer

    One pass makes four comparisons. A list of n items has n − 1 adjacent pairs.

  3. 3

    What is [6, 2, 9, 4, 1] after the first pass of a bubble sort into ascending order?

    Model answer

    After the first pass the list is [2, 6, 4, 1, 9]. The pass makes three swaps, and the largest value, 9, has moved to the end.

  4. 4

    What is [6, 2, 9, 4, 1] after the second pass of a bubble sort into ascending order?

    Model answer

    After the second pass the list is [2, 4, 1, 6, 9]. The two largest values are now in their final places.

  5. 5

    A bubble sort stops after a pass with no swaps. How many passes does it take to sort [6, 2, 9, 4, 1]?

    Model answer

    The sort takes five passes. Four passes make swaps and the fifth makes none, which confirms the list is in order.

  6. 6

    Why can a bubble sort stop as soon as a pass makes no swaps?

    Model answer

    A pass with no swaps shows that every adjacent pair is already in order. The whole list must therefore be sorted.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Algorithms
Programming
Data Representation
Computer Systems

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

The table one extra row.
gainslosescopies

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AThe algorithm outputs 1.
BThe variable x falls from 5 to 3 to 1.
CThe loop stops because 1 is not greater than 1.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

ASC means sorting from smallest to largest, or A to Z.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Algorithms, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.