Quadratic Sorts: Bubble and Insertion · graine 1 · A4, économe en encre. Le corrigé s'imprime sur sa propre page, pour les adultes.
En anglais

Two slow sorts that teach a lot

Informatique · Algorithmes et structures de données · de 16 à 17 ans
Nom ______________________   Date ____________
  1. What does one insertion step do?

    • It slides the next value into its slot among the sorted ones
    • It finds the smallest remaining value and swaps it to the front
    • It deletes the largest value
  2. What does one bubble sort pass do?

    • It picks the minimum of the whole list at once
    • It swaps out-of-order neighbours as it walks
    • It splits the list in half
  3. With an early exit flag, what does bubble sort do on a list that is already sorted?

    • 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)?

    • Comparisons grow with n times n
    • They each use exactly n comparisons
    • They never compare anything
  5. In the worst case, how many comparisons does insertion sort make on seven values?

    Réponse : ______________

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

    En entourer un :   Vrai   Faux

  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

Corrigé

Pour les adultes. Replier cette page avant de passer le reste.

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

  1. It slides the next value into its slot among the sorted ones · The newcomer slots into the sorted front.
  2. It swaps out-of-order neighbours as it walks · 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. Comparisons grow with n times n · Each of n items can meet n others.
  5. 21 · Each newcomer meets every value already placed: 6 + 5 + 4 + 3 + 2 + 1 = 21.
  6. Vrai · 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.
Fiche d'exercices · LightMySky