GateAI
Linear Structures, Trees and Heaps

GATE CSE 2018 · Q3

MCQ1 markMedium

Time

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 nn 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?

GATE CSE 2018 Q3 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) (1), (n)

Linear Structures, Trees and Heaps
  1. enqueue (Insertion at head):

    • A new node is allocated, its next pointer is set to the current head, and head is updated to point to the new node.

    • This requires a constant number of operations, taking Θ(1)\Theta(1) time.

  2. dequeue (Deletion from tail):

    • To delete the tail node in a singly linked list, we must update the next pointer of the node preceding the tail to NULL (or ground) and point tail to this predecessor.

    • Since the list is singly linked with pointers directed from head towards tail, there are no backward pointers from tail.

    • Finding the predecessor of the tail node requires traversing all nn nodes from the head.

    • Hence, deletion at the tail takes Θ(n)\Theta(n) time.

Therefore, the time complexities are Θ(1)\Theta(1) and Θ(n)\Theta(n), making (B) the correct option.

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 Q3 of the GATE CSE 2018 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 2018.

How GATE tests Linear Structures, Trees and Heaps

More from GATE CSE 2018

Share this solution

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

GateAI solution cardGATE CSE 2018 · Q3 · MCQ

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?

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.