GATE CS 2022 | Question 15

Programming & Data Structures › Structures & Unions · MCQ · 1 mark · Answer: A

  1. Question 15Programming & Data Structuresmcq1 mark
    For reversing a singly linked list in space, which is TRUE about the time complexity?
    • A.
      The best algorithm takes time in the worst case.
      ✓
    • B.
      The best algorithm takes time.
    • C.
      The best algorithm takes time.
    • D.
      It is not possible to reverse a singly linked list in space.

    Answer: A

    Solution

    Answer: (A) time in the worst case Reversing a singly linked list requires rewiring each of the pointers exactly once using three pointers (prev, curr, next) — extra space and time, which is optimal since every node must be visited.

More GATE PYQ on Structures & Unions

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2022 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →