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]. |
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]. |
Singly Linked List vs Doubly Linked List
Before looking at the differences between the singly linked list and doubly linked list, we first understand what is singly linked list and doubly linked list separately.
What is Single Linked List
A linked list is a linear data structure that consists of a group of nodes in a sequence. A node or an element consists of data and the address of another node. A single linked list is a type of linked list.
A single linked list stores the data and the address of the next node in the sequence. As the nodes stores the address of the next node, the nodes are referring to each other. Therefore, it forms a structure similar to a chain. It is possible to perform operations such as inserting, deleting and traversing through the elements in a single linked list.
What is Double Linked List
Similar to a single linked list, a double linked list is also a type of linked list. It is also called a doubly linked list. It stores data and two addresses. These addresses are the address of the next node and the address of the previous node. As there are two references, it is possible to go forward and backward through elements in the double linked list. Furthermore, the programmer can perform operations such as inserting elements and deleting elements in a double linked list.
In addition to these two types, there is another linked list as a circular linked list. In this kind of list, the last node stores the address of the first node. Therefore, it forms a structure similar to a circular chain.
Difference Between Doubly linked list vs Singly linked list
- The singly linked list and doubly linked list is a type of linked list to arrange memory and information.
- The singly linked list and doubly linked list is part of dynamic data structure to avoid memory wastage and traverse using element in the list.
- The doubly linked list is a function that contains data, next node, and previous node simultaneously.
- The singly linked list is a function that contains data and the next node only.
- The singly linked list is a simple linked list to traverse one way from the first node to the next node.
- The doubly linked list is a complex linked list to traverse both ways from one node to another and vice versa.
- The singly linked list contains two parts, such as memory and pointer, but the last pointer becomes null.
- The doubly linked list contains three parts such as a previous pointer, memory node, and next pointer but the initial and last pointer becomes null.
Head to Head Comparison Between Doubly linked list vs Singly linked list [Infographics]
Below are the top differences between Doubly linked list vs Singly linked list
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Key differences between Doubly linked list vs Singly linked list
Some of the key differences between Doubly linked list vs Singly linked list are given below:
- The doubly linked list is bidirectional because of two address pointer. Therefore, a singly linked list is unidirectional because of the one address pointer.
- The doubly linked list has occurred more memory space than the singly linked list.
- The singly linked list simple, whereas the doubly linked list, is a complex dynamic data structure of the list.
- The doubly linked list provides an empty head and tail pointer. Hence, a singly linked list provides an empty tail only.
- The doubly linked list more efficient than the singly list.
- The doubly linked list contains three parameters, and the singly linked list contains two parameters.
- The singly linked list image is given below.
- The doubly linked list image is given below.
- The doubly linked list gives time complexity O[1], whereas the singly linked list gives time complexity O[n].
Comparison table
- The doubly linked list is a complex function, and the singly linked list is a simple data structure.
- The comparison table is displayed features and descriptions of the singly linked list and doubly linked list.
- The below table is showing similarities and differences of the type of the linked list.
Features | doubly linked list | singly linked list |
Definition | The doubly linked list is a complex linked list to manage memory with previous and next pointer. | The singly linked list is a simple linked list to manage memory with the next pointer. |
Function | Organize dynamic data structure or values of the list. | Organize dynamic data structure or values of the list. |
Parameter |
|
|
Algorithm | The doubly linked list algorithm is below. 1] set Pointer = null 2] set New node = pointer 3] set Pointer = pointer -> next 4] set New node -> data = value 5] set New node -> previous = null 6] set New node -> next = start 7] set New head -> previous = New node 8] set New head = New node [continue procedure until last pointer] 9] last pointer -> null = tail 10] exit | The singly linked list algorithm is below. 1] set Pointer = null 2] set New node = pointer 3] set Pointer = pointer -> next 4] set New node -> data = value 5] set New node -> next = new head 6] set New head = New node [continue procedure until last pointer] 7] last pointer -> null = tail 8] exit |
Description | The head pointer and tail are empty. Other nodes are including data. | The tail pointer is empty. The head and other nodes are including data. |
direction | The node pointer addresses forward and reverses direction in the linked list. The doubly linked list supports bidirectional. | The node pointer addresses only the forward direction because of the next node. This linked list does not traverse the reverse direction. The doubly linked list supports unidirectional. |
Memory space | The doubly linked list contains two addresses of the node. This variable takes 8-byte memory space. | The singly linked list contains one address of the node. This variable takes 4-byte memory spaces. |
Time complexity | The time complexity of basic operation such as insert and delete of the list is O [1]. | The time complexity of basic operation such as insert and delete of the list is Popular Course in this category Java Training [40 Courses, 29 Projects, 4 Quizzes]40 Online Courses | 29 Hands-on Projects | 285+ Hours | Verifiable Certificate of Completion | Lifetime Access | 4 Quizzes with Solutions 4.8 [12,280 ratings] Course Price View Course Related Courses Python Training Program [39 Courses, 13+ Projects]HTML Training [12 Courses, 19+ Projects, 4 Quizzes]O [n]. |
complexity | The doubly linked list is complex than a singly linked list to handle and operate data. It is difficult to manage data and its address. | The singly linked list is simple than a doubly-linked list to handle and operate data. It is easy to manage data and its address. |
Operation |
|
|
Advantages and limitations |
|
|
Implementation |
|
|
Real-time Example |
|
|
Conclusion
- The singly linked list and doubly linked list make the application usable, handy, and manageable.
- The singly linked list and doubly linked list helps to manage and operate a list of data.
Recommended Articles
This is a guide to the Doubly linked list vs Singly linked list. Here we discuss the Doubly linked list vs Singly linked list key differences with infographics and comparison table. You may also have a look at the following articles to learn more –
- Snapseed vs Lightroom
- Krita vs Photoshop
- Lumion vs V-Ray
- Lubuntu vs Xubuntu
All in One Software Development Bundle [600+ Courses, 50+ projects]
600+ Online Courses
50+ projects
3000+ Hours
Verifiable Certificates
Lifetime Access
Learn More
Difference Between Singly Linked List vs Doubly Linked List
What Is Singly Linked List?
It is the one of the variation of linked list in which operations of data items and elements are performed or executed in one way direction and it is defined for the storing of that object that further called as nodes and can be stored in memory randomly , there are two fields in singly linked list one is called where these data stores and the second is called pointer and these both link with the data to address them properly. Insertion, deletion and transversal operations are performed in singly linked list.