59,417 views
3 3 votes
Which of the following is true about linked list implementation of queue?
(a) In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end.
(b) In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be
removed from the beginning.   
(c) Both of the above
(d) None of the above

Answer is (C)

But my doubt here is that:-

If we are allowed to use only singly linked list then option a) will take O(n) time to remove a node from the end of the linked list. So, in this case i.e. in case of singly linked list with O(1) TC answer should be (b)

But If we are allowed to use doubly linked list then answer should be C only

ryt?

4 Answers

1 1 vote

Correct answer is C

both (a) and (b) are correct.

In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end.
In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning. 

Time complexity has nothing to do in this question whether it is O(1) or O(n). 

1 1 vote
According to the question we need not worry about the TIME COMPLEXITY. Just we need to check whether it is going to worry or not that's it
0 0 votes
The correct answer is (b). In a linked list implementation of queue, new nodes are inserted at the end in the push operation and removed from the beginning in the pop operation.
0 0 votes

Think in one simple rule:

In Queue using linked list, insertion and deletion happen at opposite ends.

So:

  • Insert at front → Delete at rear.

  • Insert at rear → Delete at front.

  • Both valid.

Position:
Show:

Related questions

2 2 votes
1 answers 1 answer
10.7k
10.7k views
rahul sharma 5 asked Sep 28, 2017
10,739 views
if we implement queue using singly linked list then how juch time enqueue enqueue and dequeue will take ?
2 2 votes
1 1 answer
4.0k
4.0k views
Shubham Kumar Gupta asked Oct 26, 2017
3,976 views
Which of the following operations is performed more efficiently by doubly linked list than by linear linked list?(a). Deleting a node whose location is given.(b). Searchi...
3 3 votes
1 1 answer
652
652 views
ASUR asked Oct 26, 2025
652 views
Suppose that we use a linked list to represent a queue and that in addition to the enqueue and dequeue functions add a new operation to the queue that deletes the last el...
0 0 votes
1 1 answer
1.1k
1.1k views
Aghori asked Aug 18, 2017
1,071 views
Why the following code is not giving desired results? The code simple push & appends the nodes in the linked list.#include <stdio.h #include <stdlib.h struct Node{ int it...