Linked Lists:
A linked list is a linear data structure.
A linked list in data structures is a collection of elements called nodes, where each node contains
some data and a reference to the next node in the sequence
Types of Linked List
A Linked Lists come in a variety of types, which are listed below:
Singly Linked List
Each element (or node) in a singly linked list stores a value and a pointer to
the next element (or node) in the list. The first node is known as the head
node, while the last node is known as the tail node.
The structure of a singly linked list is as follows:
Doubly Linked List
In a Doubly Linked List, each node in a Doubly Linked List has two pointers,
one pointing to the next node in the list and the other referring to the
previous node in the list.This allows for easy traversal in both directions
Circular Linked List
In a Circular Linked List, the last node in the list points to the first node,
forming a circle. This allows for continuous traversal of the list.
Doubly Circular Linked List
Each node in a doubly circular linked list contains two pointers, one pointing
to the node before it and the other pointing to the node after it, creating a
circular link between the nodes. In a double circular linked list, the last node
points to the first node, making it circular. Additionally, the first node's
previous pointer also points to the last node, making it doubly linked. This
means that elements can be traversed both forward and backward.
Basic Operations In Linked List
When it comes to linked lists, there are five operations supported by the series or list.
Traversal – Through this operation, we can access elements.
Insertion – In this operation, elements can be added at the starting of the list.
Deletion – In this operation, elements can be deleted at the starting of the list.
Search – Through this operation, we can easily search for an element utilising
the provided key.
Sort – Through this operation, we can sort the nodes of the linked list.
Advantages of Linked Lists
A linked list is dynamic, which means it will provide memory whenever needed.
In a linked list, we can swiftly execute the operations like insertion and deletion.
We can easily implement stacks and queues.
It helps in reducing the access time.
Disadvantages of Linked Lists
Sometimes the memory gets wasted because pointers need extra memory for
storage.
We can access elements in sequence. You cannot do this process in a random
manner.
In a linked list, reverse traversing is challenging.