A. head->next is set to head instead of NULL causing a cycle
B. Missing base case for empty list
C. Incorrect return value; should return head
D. No recursive call made
Solution
Step 1: Analyze pointer assignments
head->next->next = head correctly points next node back to current node.
Step 2: Identify incorrect pointer reset
head->next = head wrongly points current node's next to itself, causing a cycle instead of NULL.
Final Answer:
head->next is set to head instead of NULL causing a cycle -> Option A
Quick Check:
head->next must be NULL, not head [OK]
Hint: Set head->next to NULL to avoid cycles [OK]
Common Mistakes:
Setting head->next to head causing infinite loop
Forgetting to return the new head
Not handling base case properly
5. Given a singly linked list with nodes containing values 10 -> 20 -> 30 -> 40 -> NULL, what will be the printed output after applying this recursive reverse function?
Node* reverse(Node* head) {
if (!head || !head->next) return head;
Node* rest = reverse(head->next);
head->next->next = head;
head->next = NULL;
return rest;
}
void printList(Node* head) {
while (head) {
printf("%d -> ", head->data);
head = head->next;
}
printf("NULL\n");
}
int main() {
// List creation omitted for brevity
Node* reversed = reverse(head);
printList(reversed);
}
hard
A. 40 -> 30 -> 20 -> 10 -> NULL
B. 10 -> 20 -> 30 -> 40 -> NULL
C. NULL
D. 40 -> 20 -> 30 -> 10 -> NULL
Solution
Step 1: Trace recursive reversal on list 10->20->30->40
Recursion reverses from last node: 40 becomes new head, pointers reversed stepwise.
Step 2: Confirm print output
Print function outputs nodes in order: 40 -> 30 -> 20 -> 10 -> NULL.
Final Answer:
40 -> 30 -> 20 -> 10 -> NULL -> Option A
Quick Check:
Reverse(10->20->30->40) = 40->30->20->10 [OK]
Hint: Last node becomes head; print from new head [OK]
Common Mistakes:
Assuming original order remains after reverse
Forgetting to set last node's next to NULL
Confusing print output with input list
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.