0% found this document useful (0 votes)
5 views

Linked Lists

A linked list is a linear data structure that allows efficient insertion and deletion operations compared to arrays, using nodes that store data and pointers to the next node. There are various types of linked lists, including singly, doubly, circular, and header linked lists, each with specific applications and advantages. While linked lists offer benefits such as dynamic memory allocation and ease of manipulation, they also have disadvantages like slower access times and higher memory overhead.

Uploaded by

Ishavdeep Kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Linked Lists

A linked list is a linear data structure that allows efficient insertion and deletion operations compared to arrays, using nodes that store data and pointers to the next node. There are various types of linked lists, including singly, doubly, circular, and header linked lists, each with specific applications and advantages. While linked lists offer benefits such as dynamic memory allocation and ease of manipulation, they also have disadvantages like slower access times and higher memory overhead.

Uploaded by

Ishavdeep Kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Linked Lists Theory Notes

A linked list is a fundamental data structure in computer science. It mainly


allows efficient insertion and deletion operations compared to arrays. Like
arrays, it is also used to implement other data structures like stack, queue and
deque.

Linked List is a linear data structure, in which elements are not stored at a
contiguous location, rather they are linked using pointers. Linked List forms a
series of connected nodes, where each node stores the data and the address of
the next node.

Node Structure: A node in a linked list typically consists of two components:


1. Data: It holds the actual value or data associated with the node.
2. Next Pointer or Reference : It stores the memory address
(reference) of the next node in the sequence.
Head and Tail: The linked list is accessed through the head node, which points
to the first node in the list. The last node in the list points to NULL or nullptr,
indicating the end of the list. This node is known as the tail node.
Why linked list data structure needed?
The main cases where we prefer linked list over arrays is due to ease of insertion
and deletion in linked list.
Operations on Linked Lists
1. Insertion: Adding a new node to a linked list involves adjusting the
pointers of the existing nodes to maintain the proper sequence.
Insertion can be performed at the beginning, end, or any position
within the list
2. Deletion: Removing a node from a linked list requires adjusting the
pointers of the neighboring nodes to bridge the gap left by the deleted
node. Deletion can be performed at the beginning, end, or any position
within the list.
3. Searching: Searching for a specific value in a linked list involves
traversing the list from the head node until the value is found or the
end of the list is reached.

Basic Terminologies of Linked List


• Head: The Head of a linked list is a pointer to the first node or
reference of the first node of linked list. This pointer marks the
beginning of the linked list.
• Node: Linked List consists of a series of nodes where each node has
two parts: data and next pointer.
• Data: Data is the part of node which stores the information in the
linked list.
• Next pointer: Next pointer is the part of the node which points to the
next node of the linked list.
Applications, Advantages and Disadvantages of Linked List

A Linked List is a linear data structure that is used to store a collection of data
with the help of nodes. Please remember the following points before moving
forward.
• The consecutive elements are connected by pointers / references.
• The last node of the linked list points to null.
• The entry point of a linked list is known as the head.
• The common variations of linked lists are Singly, Doubly, Singly
Circular and Doubly Circular.
Advantages of Linked Lists (or Most Common Use Cases):
• Linked Lists are mostly used because of their effective insertion and
deletion. We only need to change few pointers (or references) to insert
(or delete) an item in the middle
• Insertion and deletion at any point in a linked list take O(1) time.
Whereas in an array data structure, insertion / deletion in the middle
takes O(n) time.
• This data structure is simple and can be also used to implement a
stack, queues, and other abstract data structures.
• Implementation of Queue and Deque data structures : Simple array
implementation is not efficient at all. We must use circular array to
efficiently implement which is complex. But with linked list, it is easy
and straightforward. That is why most of the language libraries use
Linked List internally to implement these data structures..
• Linked List might turn out to be more space efficient compare to
arrays in cases where we cannot guess the number of elements in
advance. In case of arrays, the whole memory for items is allocated
together. Even with dynamic sized arrays like vector in C++ or list in
Python or ArrayList in Java. the internal working involves de-allocation
of whole memory and allocation of a bigger chunk when insertions
happen beyond the current capacity.
Applications of Linked Lists:
• Linked Lists can be used to implement stacks, queue, deque, sparse
matrices and adjacency list representation of graphs.
• Dynamic memory allocation in operating systems and compilers
(linked list of free blocks).
• Manipulation of polynomials
• Arithmetic operations on long integers.
• In operating systems, they can be used in Memory management,
process scheduling (for example circular linked list for round robin
scheduling) and file system.
• Algorithms that need to frequently insert or delete items from large
collections of data.
• LRU cache, which uses a doubly linked list to keep track of the most
recently used items in a cache.
Applications of Linked Lists in real world:
• The list of songs in the music player are linked to the previous and
next songs.
• In a web browser, previous and next web page URLs can be linked
through the previous and next buttons (Doubly Linked List)
• In image viewer, the previous and next images can be linked with the
help of the previous and next buttons (Doubly Linked List)
• Circular Linked Lists can be used to implement things in round
manner where we go to every element one by one.
• Linked List are preferred over arrays for implementations of Queue
and Deque data structures because of fast deletions (or insertions) from
the front of the linked lists.
Disadvantages of Linked Lists:
Linked lists are a popular data structure in computer science, but like any other
data structure, they have certain disadvantages as well. Some of the key
disadvantages of linked lists are:
• Slow Access Time: Accessing elements in a linked list can be slow, as
you need to traverse the linked list to find the element you are looking
for, which is an O(n) operation. This makes linked lists a poor choice
for situations where you need to access elements quickly.
• Pointers or References: Linked lists use pointers or references to
access the next node, which can make them more complex to
understand and use compared to arrays. This complexity can make
linked lists more difficult to debug and maintain.
• Higher overhead: Linked lists have a higher overhead compared to
arrays, as each node in a linked list requires extra memory to store the
reference to the next node.
• Cache Inefficiency: Linked lists are cache-inefficient because the
memory is not contiguous. This means that when you traverse a linked
list, you are not likely to get the data you need in the cache, leading to
cache misses and slow performance.
Linked List vs Array

Array: Arrays store elements in contiguous memory locations, resulting in easily


calculable addresses for the elements stored and this allows faster access to an
element at a specific index.

Data storage scheme of an array

Linked List: Linked lists are less rigid in their storage structure and elements are
usually not stored in contiguous locations, hence they need to be stored with
additional tags giving a reference to the next element.
Types Of Linked Lists:

1. Singly Linked List


Singly linked list is the simplest type of linked list in which every node contains
some data and a pointer to the next node of the same data type.

The node contains a pointer to the next node means that the node stores the
address of the next node in the sequence. A single linked list allows the traversal
of data only in one way

2. Doubly Linked List


A doubly linked list or a two-way linked list is a more complex type of linked list
that contains a pointer to the next as well as the previous node in sequence.

Therefore, it contains three parts of data, a pointer to the next node, and a
pointer to the previous node. This would enable us to traverse the list in the
backward direction as well.
3. Circular Linked List
A circular linked list is a type of linked list in which the last node’s next pointer
points back to the first node of the list, creating a circular structure. This design
allows for continuous traversal of the list, as there is no null to end the list.

While traversing a circular linked list, we can begin at any node and traverse the
list in any direction forward and backward until we reach the same node we
started. Thus, a circular linked list has no beginning and no end. Below is the
image for the same:

4. Doubly Circular linked list


Doubly Circular linked list or a circular two-way linked list is a complex type
of linked list that contains a pointer to the next as well as the previous node in
the sequence. The difference between the doubly linked and circular doubly
list is the same as that between a singly linked list and a circular linked list.
The circular doubly linked list does not contain null in the previous field of the
first node.
Header Linked List

A header linked list is a special type of linked list which consists of a header node
in the beginning of the list. The header node can store meta data about the
linked list. This type of list is useful when information other than that found in
each node is needed. For example, suppose there is an application in which
the number of items in a list is often calculated. Usually, a list is always
traversed to find the length of the list. However, information can be easily
obtained if the current length is maintained in an additional header node.

Types of Header Linked List

1. Singly or Doubly Header Linked List

It is a list whose last node contains the NULL pointer. In the header linked list
the start pointer always points to the header node. start -> next =
NULL indicates that the header linked list is empty. The operations that are
possible on this type of linked list are Insertion, Deletion, and Traversing. This
structure can be implemented using a singly linked list or a doubly linked
list.When using a doubly linked list, the header node
simplifies bidirectional traversal and manipulation of the list, further
enhancing the efficiency of operations like insertion and deletion.
2. Singly or Doubly Circular Header Linked List

A list in which the last node points back to the header node is called circular
header linked list. The chains do not indicate first or last nodes. In this case,
external pointers provide a frame of reference because last node of a circular
linked list does not contain the NULL pointer. The possible operations on this
type of linked list are Insertion, Deletion and Traversing.

You might also like