Open In App
Related Articles

Difference between Singly linked list and Doubly linked list

Improve Article
Improve
Save Article
Save
Like Article
Like

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.

 

linkedlist

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. 

 

dll

Singly linked list vs Doubly linked list 
 

Singly linked list (SLL) Doubly linked list (DLL)
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.
linkedlist dll
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(n / 2) = O(n) because traversal can be made from start or from the end.
Complexity of deletion with a given node is O(n), because the previous node needs to be known, and traversal takes O(n) Complexity of deletion with a given node is O(1) because the previous node can be accessed easily
We mostly prefer to use singly linked list for the execution of stacks. We can use a doubly linked list to execute heaps and stacks, binary trees.
When we do not need to perform any searching operation and we want to save memory, we prefer a singly linked list. In case of better implementation, while searching, we prefer to use doubly linked list.
A singly linked list consumes less memory as compared to the doubly linked list. The doubly linked list consumes more memory as compared to the singly linked list.
Singly linked list is less efficient.
It is preferred when we need to save memory and searching is not required as pointer of single index is stored.
Doubly linked list is more efficient.
When memory is not the problem and we need better performance while searching, we use doubly linked list.

 

Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated : 08 May, 2023
Like Article
Save Article
Similar Reads
Related Tutorials