Difference between Singly linked list and Doubly linked list
Introduction to Singly linked list : A singly linked list is a set of nodes where each node has two fields ‘data’ and ‘link’. The ‘data’ field stores actual piece of information and ‘link’ field is used to point to next node. Basically the ‘link’ field stores the address of the next node.
Introduction to Doubly linked list : A Doubly Linked List [DLL] contains an extra pointer, typically called previous pointer, together with next pointer and data which are there in singly linked list.
Singly linked list vs Doubly linked list
SLL nodes contains 2 field -data field and next link field. | DLL nodes contains 3 fields -data field, a previous link field and a next link field. | |
In SLL, the traversal can be done using the next node link only. Thus traversal is possible in one direction only. | In DLL, the traversal can be done using the previous node link or the next node link. Thus traversal is possible in both directions [forward and backward]. | |
The SLL occupies less memory than DLL as it has only 2 fields. | The DLL occupies more memory than SLL as it has 3 fields. | |
Complexity of insertion and deletion at a given position is O[n]. | Complexity of insertion and deletion at a given position is O[1]. |
Types of Linked List
Before knowing about the types of a linked list, we should know what is linked list. So, to know about the linked list, click on the link given below:
Difference between Singly linked list and Doubly linked list in Java
Both Singly linked list and Doubly linked list are the implementation of Linked list in which every element of singly-linked list contains some data and a link to the next element, which allows to keep the structure. On the other hand, every node in a doubly-linked list also contains a link to the previous node.
The following are the important differences between a Singly linked list and Doubly linked list.
1 | Complexity | In singly linked list the complexity of insertion and deletion at a known position is O[n] | In case od doubly linked list the complexity of insertion and deletion at a known position is O[1] |
2 | Internal implementation | In singly linked list implementation is such as where the node contains some data and a pointer to the next node in the list | While doubly linked list has some more complex implementation where the node contains some data and a pointer to the next as well as the previous node in the list |
3 | Order of elements | Singly linked list allows traversal elements only in one way. | Doubly linked list allows element two way traversal. |
4 | Usage | Singly linked list are generally used for implementation of stacks | On other hand doubly linked list can be used to implement stacks as well as heaps and binary trees. |
5 | Index performance | Singly linked list is preferred when we need to save memory and searching is not required as pointer of single index is stored. | If we need better performance while searching and memory is not a limitation in this case doubly linked list is more preferred. |
6 | Memory consumption | As singly linked list store pointer of only one node so consumes lesser memory. | On other hand Doubly linked list uses more memory per node[two pointers]. |
Types of Linked List - Singly linked, doubly linked and circular
In this tutorial, you will learn different types of linked list. Also, you will find implementation of linked list in C.
Before you learn about the type of the linked list, make sure you know about the LinkedList Data Structure.
There are three common types of Linked List.
- Singly Linked List
- Doubly Linked List
- Circular Linked List