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

Dynamic arrays and amortised analysis (Lecture 04)

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

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

  1. W4-M01 تذكّر

    For a DynamicArray, len(a) returns:

  2. W4-M02 تطبيق

    With doubling, what is the capacity after 5 appends?

  3. W4-M03 تطبيق

    With doubling, how many resizes do 1,000 appends cause?

  4. W4-M04 تطبيق

    If the capacity grows by one slot at every resize, the total number of copies for n appends is:

  5. W4-M05 تعليل

    If the capacity grows by a constant 100 slots at every resize, the amortised cost of append is:

  6. W4-M06 تذكّر

    With doubling, the amortised cost of append is:

  7. W4-M07 تعليل

    With doubling, the worst-case cost of a single append is:

  8. W4-M08 تعليل

    How does amortised cost differ from average-case cost?

  9. W4-M09 تطبيق

    With doubling, the total number of element copies for n appends is:

  10. W4-M10 تطبيق

    With doubling, which of these appends triggers a resize?

  11. W4-M11 تعليل

    To shrink without thrashing, a dynamic array should halve its capacity when the size falls to:

  12. W4-M12 تذكّر

    "Thrashing" in a dynamic array means:

  13. W4-M13 تذكّر

    CPython's list grows its capacity by about:

  14. W4-M14 تطبيق

    How can you see a Python list's capacity from Python?

  15. W4-M15 تطبيق

    In a DynamicArray of size 5 and capacity 8, a[-1] reads self._block at index:

  16. W4-M16 تذكّر

    insert_at(0, x) on a dynamic array of size n costs:

  17. W4-M17 تذكّر

    pop() — removing the last element — costs:

  18. W4-M18 تعليل

    Why does growing by a factor give amortised O(1) append?

  19. W4-M19 تعليل

    Growing by a factor of 1.5 instead of 2:

  20. W4-M20 تطبيق

    With doubling and no shrinking, just after a resize, about how much of the capacity is unused?

  21. W4-M21 تذكّر

    Which structure in dsa/ stores its items in the student's own DynamicArray?

  22. W4-M22 تطبيق

    In the accounting ("bank") proof for doubling, how many coins must each append be charged?

  23. W4-M23 تطبيق

    With the course DynamicArray (capacity 1, doubling), what are len(a) and a._capacity after a = DynamicArray(range(6))?

  24. W4-M24 تعليل

    Why does __getitem__ check index < self._size rather than index < self._capacity?

  25. W4-M25 تطبيق

    What does this print?

    a = DynamicArray()
    for i in range(9):
        a.append(i)
    print(a.resize_count, a._capacity)
  26. W4-M26 تذكّر

    When the course DynamicArray resizes, it:

  27. W4-M27 تعليل

    Why can _resize not simply make the existing Array longer?

  28. W4-M28 تطبيق

    A DynamicArray holds 8 elements and has capacity 8. Counting the elements copied by a resize and the elements shifted, how many existing elements move during insert_at(0, "x")?

  29. W4-M29 تطبيق

    a = DynamicArray([10, 20, 30, 40, 50]). What does a.pop(2) return, and how many elements move?

  30. W4-M30 تطبيق

    After 9 appends and then 8 calls of pop(), what is the capacity of the course DynamicArray?

  31. W4-M31 تطبيق

    During 1,000,000 appends to an array that doubles, the single most expensive append copies how many elements?

  32. W4-M32 تطبيق

    With DynamicArray(growth=3), the total number of elements copied by n appends is always less than:

  33. W4-M33 تذكّر

    Which of these statements is an amortised bound rather than a worst-case bound for a single operation?

  34. W4-M34 تذكّر

    DynamicArray(growth=1.5) fails at its first resize. Why?

  35. W4-M35 تعليل

    What does DynamicArray([1, 2], growth=1) do?

  36. W4-M36 تعليل

    An array that grows by a constant +10 slots copies 798,400 elements for 4,000 appends. For 8,000 appends it copies about:

  37. W4-M37 تذكّر

    A DynamicArray holds 5 elements in capacity 8. What does a[5] = "x" do?

  38. W4-M38 تعليل

    In the accounting argument (3 coins per append), the doubling from capacity 8 to 16 copies 8 elements. Which coins pay for it?

  39. W4-M39 تعليل

    A student's _resize copies into the new block and sets self._block, but forgets self._capacity = capacity. Starting empty with capacity 1, what happens?

  40. W4-M40 تذكّر

    Which methods of the course DynamicArray can trigger a resize?

34 درجات

أسئلة المقال

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

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

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

    Define amortised cost. Prove that n appends to a dynamic array that doubles cost O(n) in total, and conclude the amortised cost of one append.

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

    Explain why growing the capacity by a constant number of slots gives Θ(n2) total cost for n appends, however large the constant, while growing by a constant factor gives Θ(n).

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

    append is "worst-case O(n) and amortised O(1)". Explain both statements, why both are true, and when the worst case still matters.

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

    Explain thrashing with a concrete sequence of operations, and the shrinking rule that prevents it.

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

    Growth factor is a time–space trade-off. Explain the trade-off, and why CPython's list uses a small factor (about 1.125).

  6. W4-E6 تطبيق 4 درجات

    A DynamicArray holds a b c d in capacity 4. Describe every step of insert_at(1, "x"), give the final contents, size and capacity, and count the elements copied and shifted. Why must insert_at check for a full array before it shifts?

  7. W4-E7 تعليل 4 درجات

    Stack, SlowQueue, MinHeap and Graph are all built on your DynamicArray. For the stack and the slow queue, explain how the cost of each operation follows from the DynamicArray table. Why does a bug in DynamicArray show up in the tests of other weeks?

  8. W4-E8 تعليل 3 درجات

    Explain the accounting ("bank") argument for a doubling array: how many coins each append is charged, what each coin pays for, and why the bank never goes negative.

  9. W4-E9 تعليل 4 درجات

    A game appends one record to a dynamic array every frame and must never take longer than one frame. Explain why a doubling array is a risk even though append is amortised O(1), and describe two ways to remove the risk.