282 views

1 Answer

2 votes
2 votes
Answer is  : Option 2

Reason :

Enqueue is implemented by adding a new node at the head of the linkedlist. This will require constant time as we have to update the pointer to head and new node. Hence it is O(1)

Dequeue is implemented by removing a node from the end of the linkedlist and updating the tail pointer. It is a singly linked list with only next pointer. As we do not have a previous pointer, we’ll have to traverse until the next to next of the node is null. In that case, we’ll traverse the whole list once. Hence, it is O(n).

If we add a previous pointer, queue operations can be made more efficient and it’s complexity will be O(1).

Related questions

0 votes
0 votes
1 answer
1
rsansiya111 asked Dec 20, 2021
516 views
Consider the following C program:#include <stdio.h>int r( ){static int num = 7;return num ;}int main ( ) {for (r( ) ;r ( ) ;r ( ) )printf(“ % d”, r( ) );return 0;}Whi...
0 votes
0 votes
1 answer
2
rsansiya111 asked Dec 17, 2021
311 views
0 votes
0 votes
1 answer
3
rsansiya111 asked Dec 16, 2021
377 views
0 votes
0 votes
1 answer
4
rsansiya111 asked Dec 16, 2021
332 views