LINKED LIST.pptx
LINKED LIST.pptx
LINKED LIST.pptx
UNIT 2
► Linked list is a linear data structure that includes a series of connected
nodes. Linked list can be defined as the nodes that are randomly stored in
the memory. A node in the linked list contains two parts, i.e., first is the
data part and second is the address part. The last node of the list contains
a pointer to the null. After array, linked list is the second most used data
structure. In a linked list, every link contains a connection to another link.
► Representation of a Linked list
► Linked list can be represented as the connection of nodes in which each
node points to the next node of the list. The representation of the linked
list is shown below -
►
► Till now, we have been using array data structure to organize the group of
elements that are to be stored individually in the memory. However, Array
has several advantages and disadvantages that must be known to decide
the data structure that will be used throughout the program.
► Now, the question arises why we should use linked list over array?
Why use linked list over array?
• The size of the array must be known in advance before using it in the
program.
• Increasing the size of the array is a time taking process. It is almost
impossible to expand the size of the array at run time.
• All the elements in the array need to be contiguously stored in the
memory. Inserting an element in the array needs shifting of all its
predecessors.
► Linked list is useful because -
• It allocates the memory dynamically. All the nodes of the linked list are
non-contiguously stored in the memory and linked together with the help
of pointers.
• In linked list, size is no longer a problem since we do not need to define its
size at the time of declaration. List grows as per the program's demand
and limited to the available memory space.
Types of Linked list
► Linked list is classified into the following types -
• Singly-linked list - Singly linked list can be defined as the collection of an
ordered set of elements. A node in the singly linked list consists of two
parts: data part and link part. Data part of the node stores actual
information that is to be represented by the node, while the link part of the
node stores the address of its immediate successor.
• Doubly linked list - Doubly linked list is a complex type of linked list in
which a node contains a pointer to the previous as well as the next node in
the sequence. Therefore, in a doubly-linked list, a node consists of three
parts: node data, pointer to the next node in sequence (next pointer), and
pointer to the previous node (previous pointer).
• Circular singly linked list - In a circular singly linked list, the last node of
the list contains a pointer to the first node of the list. We can have circular
singly linked list as well as circular doubly linked list.
• Circular doubly linked list - Circular doubly linked list is a more complex
type of data structure in which a node contains pointers to its previous
node as well as the next node. Circular doubly linked list doesn't contain
NULL in any of the nodes. The last node of the list contains the address of
the first node of the list. The first node of the list also contains the address
Advantages of Linked list
► The advantages of using the Linked list are given as follows -
• Dynamic data structure - The size of the linked list may vary according to
the requirements. Linked list does not have a fixed size.
• Insertion and deletion - Unlike arrays, insertion, and deletion in linked list
is easier. Array elements are stored in the consecutive location, whereas
the elements in the linked list are stored at a random location. To insert or
delete an element in an array, we have to shift the elements for creating
the space. Whereas, in linked list, instead of shifting, we just have to
update the address of the pointer of the node.
• Memory efficient - The size of a linked list can grow or shrink according
to the requirements, so memory consumption in linked list is efficient.
• Implementation - We can implement both stacks and queues using linked
list.
Disadvantages of Linked list