A playback service stores nnn items in a doubly linked list with head, tail, and a stored length. The list has no extra boundary nodes. Each node stores next and prev references.
An operation takes constant time, written O(1)O(1)O(1), when its number of basic operations is bounded independently of nnn. Count link work only; assume allocating or releasing one node takes constant time. Reversing the list means changing its actual links so traversal through next gives the reversed order.
Which statements are true? Select all that apply.
Appending one new item through the stored tail reference takes constant time.
Locating the middle item through the closer endpoint takes constant time.
Reversing the actual list links by exchanging only head and tail takes constant time.
Deleting an interior item through a supplied node reference takes constant time.
Unlock full course notes by signing up
Reversing links without losing your place
An editing application stores four pages in a doubly linked list. Initially, head references A, tail references D, A.prev is null, and D.next is null.
You need an in-place reversal: reverse the list by changing links in its existing nodes, without allocating nodes or moving their stored page data. Only head and tail provide persistent endpoint references.
Arrange the stages into the correct execution order. Some stages run once for each node. Exchanging two fields means swapping their values without losing either value.
Accounting for both links and padding
A document application stores 1,250 records in a doubly linked list. Each node stores 18 bytes of record data, an 8-byte next reference, and an 8-byte prev reference. Null references still occupy their full 8-byte fields.
Each node's allocated size is rounded up to the smallest multiple of 8 bytes that can hold these fields. The extra unused bytes are padding. Assume all padding occurs after the fields, and there is no other per-node allocation overhead.
The list also has one separate header containing an 8-byte head reference, an 8-byte tail reference, and an 8-byte length field. The header needs no additional padding, and there is no other storage to count.
Tracing a faulty range move
A job editor initially stores nodes A through H in that order in a doubly linked list. head points to A, tail points to H, A.prev = null, and H.next = null. There are no extra boundary nodes.
A programmer intends to move the consecutive range B, C, D immediately after G. The variables first, last, and destination hold references to B, D, and G, respectively. These variables continue to refer to those same nodes throughout the code.
The following faulty Python-style code changes node fields. Execute assignments in the written order; do not substitute the intended result.
When every local link check passes
A playlist's doubly linked list has head = A, tail = D, and a recorded length of 6. The six nodes below are all allocated and are all claimed to belong to this one list. No nodes are inserted, removed, or modified during inspection.
A node passes the reciprocal-link check when both applicable conditions hold: if x.next is not null, then x.next.prev == x; if x.prev is not null, then x.prev.next == x. A condition with a null link passes without following that link.
Complete the inspection report. Count distinct nodes, including each traversal's starting node. Follow next from head or prev from tail until reaching null or a previously visited node. Enter exact integers for counts and yes or no for the final row. A valid list must contain every claimed node in one chain between its endpoints, with reciprocal links and an accurate recorded length.