54,583 views
1 votes
1 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?

3 Answers

1 votes
1 votes

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). 

0 votes
0 votes
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 votes
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.

Related questions

2 votes
2 votes
1 answer
1
rahul sharma 5 asked Sep 28, 2017
7,955 views
if we implement queue using singly linked list then how juch time enqueue enqueue and dequeue will take ?