GateAI
Linear Structures, Trees and Heaps

GATE CSE 2022 · Q15

MCQ1 markEasy

Time

Consider the problem of reversing a singly linked list. To take an example, given the linked list below, the reversed linked list should look like

Which one of the following statements is TRUE about the time complexity of algorithms that solve the above problem in O(1)O(1) space?

GATE CSE 2022 Q15 diagram 1
GATE CSE 2022 Q15 diagram 2

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) The best algorithm for the problem takes (n) time in the worst case.

Linear Structures, Trees and Heaps

A singly linked list with nn nodes can be reversed in-place using three pointers (prev, curr, next) in $O(1)$ auxiliary space.

In this iterative algorithm:

  • We iterate through each node once from head to tail.

  • At each step, the next pointer of the current node is reversed to point to prev.

  • A total of nn nodes are visited and processed in constant time per node.

Thus, the algorithm runs in Θ(n)\Theta(n) (or θ(n)\theta(n)) time in the worst case using O(1)O(1) space. Since every node's pointer must be modified, Ω(n)\Omega(n) is also the lower bound, making θ(n)\theta(n) the best possible time complexity.

Therefore, option A is the correct statement.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Linear Structures, Trees and Heaps previous year question is Q15 of the GATE CSE 2022 paper. Find more GATE CSE PYQs on Linear Structures, Trees and Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Linear Structures, Trees and Heaps PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Linear Structures, Trees and Heaps in GATE CSE

Linear Structures, Trees and Heaps has 14 GATE CSE PYQs across 12 papers from 2012 to 2026. 7 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2022.

How GATE tests Linear Structures, Trees and Heaps

More from GATE CSE 2022

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2022 · Q15 · MCQ

Consider the problem of reversing a singly linked list. To take an example, given the linked list below, the reversed linked list should look like Which one of the following statements is TRUE about the time complexity of algorithms that solve the above problem in O(1) space?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.