هياكل البيانات والخوارزميات (DSA27) · الأسبوع 9

Basic sorting (Lecture 09)

هذه اختبارات للتدريب الذاتي، تُحفظ إجاباتك على هذا الجهاز فقط ولا تُرسل إلى أحد. الأسئلة والشرح بالإنجليزية لغة المقرر.

النتيجة: 0 / 22 · أُجيب: 0

  1. W9-M01 تذكّر

    A sorting algorithm is stable when:

  2. W9-M02 تذكّر

    A sort is in place when:

  3. W9-M03 تذكّر

    Which of these sorts is not stable, as written in the course?

  4. W9-M04 تطبيق

    Bubble sort, with the early exit, on [1, 2, 3, 4, 5, 6] makes how many comparisons?

  5. W9-M05 تطبيق

    Selection sort on [1, 2, 3, 4, 5, 6] makes how many comparisons?

  6. W9-M06 تطبيق

    The array after the first pass of bubble sort on A is:

  7. W9-M07 تطبيق

    The array after the first round of selection sort on A is:

  8. W9-M08 تطبيق

    Insertion sort on A. The array after the round that inserts a[3] (the value 1) is:

  9. W9-M09 تطبيق

    How many inversions does [3, 1, 2] have?

  10. W9-M10 تعليل

    The number of shifts insertion sort makes is always equal to:

  11. W9-M11 تذكّر

    The best case of insertion sort is:

  12. W9-M12 تعليل

    Selection sort is the best of the three basic sorts when:

  13. W9-M13 تطبيق

    The largest number of swaps selection sort makes on 10 values is:

  14. W9-M14 تطبيق

    counting_sort([4, 0, 4, 1]) makes a counts array of how many slots?

  15. W9-M15 تذكّر

    Counting sort on n values from the range 0 .. k - 1 takes:

  16. W9-M16 تعليل

    Counting sort is a bad choice when:

  17. W9-M17 تذكّر

    In the worst case, every comparison sort of n values needs at least:

  18. W9-M18 تطبيق

    The fewest comparisons that can sort any 4 values in the worst case, by comparing, is at least:

  19. W9-M19 تعليل

    The decision-tree argument for the lower bound uses the fact that:

  20. W9-M20 تعليل

    A _steps generator yields its working list itself (not a copy) before each comparison. Then frames = list(generator) holds:

  21. W9-M21 تعليل

    A plain sort runs its _steps generator to the end, and the generator copies the array before each of its about n2/2 comparisons. The plain sort costs:

  22. W9-M22 تطبيق

    Bubble sort on [6, 5, 4, 3, 2, 1] makes how many swaps?

20 درجات

أسئلة المقال

5 أسئلة مقالية (20 درجة). اكتب إجابتك أولًا، ثم اعرض الإجابة النموذجية ونقاط التصحيح، وقدّر درجتك بأمانة: كل نقطة تساوي درجة تقريبًا.

مجموع درجات المقال: 0 / 20

  1. W9-E1 تعليل 4 درجات

    Define stable and in place. Say which of bubble, selection and insertion sort are stable, and why, from their code. Give a small input on which selection sort is not stable, and explain why stability matters when you sort by two keys.

  2. W9-E2 تطبيق 4 درجات

    Compare bubble, selection and insertion sort: the comparisons they make at best and at worst, and the swaps or shifts. For each, describe a situation in which it is the best of the three.

  3. W9-E3 تعليل 4 درجات

    Define an inversion. Prove that insertion sort makes exactly one shift per inversion, and use that to give its best, worst and average case. Why do library sorts such as Timsort use insertion sort inside?

  4. W9-E4 تعليل 4 درجات

    Explain the _steps generator pattern of dsa/sorting.py: what it yields and when, how the plain sort reuses it, the two rules its frames must obey, and what "the price of watching" is and how it is fixed.

  5. W9-E5 تعليل 4 درجات

    State the lower bound for comparison sorting and give the decision-tree argument for it. Explain why counting sort does not contradict it, and when counting sort is the right choice.