Data Structures and Algorithms-DSA_Linkedlist_class 2.pdf
1. Dr. CHETHAN CHANDRA S BASAVARADDI
B.E., B.Ed., M.Tech., Ph.D., D.Litt., KEA-KSET.,
Associate Professor,
Dept. CSE, School of CS&T,
Faculty of Engineering Technology,
G M University,
Post Box No-4, PB Road,
Davanagere-577006,
2. Essential Operation on Linked Lists
Traversing: To traverse all nodes one by one.
Insertion: To insert new nodes at specific
positions.
Deletion: To delete nodes from specific positions.
Searching: To search for an element from the
linked list.
3. Traversal
In this operation, you will display all the nodes in the linked list.
When the temp is null, it means you traversed all the nodes, and you
reach the end of the linked list and get out from the while loop.
4. Insertion
You can add a node at the beginning, middle,
and end.
Insert at the Beginning
Create a memory for a new node.
Store data in a new node.
Change next to the new node to point to start.
Change starts to tell the recently created node.
6. Insert at the End
Insert a new node and store data in it.
Traverse the last node of a linked list
Change the next pointer of the last node to the
newly created node.
8. Insert at the Middle
Allocate memory and store data in the new
node.
Traverse the node, which is just before the new
node.
Change the next pointer to add a new node in
between.
10. Deletion
You can also do deletion in the linked list in three
ways either from the end, beginning, or from a
specific position.
Delete from the Beginning
The point starts at the second node.
start = start -> next;
11. Delete from the End
Traverse the second last element in the linked list.
Change its next pointer to null.
12. Delete from the Middle
Traverse the element before the element to be deleted.
Change the next pointer to exclude the node from the linked list.
For(int i=2; i<position; i++)
13. Searching
The search operation is done to find a particular
element in the linked list. If the element is found
in any location, then it returns. Else, it will return
null.
14. Application of a Linked List
A linked list is used to implement stacks and queues.
A linked list also helps to implement an adjacency matrix
graph.
It is used for the dynamic memory location.
The linked list makes it easy to deal with the addition and
multiplication of polynomial operations.
Implementing a hash table, each bucket of the hash
table itself behaves as a linked list.
It is used in a functionality known as undo in Photoshop
and Word.
15. Types of Linked List in Data Structures
A linked list is like a train where each bogie is
connected with links. Different types of linked lists
exist to make lives easier, like an image viewer,
music player, or when you navigate through
web pages.
17. There are four key types of linked lists:
Singly linked lists
Doubly linked lists
Circular linked lists
Circular doubly linked lists