Hint: Prev starts NULL, current starts at head [OK]
Common Mistakes:
Setting prev to head initially
Setting current to NULL at start
Initializing next pointer incorrectly
3. What will be the output linked list after running the iterative reverse function on the list: 1 -> 2 -> 3 -> NULL?
medium
A. 2 -> 3 -> 1 -> NULL
B. 3 -> 2 -> 1 -> NULL
C. NULL -> 3 -> 2 -> 1
D. 1 -> 2 -> 3 -> NULL
Solution
Step 1: Trace reversal process
Initially: 1->2->3->NULL. After reversal, links point backward: 3->2->1->NULL.
Step 2: Confirm final head
The last node (3) becomes the new head, so output is 3->2->1->NULL.
Final Answer:
3 -> 2 -> 1 -> NULL -> Option B
Quick Check:
Reverse order of nodes [OK]
Hint: Reverse means last becomes first [OK]
Common Mistakes:
Assuming list stays the same after reversal
Confusing NULL placement
Mixing node order incorrectly
4. Identify the error in this iterative reversal code snippet for a singly linked list in C:
struct Node* reverse(struct Node* head) {
struct Node* prev = head;
struct Node* current = head;
struct Node* next = NULL;
while (current != NULL) {
next = current->next;
current->next = prev;
prev = current;
current = next;
}
return prev;
}
medium
A. prev should be initialized to NULL, not head
B. current should be initialized to NULL, not head
C. next pointer is not updated inside the loop
D. Function should return current, not prev
Solution
Step 1: Check pointer initialization
Prev must start as NULL because the new tail node points to NULL, not head.
Step 2: Analyze loop pointer updates
Current and next are correctly updated; only prev initialization is wrong.
Final Answer:
prev should be initialized to NULL, not head -> Option A
Quick Check:
Prev NULL to mark new tail [OK]
Hint: Prev must start NULL to avoid cycle [OK]
Common Mistakes:
Starting prev at head causing cycle
Not updating next inside loop
Returning wrong pointer at end
5. Given a singly linked list with nodes containing values 10 -> 20 -> 30 -> 40 -> NULL, write the final linked list after applying iterative reversal twice in a row.
hard
A. NULL
B. 40 -> 30 -> 20 -> 10 -> NULL
C. 10 -> 20 -> 30 -> 40 -> NULL
D. 20 -> 10 -> 40 -> 30 -> NULL
Solution
Step 1: Reverse the list once
Original: 10->20->30->40->NULL. After first reversal: 40->30->20->10->NULL.
Step 2: Reverse the reversed list again
Reversing 40->30->20->10->NULL returns it to original: 10->20->30->40->NULL.
Final Answer:
10 -> 20 -> 30 -> 40 -> NULL -> Option C
Quick Check:
Double reversal restores original list [OK]
Hint: Reversing twice returns original list [OK]
Common Mistakes:
Assuming double reversal changes list order
Confusing node values after reversal
Forgetting NULL at list end
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.