Question
Official answer and solution
- Official answer
- A
- From
- Official GATE 2022 answer key
Solution
Evaluate the standard iterative three-pointer algorithm for in-place linked list reversal.
A singly linked list with nodes can be reversed in-place using three pointers (prev, curr, next):
- Initialize
prev = NULLandcurr = head. - In each iteration, save
next = curr->next, reverse the link by settingcurr->next = prev, then advanceprev = currandcurr = next. - The loop visits each node exactly once, performing pointer assignments per node.
This algorithm requires auxiliary space and runs in time in both best and worst cases. Since any algorithm must examine all nodes to reverse the list, time is a lower bound, making the tight worst-case time complexity. This confirms Option (A) is TRUE.
Option (A)
Assuming recursive reversal is required, which uses call stack space.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2022 Computer Science and Information Technology (CS)
- Question
- 15 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.