A queue is implemented using a non-circular singly linked list and a circular singly linked list. The queue has a head pointer and a tail pointer, as shown in the figures. 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 ‘dequeue\’ operations for circular singly linked list and non-circular singly linked list data structure respectively?
(A) Θ(1), Θ(N)
(B) Θ(1), Θ(1)
(C) Θ(N), Θ(N)
(D) Θ(N), Θ(1)


Answer: (C)

Explanation: Since, dequeue operation is to delete an element from tail end of the queue. And, deleting from tail end in both of the linked list, we must point next pointer of the node previous to tail to the next of the tail, which can be done only by reaching to that node (just previous to tail). This takes O(N) in both of the cases.

Option (C) is correct.

Quiz of this Question


  • Last Updated : 20 Jan, 2019

Share your thoughts in the comments