What is the advantage of singly linked list?

Here you will learn about advantages and disadvantages of linked list.

It is a data structure in which elements are linked using pointers. A node represents an element in linked list which have some data and a pointer pointing to next node. Its structure looks like as shown in below image.

What is the advantage of singly linked list?

There are various merits and demerits of linked list that I have shared below.

Advantages of Linked List

Dynamic Data Structure

Linked list is a dynamic data structure so it can grow and shrink at runtime by allocating and deallocating memeory. So there is no need to give initial size of linked list.

Insertion and Deletion

Insertion and deletion of nodes are really easier. Unlike array here we don’t have to shift elements after insertion or deletion of an element. In linked list we just have to update the address present in next pointer of a node.

No Memory Wastage

As size of linked list can increase or decrease at run time so there is no memory wastage. In case of array there is lot of memory wastage, like if we declare an array of size 10 and store only 6 elements in it then space of 4 elements are wasted. There is no such problem in linked list as memory is allocated only when required.

Implementation

Data structures such as stack and queues can be easily implemented using linked list.

Disadvantages of Linked List

Memory Usage

More memory is required to store elements in linked list as compared to array. Because in linked list each node contains a pointer and it requires extra memory for itself.

Traversal

Elements or nodes traversal is difficult in linked list. We can not randomly access any element as we do in array by index. For example if we want to access a node at position n then we have to traverse all the nodes before it. So, time required to access a node is large.

Reverse Traversing

In linked list reverse traversing is really difficult. In case of doubly linked list its easier but extra memory is required for back pointer hence wastage of memory.

Video Tutorial


If you know some other advantages and disadvantages of linked list then please mention by commenting below.

Linked List – Linked List consists of nodes attached to each other where every node holds the address of the other node.

We can create two types of linear linked List 

  1. Singly Linked List
  2. Doubly Linked List

What is a Singly Linked List?

A Singly Linked List consists of Nodes attached to each other where each node has two members – ‘data’ and ‘next’ .’data’ is the data of the nodes and ‘next’ stores the address of the next node.

Here is the diagrammatic representation of singly Linked List

What is the advantage of singly linked list?

Advantages of Singly Linked List

  • Less memory is required for storing the members (2 members – data and next)
  • During execution, we can deallocate or allocate memory very easily.
  • Insertion and Deletion don’t require the shifting of all elements as required in the array.

Disadvantages of Singly Linked List

  • Insertion and Deletion of element require O(N) time.
  • Accessing the previous node is not possible since we do not have prev pointer.

What is a Doubly Linked List?

Doubly Linked List consists of Nodes attached to each other where each node has three members – ‘data’, ‘prev’ and  ‘next’ .’data’ is the data of the nodes,’ prev’ stores the address of the previous node, and ‘next’ stores the address of the next node.

Here is the diagrammatic representation of Doubly Linked List

What is the advantage of singly linked list?

Advantages of Doubly Linked List

  • Traversal can be done in both directions (either forward or backward since we are now available with two pointers – next and prev)
  • Accessing the previous node easy since we have prev pointer.
  • Insertion and Deletion of element require O(1) time.
  • Insertion and Deletion don’t require the shifting of all elements as required in the array.
  • During execution, we can deallocate or allocate memory very easily.

Disadvantages of Doubly Linked List

  • More memory is required for storing the members (3 members – data , prev and next)
  • Random Access is not available since elements are stored randomly where every node points to other nodes which is present randomly.

Now let us analyze the difference between Singly Linked List and Doubly Linked List.

S.No.ParametersSingly Linked List (SLL)Doubly Linked List (DLL)
1.MembersIt has two members – data and next (‘data’ for holding the data of the current node and ‘next’ for holding the address of the next node)It has three members – data, prev, and next (‘data’ for holding the data of the current node, ‘prev’ for storing the address of the previous node, and ‘next’ for storing the address of the next node)
2.DirectionalIt is unidirectional since traversing can be done using the next pointer only.It is bidirectional since traversing can be done using the next and prev pointer.
3.Insertion and Deletion operationInsertion and deletion can be done in O(n)Insertion and deletion can be done in O(1)
4.MemoryIt requires less memory since we need 2 members.It requires more memory since we need 3 members.

Some Important Questions on LinkedList:

Special thanks to Gurmeet Singh for contributing to this article on takeUforward. If you also wish to share your knowledge with the takeUforward fam, please check out this article

Que-    Advantage and Disadvantage of singly Linked list and Doubly Linked list


SINGLY LINKED LIST


*ADVANTAGE :-
1) Insertions and Deletions can be done easily.
2) It does not need movement of elements for insertion and deletion.
3) It space is not wasted as we can get space according to our requirements.
4) Its size is not fixed.
5) It can be extended or reduced according to requirements.
6) Elements may or may not be stored in consecutive memory available,even then we can store the data in computer.
7) It is less expensive.


*DISADVANTAGE :-
1) It requires more space as pointers  are also stored  with information.
2) Different amount of time is required to access each element.
3) If we have to go to a particular element then we have to go through all those elements that come before that element.
4) we can not traverse it from last & only from the beginning.
5) It is not easy to sort the elements stored in the linear linked list.



-----------------------------------------------------------------------------------------------------------

DOUBLY LINKED LIST

*ADVANTAGE :-

1) We can traverse in both direction i.e from starting to end & as well as from end to starting.
2) It is easy to reverse the linked list.
3) If we are at a node,the we can go at any node.But in linked list,it is not possible to reach the previous node.



*DISADVANTAGE :-

1) It requires more space per space per node because extra field is required for pointer to previous node.
20 Insertion and Deletion take more time than linear linked list because more pointer operations are required than linear linked list.