1,284 views
0 votes
0 votes
What is the time-complexity of Enqueue and Dequeue operations when Queue is implemented using linked list?

What is the time complexity of inserting a element in single linked list ?

1 Answer

0 votes
0 votes
In linked list if we want to insert  an element in the beginning then time complexity  is O(1)

in linked list if we want to insert an element at the last or in between then time complexity is O(n)

if we want to implement queue using linked list ,in queue we have two pointers front and rear ,insertion is done using rear pointer and deletion is done using rear pointer ,if head of linked list is rear pointer(for insertion) means enqueue operation so time complexity will be O(1) and tail pointer as front pointer (for deletion) means dequeue so time complexity will be O(n)
edited by

Related questions

0 votes
0 votes
1 answer
4
Abhrajyoti00 asked Oct 29, 2022
741 views
Can there be “Stack Overflow” in Linked list Implementation of stack? If Yes, how?