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

Linked lists (Lecture 05)

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

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

  1. W5-M01 تذكّر

    A node of a singly linked list holds:

  2. W5-M02 تذكّر

    Reading ll[i] on a linked list of n nodes costs:

  3. W5-M03 تذكّر

    push_front costs:

  4. W5-M04 تذكّر

    append on a singly linked list without a tail reference costs:

  5. W5-M05 تعليل

    Which operation is O(1) on a linked list but O(n) on a dynamic array?

  6. W5-M06 تعليل

    Which operation is O(1) on a dynamic array but O(n) on a linked list?

  7. W5-M07 تعليل

    In push_front, why must new.next = self.head come before self.head = new?

  8. W5-M08 تعليل

    To remove a node from a singly linked list, you need a reference to:

  9. W5-M09 تذكّر

    Which node is the special case in remove(value) without a sentinel?

  10. W5-M10 تطبيق

    What is the running time of this loop over a linked list of n nodes?

    for i in range(len(ll)):
        total += ll[i]
  11. W5-M11 تعليل

    Why is len(ll) O(1) in dsa/linked_list.py?

  12. W5-M12 تطبيق

    Reversing a linked list in place needs how much extra space?

  13. W5-M13 تذكّر

    On 64-bit CPython, a Node with __slots__ takes about 48 bytes. One slot of an array of references takes:

  14. W5-M14 تعليل

    A doubly linked list can do in O(1) what a singly linked one cannot:

  15. W5-M15 تعليل

    What is a sentinel (dummy) node for?

  16. W5-M16 تعليل

    A singly linked list with a tail reference. Removing the last node costs:

  17. W5-M17 تذكّر

    Python's collections.deque is implemented as:

  18. W5-M18 تعليل

    Why does the traversal loop test while node is not None: rather than while node.next is not None:?

  19. W5-M19 تطبيق

    After a = Node(1), b = Node(2, a), c = Node(3, b), what is c.next.next.value?

  20. W5-M20 تذكّر

    In Python, what happens to a node that nothing refers to any more?

  21. W5-M21 تطبيق

    To insert a new node at index i ≥ 1, you walk to the node at index:

  22. W5-M22 تذكّر

    Where in this course do short linked lists appear inside another structure?

  23. W5-M23 تعليل

    What is printed?

    ll = LinkedList([1, 2, 3, 4])
    node = ll.head.next
    node.next = node.next.next
    print(list(ll), len(ll))
  24. W5-M24 تطبيق

    On a list of 6 nodes, insert_at(4, x) runs. How many times does prev = prev.next run?

  25. W5-M25 تذكّر

    ll = LinkedList([1, 2, 3]). Which call raises IndexError?

  26. W5-M26 تذكّر

    In a list with a sentinel node, the list is empty when:

  27. W5-M27 تطبيق

    In a doubly linked list, x is a node that is neither the first nor the last. Which two assignments remove it from the list?

  28. W5-M28 تطبيق

    A new node is inserted between two neighbouring nodes a and b of a doubly linked list. How many references must be set, counting the new node's own?

  29. W5-M29 تعليل

    A student adds _tail to the list. Their append decides "empty" by testing self._tail is None, and their pop_front updates head and _size but never _tail. What does this print?

    ll = LinkedList([7])
    ll.pop_front()
    ll.append(5)
    print(list(ll), len(ll))
  30. W5-M30 تطبيق

    reverse() runs on 1 → 2 → 3. After the first pass of the loop body, what is the state?

  31. W5-M31 تعليل

    Suppose insert_at had no index == 0 case and went straight to the walk. What would insert_at(0, 9) do to [1, 2, 3]?

  32. W5-M32 تذكّر

    ll = LinkedList([4, 2, 4]), then ll.remove(4). Now list(ll) is:

  33. W5-M33 تعليل

    Walking a dynamic array and walking a linked list are both O(n), yet the array walk is usually several times faster. Why?

  34. W5-M34 تعليل

    In a circular list the last node points back to the first. What does the usual loop while node is not None: do on it?

  35. W5-M35 تطبيق

    What is printed?

    a, b, c = Node(1), Node(2), Node(3)
    a.next = b
    b.next = c
    b.next, c.next = None, b
    print(a.next.value, c.next.value, b.next)
  36. W5-M36 تذكّر

    LinkedList().pop_front():

  37. W5-M37 تعليل

    You hold a reference node to a node in the middle of a long singly linked list. Inserting a new node immediately before it costs:

  38. W5-M38 تطبيق

    What is printed?

    ll = LinkedList()
    for v in [3, 1, 2]:
        ll.push_front(v)
    ll.append(ll.pop_front())
    print(list(ll))
  39. W5-M39 تذكّر

    insert_at(2, x) on a singly linked list of 5 nodes. How many references held by nodes that were already in the list change?

  40. W5-M40 تعليل

    A singly linked list with head and _tail is reversed in place. What must happen to _tail?

33 درجات

أسئلة المقال

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

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

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

    Compare a dynamic array and a singly linked list on four operations, with their costs. For each structure, give one situation where you would choose it, and say why.

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

    Explain push_front step by step with a diagram. Show what goes wrong if the two assignments are done in the other order.

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

    LinkedList supports ll[i], just like an array. Explain why the cost is different, and why for i in range(len(ll)): ll[i] is a bad loop. What should be written instead?

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

    A tail reference makes append O(1). What does it cost? Name the methods that must change, and explain why removing the last node is still O(n).

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

    Explain what a doubly linked list and a sentinel node each fix, and what each costs.

  6. W5-E6 تعليل 4 درجات

    A music player keeps a playlist. The user presses next and previous, and can delete the song that is playing. Which structure would you choose: a dynamic array, a singly linked list or a doubly linked list? Give the cost of each of the three actions in your choice, and say why each of the other two is worse.

  7. W5-E7 تطبيق 4 درجات

    Explain insert_at(index, value) step by step: the check on index, the case index == 0, the walk, and the splice. Why does the walk stop after index - 1 steps? Give the best-case and worst-case cost, and show what goes wrong if the loop is written for _ in range(index):, both for an index in the middle and for index == len(ll).

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

    A linked list and a dynamic array are both O(n) to walk, yet measurement shows the array is faster and smaller. Explain both differences, with numbers for CPython. When is the linked list still the right choice?

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

    Explain how reverse() reverses a list in place with three references. State what prev and current mean at the start of each pass of the loop, why following must be saved first, and why the extra space is O(1). Compare with building a reversed copy with push_front.