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

Advanced sorting (Lecture 10)

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

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

  1. W10-M01 تذكّر

    Which of these is not one of the three steps of divide and conquer?

  2. W10-M02 تطبيق

    The recurrence for the number of steps of merge sort on n elements is:

  3. W10-M03 تطبيق

    _merge merges two sorted runs of 4 elements each. The largest number of comparisons it can make is:

  4. W10-M04 تعليل

    Merge sort is stable because:

  5. W10-M05 تذكّر

    The extra space merge sort needs, beyond the input, is:

  6. W10-M06 تطبيق

    How many calls of _merge does merge_sort make on 8 elements?

  7. W10-M07 تطبيق

    merge_sort(list(range(1024))) — already sorted — makes how many comparisons?

  8. W10-M08 تذكّر

    During Lomuto's partition, with j the next index to look at, the invariant is:

  9. W10-M09 تطبيق

    _partition(a, 0, 7) on a = [6, 3, 9, 1, 8, 2, 7, 4] returns:

  10. W10-M10 تطبيق

    How many comparisons with the pivot does one Lomuto partition of a range of 8 elements make?

  11. W10-M11 تعليل

    quick_sort(list(range(n)), pivot="first") makes:

  12. W10-M12 تعليل

    On an already sorted range, pivot="median3" avoids the worst case because:

  13. W10-M13 تعليل

    Quicksort recurses into the smaller part and loops on the larger. This bounds:

  14. W10-M14 تذكّر

    Quicksort is not stable because:

  15. W10-M15 تذكّر

    In the array layout of a heap, the children of index i are at:

  16. W10-M16 تطبيق

    Build-heap on [4, 10, 3, 5, 1, 8, 2, 7] gives:

  17. W10-M17 تعليل

    Build-heap is O(n), not O(n log n), because:

  18. W10-M18 تطبيق

    For n = 10, heap sort's build loop sifts down the indices:

  19. W10-M19 تذكّر

    Which sort is O(n log n) in the worst case and needs only O(1) extra space?

  20. W10-M20 تعليل

    The lower bound of about n log2 n comparisons applies to:

  21. W10-M21 تذكّر

    Python's sorted() and list.sort() use:

  22. W10-M22 تطبيق

    sorted(list(range(1000))) — already sorted — makes how many comparisons?

20 درجات

أسئلة المقال

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

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

  1. W10-E1 تعليل 5 درجات

    Describe merge sort as divide and conquer. Write its recurrence and solve it with a recursion tree. Give its extra space, and explain what makes it stable.

  2. W10-E2 تعليل 4 درجات

    Describe Lomuto's partition: what it does, its invariant, and why the pivot is in its final place afterwards. Why is there nothing to "combine" in quicksort?

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

    Compare the pivot strategies "first", "random" and "median3": the cost of choosing, and the inputs on which each is at its worst. Why is sorted input the case that matters?

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

    Explain how heap sort uses an array as a tree. Describe build-heap and the sort phase, and argue that build-heap is O(n). Why is heap sort often slower in practice than quicksort, though its worst case is better?

  5. W10-E5 تعليل 3 درجات

    Define a stable sort. Give a practical reason to want one, say which of the six sorts in dsa/sorting.py are stable, and explain why sorting (key, tag) tuples does not test stability.