Reversing a Linked List
A linked list can be reversed iteratively by maintaining previous, current, and next references. At each step, the current node's next pointer is redirected toward the previous node. A recursive solution reverses the remaining list first and then reconnects the current node.
Iterative time complexity: O(n).
Iterative auxiliary space: O(1).
Recursive time complexity: O(n).
Recursive auxiliary space: O(n) because of the call stack.
The iterative solution is generally safer for very long lists because it avoids stack overflow.