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

Heaps and Priority Queues (Lecture 12)

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

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

  1. W12-M01 تذكّر

    In a min-heap, which statement is always true?

  2. W12-M02 تذكّر

    With 0-based indices, the left child of index i is at:

  3. W12-M03 تطبيق

    The parent of index 10 is at index:

  4. W12-M04 تطبيق

    The height of a heap holding 1,000 values (a single node has height 0) is:

  5. W12-M05 تطبيق

    Which array is a valid min-heap?

  6. W12-M06 تطبيق

    Q.push(2): how many swaps does the sift-up make?

  7. W12-M07 تطبيق

    Q.pop() returns 1. Which value is at the root afterwards?

  8. W12-M08 تعليل

    Sift-down swaps an item with the better of its two children, not just any child that beats it, because:

  9. W12-M09 تذكّر

    heapify on an array of n values sifts down first at index:

  10. W12-M10 تذكّر

    The worst-case cost of heapify on n values is:

  11. W12-M11 تعليل

    heapify costs less than n pushes because:

  12. W12-M12 تطبيق

    Pushing the values n, n – 1, …, 2, 1 (in that order) into an empty min-heap costs, in total:

  13. W12-M13 تذكّر

    peek() on a heap of n values costs:

  14. W12-M14 تذكّر

    Checking whether an arbitrary value x is in a heap of n values costs, in the worst case:

  15. W12-M15 تعليل

    A heap is stored in an array, with no node objects, because:

  16. W12-M16 تطبيق

    enqueue("a", 2), enqueue("b", 1), enqueue("c", 1), then three dequeue()s return:

  17. W12-M17 تعليل

    PriorityQueue pushes (priority, counter, item) rather than (priority, item) because:

  18. W12-M18 تطبيق

    The k largest of n values, found with a min-heap of at most k values, cost:

  19. W12-M19 تعليل

    To find the k largest values you keep a min-heap of size k because:

  20. W12-M20 تذكّر

    The extra space of heap sort (Week 10) is:

  21. W12-M21 تعليل

    Heap sort sorts into ascending order with a max-heap because:

  22. W12-M22 تطبيق

    After MaxHeap([3, 1, 4, 1, 5, 9, 2, 6]), the value at _items[1] is:

18 درجات

أسئلة المقال

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

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

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

    Define a binary heap by its two properties. Explain why the shape property matters: what it gives the height, and what it gives the storage.

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

    Describe push and pop on a min-heap, including sift-up and sift-down, the cost of each, and the special cases the code must handle.

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

    Explain how heapify builds a heap bottom-up, why it must go from the last parent backwards, and show that it is O(n). Why are n pushes O(n log n) in the worst case?

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

    Compare four ways to implement a priority queue — unsorted array, sorted array, binary heap, balanced binary search tree — by the cost of enqueue, dequeue and peek. Which would you choose, and why?

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

    PriorityQueue stores (priority, counter, item). What goes wrong with (priority, item)? What does the counter add besides avoiding that error?