GeeksforGeeks » Miscellaneous
Time complexity
(3 posts)-
What is the complexity of insertion and deletion of the following
1) Queue
2)Linked list
3)Queue implemented using linked list -
For Linked List, if we always add a node to the front (or head) and also remove from the front (LIFO), then complexity is O(1) for both insert and delete. We just have to just change few links here and there, we don't need to traverse the complete list.
For queue implementation using Array, both insert and delete can be done in O(1)
For queue implementation using linked list, both operations can be done in O(1) . The only point is we have to keep track of both first node and last node in linked list.
-
student
Reply
You must log in to post.