A singly linked list contains the distinct node objects shown. The variable q refers to B, and the separate variable r refers to C. Each node has integer value and reference next fields. Execute the following Python function call with no other code running. Which statements are true? Select all that apply.
def remove_at(q): q.value = q.next.value q.next = q.next.next remove_at(q)
The reference r still reaches C, so bypassing C does not remove every route to that node.
The same function also removes the final node, because its next field contains None.
Traversing from head visits values 10, 30 and 40, while q still refers to B.
The reference r now refers to B because B receives the value originally stored in C.
Unlock full course notes by signing up
Count repeated traversal work
A reporting routine visits a singly linked list containing exactly n nodes. It runs the Python code below, where visit reads a value without changing any nodes or references. For each list length, enter the exact integer number of calls to visit and executions of p = p.next over the entire routine. Count only that explicit advance statement, excluding p = head.
Trace consecutive node removals
A singly linked list initially stores 8, 3, 4, 9, 2 and 7 in that order. Each node has value and next fields. Run the following Python code once. Determine the final value of removed, in nodes, and the sum of the values still reachable from head. Give both answers as exact integers.
Trace an in-place reversal
A singly linked list holds the values 4, 9, 2 and 7, in that order from the head, with the last node's link set to null. Every value is distinct, so you can name each node by its value. The list is reversed in place by this loop:
For each pass through the loop body, fill in the value the link of the current node is set to, then the node that prev refers to and the node that curr refers to at the end of that pass. Write each node as its value, and write null for the empty reference.