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 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.
[Figure: a singly linked list of nodes drawn left to right, each node a two-cell box with a right-pointing arrow to the next node. The first (leftmost) node is labelled by an upward arrow from the word "head". A row of dots indicates further nodes in between. The last (rightmost) node is labelled by an upward arrow from the word "tail", and its next-pointer cell points to a ground symbol (null terminator).]
Which one of the following is the time complexity of the most time-efficient implementation of enqueue and dequeue, respectively, for this data structure?
Tap to open full sizeFigure description
A non-circular singly linked list drawn left to right: each node is a box split into a data cell and a next-pointer cell, with an arrow from the pointer cell to the next node's box. The head pointer points (upward arrow) to the first node. A row of dots between the second node and the last node indicates additional nodes. The tail pointer points (upward arrow) to the last node, whose next-pointer cell points to a ground/earth symbol representing NULL — confirming the list is singly linked (no backward links) and non-circular.
- (A)
- (B)
- (C)
- (D)