What is Circular Linked List ? What are Advantages and Disadvantages of Circular Linked List
In it the last node does not contain NULL pointer. Instead the last node contains a pointer that has the address of first node and thus points back to the first node. |
Advantages of Doubly linked list over singly linked list
1) A doubly linked list can be travel across in both forward and backward direction.
2) For delete operation a pointer to previous node is needed that is difficult in singly linked list so we need to traverse the list but in doubly linked list the previous node can be found easily using previous pointer.
Disadvantages of Doubly linked list over singly linked list
1) In doubly linked list extra space is required for previous pointer.
2) In all operations like insertion and deletion, an extra pointer (previous pointer) has to be maintained.
Circular Linked List
In Circular linked list all nodes are connected in such way that they form a circle and no NULL at the end of the list like a circle.
Advantages of Circular Linked Lists:
1) In this linked list any node can be a starting point. And to traverse list, we can start at any point and stop when the first node is visited again.
2) Unlike doubly linked list, in this linked list we don’t need to focus on two pointers for next and previous. So it is useful implementing a queue.
3) It is also useful for repeating list. For example operating system, so that when it reaches the end of the list of all application it can go to the front of the list
4) Circular DLL are used to implement advanced data structures like Fibonacci Heap.
Singly, Doubly & Circular Linked List
Singly | Doubly | Circular | |
---|---|---|---|
Concept | One way direction | Two way direction | One way direction in a circle |
Has head | Yes | Yes | No-because tail will refer to first node |
Has tail | Yes | Yes | Yes |
No of Node | 1-next node | 2-next node & previous node | 1-next node |
insert() | O(n) | O(1) | O(n) |
delete() | O(n) | O(1) | O(1) |
Benefit | require small space for each element | allow to traverse the list in both directions | execute to the end can be quickly |