ITPEC FE Subject B October 2025 Question 7

Source exam: ITPEC FE Subject B October 2025Topic: Linked List

ITPEC FE Subject B October 2025 — Question 7 of 20

The function reverseList(head, elm) reverses a singly linked list recursively. head is the current node being processed, and elm is the previously processed node (starts as undefined).

  • Recursive step: If head.next is not undefined, recurse with reverseList(head.next, head) — move forward in the list, passing the current node as the new "previous"
  • Base case: When head.next is undefined, we've reached the last node — it becomes the new listHead
  • Re-linking: After recursion, set head.next ← elm to reverse the pointer direction
BlankValueWhy
Ahead.nextWe recurse on the next node, passing current head as the accumulated reversed tail
BelmEach node's next pointer is redirected to the previous node (elm)

Why not others:
- b) elm.next for B would point head to a node further back, breaking the chain

- c) elm.next for A would skip the natural traversal order; head.next.next for B makes no sense

- d) elm.next for A is wrong — we traverse via head.next, not elm.next

- e) Same problem as d) for A; elm.next for B creates incorrect linkage

Key rule: In recursive linked list reversal, each call processes the next node (head.next) and re-links the current node to point back to the previous node (elm).

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.