Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views9 pages

Linkedlist

This document is a report on the insertion operations in Doubly Linked Lists (DLL), detailing their structure, types of insertion, algorithms, advantages, and applications. It compares DLLs with Singly Linked Lists, highlighting the benefits of bidirectional traversal and efficient memory usage. The report serves as a foundational guide for understanding and implementing insertion in DLLs, which is crucial for data structures and algorithms.
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)
4 views9 pages

Linkedlist

This document is a report on the insertion operations in Doubly Linked Lists (DLL), detailing their structure, types of insertion, algorithms, advantages, and applications. It compares DLLs with Singly Linked Lists, highlighting the benefits of bidirectional traversal and efficient memory usage. The report serves as a foundational guide for understanding and implementing insertion in DLLs, which is crucial for data structures and algorithms.
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/ 9

Insertion Into Doubly Linked List

Bachelor of Technology
Computer Science and Engineering

Submitted By

SK MASUDUR RAHAMAN
(13000124123)

September 2025

Techno Main
EM-4/1, Sector-V, Salt Lake
Kolkata- 700091
West Bengal
India
TABLE OF CONTENTS

1. Introduction
2. Details
i) Overview of Linked Lists---
--- Singly Linked List
--- Doubly Linked List
--- Comparison between Singly and Doubly Linked List

ii) Structure of a Doubly Linked List


iii) Types of Insertion in Doubly Linked List
--- Insertion at the Beginning
--- Insertion at the End
--- Insertion before a Given Position

--- Insertion after a Given Position


--- Insertion at a specific Position
--- Insertion in an Empty List
iv) Algorithms for Insertion
v) Advantages of Doubly Linked List
vi) Applications of Doubly Linked List
3. Conclusion
4. References

TMSL/CSE/CA2/2025-26/Semester-3 2
1. Introduction
Data Structures form the foundation of computer science and programming. Among all
structures, linked lists are one of the most important because they allow efficient memory
usage and dynamic management of elements.
A linked list is a collection of nodes connected together using pointers. Unlike arrays, linked
lists are not stored in continuous memory locations. Instead, each element (node) is
dynamically created and connected to the next.
The Doubly Linked List (DLL) is a special type of linked list where each node contains two
links:
• One pointing to the previous node.
• One pointing to the next node.
This property makes the DLL more powerful than a singly linked list, as it allows traversal
in both directions.
Insertion is one of the most frequently performed operations on a DLL. This report explains
the concept, structure, algorithms, and examples of inserting nodes into a doubly linked list.

2. Overview of Linked Lists


2.1 Singly Linked List
• Each node has two parts: data and a pointer to the next node.
• Traversal is only possible in one direction (forward).
• Insertion and deletion are easier compared to arrays but limited because we cannot go
backwards.
2.2 Doubly Linked List
• Each node contains three parts:
1. Data
2. Pointer to previous node (prev)
3. Pointer to next node (next)
• Allows two-way traversal (forward and backward).
• More memory is required due to the extra pointer.

TMSL/CSE/CA2/2025-26/Semester-3 3
3. Comparison between Singly and Doubly Linked List
Feature Singly Linked List Doubly Linked List
Memory Per Node Less (1 pointer) More (2 pointer)
Traversal Forward only Forward + Backward
Insertion/Deletion Slower (If need previous Faster (can directly access
node) both directions)
Applications Simple queues, stacks Navigation, text editors,
playlists

4. Structure of a Doubly Linked List


In C++ syntax, a DLL node is defined as:

Visually, a DLL looks like this:


NULL <- [Prev | Data | Next] <-> [Prev | Data | Next] <-> [Prev | Data | Next] -> NULL

5. Types of Insertion in Doubly Linked List


Insertion can occur in different positions depending on requirements.
5.1 Insertion at the Beginning
• A new node is created.
• The new node’s next pointer is linked to the current head.
• The current head’s prev pointer is updated to the new node.
• The new node becomes the new head.
Diagram:
NULL <- [newNode] <-> [oldHead] <-> ... -> NULL

TMSL/CSE/CA2/2025-26/Semester-3 4
5.2 Insertion at the End
• Traverse the list until the last node.
• Set the last node’s next pointer to the new node.
• Set the new node’s prev pointer to the last node.
• New node’s next becomes NULL.
Diagram:
NULL <- [head] <-> ... <-> [lastNode] <-> [newNode] -> NULL

5.3 Insertion before a Given Position


• This operation places the new node immediately before a specific node in the list.
• For example, inserting before position 2 means the new node becomes the new node
at index 2.
Steps:
1. Traverse to the node at the desired position.
2. Create a new node.

TMSL/CSE/CA2/2025-26/Semester-3 5
3. Link newNode->prev to the current node’s prev.
4. Link newNode->next to the current node.
5. Update the previous node’s next to newNode.
6. Update the current node’s prev to newNode.
Diagram:
... <-> [prevNode] <-> [newNode] <-> [positionNode] <-> ...

5.4 Insertion After a Given Position


• This operation places the new node immediately after a specific node in the list.
• For example, inserting after position 2 means the new node comes right after the 2nd
node.
Steps:
1. Traverse to the node at the given position.
2. Create a new node.
3. Set newNode->next = current->next.
4. Set newNode->prev = current.
5. If current->next != NULL, update (current->next)->prev = newNode.
6. Update current->next = newNode.
Diagram:
... <-> [positionNode] <-> [newNode] <-> [nextNode] <-> ...

TMSL/CSE/CA2/2025-26/Semester-3 6
5.5 Insertion at a Specific Position
• Sometimes we may want to insert a node at an exact position pos (for example, the
3rd position in the list).
• The new node is inserted in between two existing nodes.
Steps:
1. Traverse to the (pos-1)th node.
2. Create a new node.
3. Set newNode->next = current->next.
4. Set newNode->prev = current.
5. Update (current->next)->prev = newNode.
6. Update current->next = newNode.
Diagram:
... <-> [prevNode] <-> [newNode] <-> [nextNode] <-> ...

TMSL/CSE/CA2/2025-26/Semester-3 7
5.6 Insertion in an Empty List
• If the list is empty (head == NULL), simply assign the new node as the head.
• Both prev and next will be NULL.

6. Algorithms for Insertion


Insertion at Beginning

Insertion at End

Insertion at Given Position

TMSL/CSE/CA2/2025-26/Semester-3 8
7.Advantages of Doubly Linked List

1. Bidirectional Traversal – Can move forward and backward.


2. Efficient Insertion/Deletion – Especially at both ends.
3. Flexibility – Easy to reverse a list.
4. Dynamic Memory Allocation – No wastage of memory like arrays.

8. Applications of Doubly Linked List


• Undo/Redo in editors – Each operation is a node in DLL.
• Browser history navigation – Forward and backward page traversal.
• Music playlist management – Easily move to next/previous song.
• Deque and Queue implementation – Supports insertion/deletion at both ends.
• Memory management systems – Used in operating systems.

9. Conclusion
Insertion in a doubly linked list is a vital operation in Data Structures and Algorithms
(DSA).
Unlike singly linked lists, DLL provides better flexibility and efficiency for insertion
operations due to its bidirectional links.
By mastering insertion at different positions — beginning, end, and any location — students
and programmers can build more advanced structures like deques, stacks, and even
navigation systems.
The study of DLL insertion not only enhances coding knowledge but also strengthens
problem-solving abilities required in real-world applications.

10. References
1. Horowitz, Ellis, Sartaj Sahni, and Dinesh Mehta. Fundamentals of Data Structures in
C.
2. Weiss, Mark Allen. Data Structures and Algorithm Analysis in C. Pearson Education.
3. GeeksforGeeks – https://www.geeksforgeeks.org/doubly-linked-list
4. TutorialsPoint –
https://www.tutorialspoint.com/data_structures_algorithms/doubly_linked_list.htm

TMSL/CSE/CA2/2025-26/Semester-3 9

You might also like