DS-NOTES-JNTUGV-R23-UNIT-2
DS-NOTES-JNTUGV-R23-UNIT-2
DS-NOTES-JNTUGV-R23-UNIT-2
DATA STRUCTURES
UNIT-II
Syllabus: Linked Lists: Singly linked lists, representation and operations, doubly linked
lists and circular linked lists, Comparing arrays and linked lists, Applications of linked
lists.
Operations on Singly Linked List: There are various operations which can be performed
on singly linked list. A list of all such operations is given below.
Node Creation
1. struct node
2. {
3. int data;
4. struct node *next;
5. };
6. struct node *head, *ptr;
7. ptr = (struct node *)malloc(sizeof(struct node *));
Insertion: The insertion into a singly linked list can be performed at different positions. Based on the
position of the new node being inserted, the insertion is categorized into the following categories.
SN Operation Description
1 Insertion at It involves inserting any element at the front of the list. We just need to a few
beginning link adjustments to make the new node as the head of the list.
2 Insertion at end It involves insertion at the last of the linked list. The new node can be inserted
of the list as the only node in the list or it can be inserted as the last one. Different logics
are implemented in each scenario.
3 Insertion after It involves insertion after the specified node of the linked list. We need to skip
specified node the desired number of nodes in order to reach the node after which the new
node will be inserted. .
SN Operation Description
1 Deletion at It involves deletion of a node from the beginning of the list. This is the simplest
beginning operation among all. It just need a few adjustments in the node pointers.
2 Deletion at the It involves deleting the last node of the list. The list can either be empty or full.
end of the list Different logic is implemented for the different scenarios.
3 Deletion after It involves deleting the node after the specified node in the list. we need to skip
specified node the desired number of nodes to reach the node after which the node will be
deleted. This requires traversing through the list.
4 Traversing In traversing, we simply visit each node of the list at least once in order to
perform some specific operation on it, for example, printing data part of each
node present in the list.
5 Searching In searching, we match each element of the list with the given element. If the
element is found on any of the location then location of that element is
returned otherwise null is returned. .
Complexity
Data Time Complexity Space
Structure Complexity
Singly θ(n) θ(n) θ(1) θ(1) O(n) O(n) O(1) O(1) O(n)
Linked
List