Algorithms #5)
CS Dojo
Introduction to Linked List
In this article, we will discuss the basics of linked list data structure.
What is a linked list?
A linked list is a data structure consisting of a group of nodes which together
represent a sequence. Each node contains two fields: data, and a reference (link)
to the next node in the sequence. The first node is called the head, and the last
node is called the tail.
Types of linked list
Singly linked list: Each node has only one reference, to the next node in the list.
Doubly linked list: Each node has two references, to the next node and the
previous node in the list.
Circular linked list: The last node in the list has a reference to the first node in
the list.
Advantages of linked list
Dynamic size: Linked list can increase or decrease in size during execution of
the program.
Efficient memory allocation: Linked list uses memory efficiently as it can
allocate memory whenever required.
Flexibility: Linked list can be easily manipulated by adding or removing nodes.
Disadvantages of linked list
Traversal: It is difficult to traverse a linked list as it does not allow random
access.
Memory usage: Linked list uses more memory than arrays as each node
requires an additional reference.
Complexity: Implementing a linked list requires additional coding compared to
arrays.