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

A queue is implemented using a non-circular singly linked list. The queue has a head pointer and a tail pointer, as shown in the figure. Let n denote the number of nodes in the queue. Let enqueue be implemented by inserting a new node at the head, and dequeue be implemented by deletion of a node from the tail.
Which one of the following is the time complexity of the most time-efficient implementation of enqueue and dequeue, respectively, for this data structure?

A singly linked list drawn left to right. Each node is a rectangle split into a data field and a next-pointer field. The first node's pointer field has an arrow to the second node, whose pointer field has an arrow to a dotted line '........' indicating more nodes, followed by an arrow to the last node. The last node's pointer field ends in a ground (null) symbol. An upward arrow labelled 'head' points to the first node, and an upward arrow labelled 'tail' points to the last node.
  1. (A) θ(1), θ(1)
  2. (B) θ(1), θ(n)
  3. (C) θ(n), θ(1)
  4. (D) θ(n), θ(n)
Answer

Answer (B)

Answer from the official GATE CS 2018 answer key.

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