What is the main idea behind reversing a singly linked list iteratively?
We change the direction of each node's pointer one by one, so the list points backward instead of forward.
Click to reveal answer
beginner
In the iterative reversal of a singly linked list, which pointers do we typically use?
We use three pointers: previous (initially null), current (starting at head), and next (to store current's next node).
Click to reveal answer
intermediate
Why do we need to store the next node before changing the current node's next pointer?
Because once we reverse the pointer, we lose the original next node. Storing it first lets us continue traversing the list.
Click to reveal answer
beginner
What is the time complexity of reversing a singly linked list iteratively?
It is O(n), where n is the number of nodes, because we visit each node exactly once.
Click to reveal answer
beginner
Show the final state of the list after reversing: 1 -> 2 -> 3 -> null
After reversal, the list becomes: 3 -> 2 -> 1 -> null
Click to reveal answer
Which pointer should initially be set to null when reversing a singly linked list iteratively?
Aprevious
Bcurrent
Cnext
Dhead
✗ Incorrect
The previous pointer starts as null because the new tail node will point to null.
What happens to the current node's next pointer during each iteration?
AIt is set to null
BIt is set to next node
CIt remains unchanged
DIt is set to previous node
✗ Incorrect
We reverse the pointer by setting current's next to previous.
Why do we need a 'next' pointer in the iterative reversal?
ATo mark the end of the list
BTo keep track of the next node before changing pointers
CTo store the previous node
DTo count the nodes
✗ Incorrect
We save the next node to continue traversal after reversing the pointer.
What is the new head of the list after reversal?
AThe original tail node
BThe original head node
CNull
DThe middle node
✗ Incorrect
After reversal, the original tail becomes the new head.
What is the space complexity of iterative reversal of a singly linked list?
AO(log n)
BO(n)
CO(1)
DO(n^2)
✗ Incorrect
We only use a few pointers, so space complexity is constant.
Explain step-by-step how to reverse a singly linked list using iteration.
Think about how pointers move and change direction.
You got /7 concepts.
Describe why storing the next node before reversing pointers is important in iterative reversal.
Imagine walking backward but needing to know where to go next.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the iterative method to reverse a singly linked list?
easy
A. To sort the nodes in ascending order
B. To delete all nodes from the list
C. To change the direction of the links between nodes one by one
D. To add new nodes at the end of the list
Solution
Step 1: Understand the linked list structure
A singly linked list has nodes connected in one direction through next pointers.
Step 2: Purpose of iterative reversal
The iterative method changes each node's next pointer to point backward, reversing the list.
Final Answer:
To change the direction of the links between nodes one by one -> Option C
Quick Check:
Reversing = changing links direction [OK]
Hint: Reversing means flipping the links one by one [OK]
Common Mistakes:
Thinking reversal deletes nodes
Confusing reversal with sorting
Assuming reversal adds nodes
2. Which of the following is the correct way to initialize pointers for iterative reversal of a singly linked list in C#?
easy
A. Node prev = head; Node current = null;
B. Node prev = null; Node current = null;
C. Node prev = head; Node current = head.next;
D. Node prev = null; Node current = head;
Solution
Step 1: Initialization for reversal
We start with prev as null because the new tail will point to null, and current at head to traverse.
Step 2: Check each option
Only Node prev = null; Node current = head; correctly sets prev to null and current to head for iteration.
Final Answer:
Node prev = null; Node current = head; -> Option D
Quick Check:
Start prev=null, current=head [OK]
Hint: Prev starts null, current starts at head [OK]
Common Mistakes:
Setting prev to head initially
Setting current to null
Both pointers null at start
3. What will be the output linked list after running this code snippet on list 1 -> 2 -> 3 -> null?
Node prev = null;
Node current = head;
while (current != null) {
Node nextTemp = current.next;
current.next = prev;
prev = current;
current = nextTemp;
}
head = prev;
medium
A. 1 -> 2 -> 3 -> null
B. 3 -> 2 -> 1 -> null
C. null
D. 1 -> null
Solution
Step 1: Trace the reversal loop
Each iteration reverses the link: 1 points to null, 2 points to 1, 3 points to 2.
Step 2: Final linked list after loop
After loop, prev points to 3, which is new head: 3 -> 2 -> 1 -> null.
Final Answer:
3 -> 2 -> 1 -> null -> Option B
Quick Check:
Reversed list = 3->2->1 [OK]
Hint: Reversal flips list order completely [OK]
Common Mistakes:
Assuming list stays same
Forgetting to update head
Confusing next and prev pointers
4. Identify the error in this iterative reversal code snippet:
Node prev = head;
Node current = head.next;
while (current != null) {
Node nextTemp = current.next;
current.next = prev;
prev = current;
current = nextTemp;
}
head.next = null;
head = prev;
medium
A. prev should be initialized to null, not head
B. current should start at head, not head.next
C. head.next should not be set to null
D. No error, code is correct
Solution
Step 1: Check pointer initialization
prev must start as null to mark new tail's next as null; starting at head causes cycle.
Step 2: Effect of wrong initialization
Starting prev at head causes the first node to point to itself, creating a loop.
Final Answer:
prev should be initialized to null, not head -> Option A
Quick Check:
Prev must be null at start [OK]
Hint: Prev must start null to avoid cycles [OK]
Common Mistakes:
Starting prev at head causing loops
Not setting head.next to null after reversal
Starting current at wrong node
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.