Quadratic Sorts: Bubble and Insertion · بذر 1 · A۴، مناسب چاپ. پاسخ‌نامه در صفحه‌ای جدا برای بزرگ‌ترها چاپ می‌شود.
به انگلیسی

Two slow sorts that teach a lot

رایانش · الگوریتم‌ها و ساختمان داده‌ها · سن ۱۶ تا ۱۷ سال
نام ______________________   تاریخ ____________
  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?

    پاسخ: ______________

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

    دور یکی دایره کشیدن:   درست   نادرست

  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

پاسخ‌نامه

برای بزرگ‌ترها. تا کردن این صفحه پیش از تحویل بقیه.

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. درست · 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.
کاربرگ · LightMySky