GATE CS 2022 · Question 15 · Programming and Data Structures · Multiple choice (MCQ) · 1 mark · −1/3 for a wrong answer

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?

A singly linked list. A pointer labelled 'head' points to the node with value a. Node a points to node b, b points to c, c points to d, d points to e. The next field of node e is null, drawn as a ground symbol. Order: head -> a -> b -> c -> d -> e -> null.
The reversed singly linked list. A pointer labelled 'head' points to the node with value e. Node e points to d, d points to c, c points to b, b points to a. The next field of node a is null, drawn as a ground symbol. Order: head -> e -> d -> c -> b -> a -> null.
  1. (A) The best algorithm for the problem takes θ(n) time in the worst case.
  2. (B) The best algorithm for the problem takes θ(n log n) time in the worst case.
  3. (C) The best algorithm for the problem takes θ(n²) time in the worst case.
  4. (D) It is not possible to reverse a singly linked list in O(1) space.
Answer

Answer (A)

Answer from the official GATE CS 2022 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes