What is the base case in the recursive reversal of a singly linked list?
The base case is when the current node is null or its next node is null, meaning we have reached the end or the list is empty. This node becomes the new head of the reversed list.
Click to reveal answer
intermediate
In recursive reversal of a singly linked list, what happens after the recursive call returns?
After the recursive call returns, the next node's next pointer is set to the current node, effectively reversing the link between them. Then, the current node's next pointer is set to null to avoid cycles.
Click to reveal answer
beginner
Why do we set the current node's next pointer to null during recursive reversal?
Setting the current node's next pointer to null breaks the original forward link, preventing cycles and correctly terminating the reversed list at the current node.
Click to reveal answer
beginner
What is the time complexity of reversing a singly linked list recursively?
The time complexity is O(n), where n is the number of nodes, because each node is visited exactly once during the recursion.
Click to reveal answer
beginner
Show the recursive function signature for reversing a singly linked list in C#.
public ListNode ReverseList(ListNode head) where ListNode is the node class representing each element in the list.
Click to reveal answer
What does the recursive function return when reversing a singly linked list?
ANull
BThe original head of the list
CThe last node visited before recursion
DThe new head of the reversed list
✗ Incorrect
The recursive function returns the new head of the reversed list after all recursive calls complete.
Which pointer is changed to reverse the link between two nodes in recursion?
ACurrent node's next pointer
BNext node's next pointer
CHead pointer
DPrevious node's next pointer
✗ Incorrect
The next node's next pointer is set to the current node to reverse the link.
What is the base case condition in recursive reversal?
AWhen current node is null or current node's next is null
BWhen current node is the head
CWhen current node's next is the head
DWhen current node's next is not null
✗ Incorrect
The recursion stops when the current node is null or its next is null, indicating the end of the list.
What happens if we don't set current node's next to null during reversal?
AThe recursion will stop early
BThe list will be reversed correctly
CThe list will form a cycle
DThe head will be lost
✗ Incorrect
Not setting current node's next to null causes a cycle, because the old forward link remains.
What is the space complexity of recursive reversal of a singly linked list?
AO(n) due to recursion stack
BO(1) constant space
CO(log n)
DO(n^2)
✗ Incorrect
Recursive calls add to the call stack, so space complexity is O(n).
Explain step-by-step how recursion reverses a singly linked list.
Think about what happens when recursion reaches the end and then unwinds.
You got /5 concepts.
Write the recursive function to reverse a singly linked list and explain each line.
Focus on how the pointers change during recursion.
You got /5 concepts.
Practice
(1/5)
1. What is the main idea behind reversing a singly linked list using recursion?
easy
A. Create a new list and copy nodes in reverse order
B. Swap the values of the first and last nodes only
C. Iterate through the list and reverse pointers in a loop
D. Reverse the rest of the list first, then fix the current node's next pointer
Solution
Step 1: Understand recursion on linked list
Recursion works by solving a smaller part first, here reversing from the next node onward.
Step 2: Fix current node's pointer after recursion
After reversing the rest, the current node's next node points back to it, reversing the link.
Final Answer:
Reverse the rest of the list first, then fix the current node's next pointer -> Option D
Quick Check:
Recursive reversal = reverse rest then fix current [OK]
Hint: Think: reverse smaller list first, then fix current link [OK]
Common Mistakes:
Trying to swap node values instead of pointers
Not fixing the current node's next pointer after recursion
Using iteration instead of recursion
2. Which of the following is the correct base case for a recursive function that reverses a singly linked list?
easy
A. if (head == null) return new Node();
B. if (head.next == null) return null;
C. if (head == null || head.next == null) return head;
D. if (head == null) return head.next;
Solution
Step 1: Identify when recursion should stop
The base case is when the list is empty or has only one node, so no reversal needed.
Step 2: Check the correct base case syntax
Return the head itself if it is null or the last node (head.next == null).
Final Answer:
if (head == null || head.next == null) return head; -> Option C
Quick Check:
Base case = empty or single node returns head [OK]
Hint: Base case: empty or single node returns itself [OK]
Common Mistakes:
Returning null when list has one node
Accessing head.next without checking if head is null
Creating new nodes unnecessarily
3. What will be the output linked list after running this recursive reverse function on the list 1 -> 2 -> 3 -> null?
B. Missing base case for single node; add 'head.next == null' check
C. head.next.next = head causes null pointer; fix by checking head.next
D. No error; code is correct
Solution
Step 1: Check base case correctness
Base case only checks head == null, missing single node case (head.next == null).
Step 2: Consequence of missing base case
Without single node base case, head.next may be null causing head.next.next to throw error.
Final Answer:
Missing base case for single node; add 'head.next == null' check -> Option B
Quick Check:
Base case must handle empty and single node [OK]
Hint: Base case must cover empty and single node to avoid errors [OK]
Common Mistakes:
Ignoring single node base case
Not setting head.next = null after reversal
Returning wrong node as new head
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 == null || head.next == null) return head;
Node newHead = Reverse(head.next);
head.next.next = head;
head.next = null;
return newHead;
}
// After reversal, print list from newHead
hard
A. 40 -> 30 -> 20 -> 10 -> null
B. 10 -> 20 -> 30 -> 40 -> null
C. 40 -> 10 -> 20 -> 30 -> null
D. 30 -> 40 -> 20 -> 10 -> null
Solution
Step 1: Trace recursive reversal on given list
Recursion reverses from last node 40 back to 10, fixing pointers step-by-step.
Step 2: Confirm final reversed list order
After reversal, list order is 40 -> 30 -> 20 -> 10 -> null.
Final Answer:
40 -> 30 -> 20 -> 10 -> null -> Option A
Quick Check:
Recursive reversal reverses entire list order [OK]
Hint: Reversal flips list order completely [OK]
Common Mistakes:
Printing original list instead of reversed
Forgetting to set head.next = null causing cycle
Misreading pointer changes as value swaps
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.