![]() |
VOOZH | about |
A Doubly Linked List (DLL) contains an extra pointer, typically called the previous pointer, together with the next pointer and data which are there in a singly linked list.
Below are operations on the given DLL:
Below is the implementation of all the operations:
Linked List: 2 4 9 1 21 22 Linked List after inserting 1 at beginning: 1 2 4 9 1 21 22 Linked List after inserting 0 at end: 1 2 4 9 1 21 22 0 Linked List after inserting 44 after 3rd Node: 1 2 4 44 9 1 21 22 0 Linked List after deleting node at beginning: 2 4 44 9 1 21 22 0 Linked List after deleting node at end: 2 4 44 9 1 21 22 Linked List after deleting node at position 5: 2 4 44 9 21 22
Time and Space of Complexity of Each Operation :
Add a node at the front of DLL:
Time Complexity: O(1)
Space Complexity: O(1)
Traversal of a Doubly linked list:
Time Complexity: O(n)
Space Complexity: O(1)
Insertion of a node at the beginning:
Time Complexity: O(1)
Space Complexity: O(1)
Insertion of a node at the end:
Time Complexity: O(1)
Space Complexity: O(1)
Insertion of a node at a given position:
Time Complexity: O(n)
Space Complexity: O(1)
Deletion of a node at the beginning:
Time Complexity: O(1)
Space Complexity: O(1)
Deletion of a node at the end:
Time Complexity: O(1)
Space Complexity: O(1)
Deletion of a node given the position:
Time Complexity: O(n)
Space Complexity: O(1)