Quadratic Sorts: Bubble and Insertion · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Two slow sorts that teach a lot

Computing · Algorithms & Data Structures · ages 16-17
Name ______________________   Date ____________
  1. What does one insertion step do?

    • It takes the next value and slides it into its slot among the sorted values
    • It swaps random pairs until lucky
    • It deletes the largest value
  2. What does one bubble sort pass do?

    • It picks the minimum of the whole list at once
    • It walks along comparing neighbours and swapping out-of-order pairs
    • It splits the list in half
  3. With an early exit flag, what does bubble sort do on nearly sorted input?

    • It still grinds through every pass
    • It can finish in one pass with no swaps
    • It runs slower than on reversed input
  4. Why are both methods O(n squared)?

    • Their comparison counts grow with the square of n
    • They each use exactly n comparisons
    • They never compare anything
  5. Worst case comparisons to insertion sort six values? Work it out as 5 + 4 + 3 + 2 + 1.

    Answer: ______________

  6. Insertion sort runs in nearly linear time on nearly sorted input.

    Circle one:   True   False

  7. A student claims bubble sort always beats insertion sort because swapping looks faster. What is the error?

    • Swapping decides nothing; on nearly sorted input insertion slots values in almost at once
    • Bubble sort can never sort at all
    • Insertion sort cannot handle small lists
  8. Six values need 15 worst case comparisons. Roughly how many for twelve values?

    • 30
    • About 45
    • About 66
LightMySky · lightmysky.comW1-mt_cBUIBa15jQ-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Two slow sorts that teach a lot W1-mt_cBUIBa15jQ-s1

  1. It takes the next value and slides it into its slot among the sorted values · The newcomer slots into the sorted front.
  2. It walks along comparing neighbours and swapping out-of-order pairs · Neighbours compare and swap, floating the largest to the end.
  3. It can finish in one pass with no swaps · A swap-free pass proves the list sorted and stops the method.
  4. Their comparison counts grow with the square of n · Each of n items can meet n others.
  5. 15 · Each newcomer meets all placed cards: 15 comparisons.
  6. True · Each value slots in almost at once, so work stays near linear.
  7. Swapping decides nothing; on nearly sorted input insertion slots values in almost at once · Input shape decides: tidy input favours insertion clearly.
  8. About 66 · Doubling roughly quadruples quadratic work: 11 + 10 down to 1 is 66.
Worksheet · LightMySky