SlideShare a Scribd company logo
Prepared By:
Dr. Chandan Kumar
Assistant Professor, Computer Science & Engineering Department
Invertis University, Bareilly
Introduction
 A linked list is a linear data structure which is used to store
a collection of elements.
 Each element in a linked list is represented by node.
 It is a best example of dynamic data structure that uses
pointer for the implementation
 Each node contain two parts
 Data part or info part - which is used to store the element
 Link part or address part- which is used to stores the link to
the next node.
Node
Data Link
Introduction
 Linked list require more memory compare to array for
the same size of the elements because along with data
or value it also store pointer to next node.
 It is the most common and simplest data structure.
They can be used to implement other data structure
like stack and queue etc.
 Finally, we can say that a linked list is a set of
dynamically allocated nodes, organized in
such a way that each node has a value and a pointer.
Introduction
 Arrays and Linked Lists are both linear data structures
so they do have some advantages and drawbacks over
each other.
 Now let us look at the difference between arrays and
linked list.
Arrays Vs Linked List
Arrays Linked Lists
 Collection of elements of
similar data type
 Support random access using
indexing
 Best suitable for fixed size
elements implementation
 Insertion and deletion of
elements are inefficient i.e.
elements are usually shifted
 An ordered collection of
elements of the same type
where each element is
linked using pointers to the
next one.
 Doesn’t support random
access
 Support Dynamic size
 Insertion and deletion of
elements are efficient i.e. no
shifting
Arrays Vs Linked List
Arrays Linked Lists
 Memory is allocated
statically or compile time
 Wastage of memory if the
allocated memory is not fully
utilized
 Data elements are stored in
computer memory in
contiguous location; so access
is faster
 Size must be specified at the
time of array declaration
 Memory is allocated
dynamically or run time
 There is no wastage of memory
 New elements can be stored
anywhere, and use pointers
to create a reference for the
new element; so access is slow
 Size of a Linked list
grows/shrinks as and when new
elements are inserted/deleted.
Types of Linked List
 There are two types of linked list
 Single or Singly linked list (SLL)
 Single Circular Linked List
 Double or Doubly linked list (DLL)
 Double Circular Linked List
Singly Linked List (SLL)
 This is a fundamental type of linked list
 Each node has two part
 Data or info part- contain actual value or information
 Next or link part – contain pointer or address of the next node
 Last node contain NULL value in link part which indicated
end of the node
 Traversing is allowed only in forward direction
 It uses less memory as compare to doubly linked list per
node ( Single pointer)
Singly Linked List (SLL)
 Complexity of insertion and deletion at a known
position is O(n)
 We prefer SLL If we need to save memory and
searching is not required
 Singly linked list can mostly be used for stacks
Singly Linked List (SLL)
 For Example
The above figure shows a singly linked list. The first node
is always used as a reference to traverse the list and is
called HEAD. The last node points to NULL.
Singly Linked List (SLL)
 A Singly linked list can be implemented in C
programming langauge using the structure and
the pointer.
struct LinkedList
{
int data;
struct LinkedList *next;
};
This definition is used to build
every node in the list.
The data field stores the element,
and the next field is a pointer to
store the next node's address.
Implementation of SLL in C language
#include<conio.h>
#include<stdio.h>
void main()
{
struct node
{
int value;
struct node *next;
}*a,*b,*c;
clrscr();
a->value=5;
b->value=6;
c->value=7;
Implementation of SLL in C language
a->next=b;
b->next=c;
c->next=NULL;
printf("nNode an value=%d and Next =%u",a->value,a->next);
printf("nNode bn value=%d and next =%u",a->next->value,a-
>next->next);
printf("nNode cn value=%d and next=%u",a->next->next-
>value,a->next->next->next);
getch();
}
Output
Single Circular Linked List
 Each node has two parts like SLL
 No beginning and No end
 Does not contain NULL pointer like SLL
 Last node is connected to first node i.e. link part of last
node contain address of first node
 Traversing allowed only in forward direction
 Time saving when we want to go from last node to first
node
 A good example where it is used is a timesharing
problem solved by operating system
Single Circular Linked List
 For example
Doubly Linked List (DLL)
 Each node has three parts, one data part and two link
part
 Data part contain actual value
 One link part contain next pointer to point next node
 Another link part contain previous pointer to point
previous node
Doubly Linked List (DLL)
// C language to represent a node for DLL
struct node
{
int info;
struct node *next;
struct node *prev;
};
Doubly Linked List (DLL)
 Traversing is possible in both directions i.e. forward and
backward directions
 Required more memory as compare to SLL for the same
size ( two pointers required)
 Previous link part value of first node and next link part
value of last node has value NULL
 Complexity of insertion and deletion at a known position is
O(1)
 We prefer DLL If we need better performance while
searching and memory is not a limitation
 Can be used to implement stacks, heaps, binary trees
Doubly Linked List (DLL)
For Example:
Doubly Circular Linked List
 Each node has three parts like DLL
 No beginning and No end
 Does not contain NULL pointer like DLL
 First node is connected to the last node and Last node is
connected to first node i.e. previous pointer of the first
node contain address of last node and next pointer of last
node contain address of first node
 Traversing allowed in both directions i.e. forward and
backward directions
 Time saving when we want to go from last node to first
node and vice versa
Doubly Circular Linked List
 For example
Operation performed on Linked List
The operations which can be performed on a linked list
follow:
1. Creation
2. Insertion
3. Deletion
4. Traversing
5. Searching
6. Concatenation
7. Display
Creation
 This operation is used to create a linked list
 Memory allocated for nodes
Creating first node
head = (node*) malloc (sizeof(node));
head -> data = 50;
head -> next = NULL;
Insertion
 Used to insert a new node in the linked list
 Insertion take place at different places such as
 At beginning of the linked list
 At the end of the linked list
 At specified position i.e. between any two nodes
 Inserting a node is a more than one step activity
 Created node must be in same structure
Insertion
 At beginning of the linked list
 Here we want to add Node X
Before inserting Node X
Insertion
After inserting Node X
New Node becomes new head of the linked list and next pointer
points to the Node A
Insertion
 At the end of the linked list
 Here we want to add Node X
Before inserting Node X
Insertion
After inserting Node X
next pointer of Node D pointes to new Node X and the
value of next pointer of Node D becomes NULL
Insertion
 At specified position i.e. between any two nodes
 Here we want to add Node X between Node B and Node C
Before inserting Node X
Insertion
After inserting Node X
Here, next pointer of Node B pointes to new Node X and next
pointer of Node X pointes to Node C
Deletion
 Used to delete a node from the list
 Deletion take place at different places such as similarly
insertion operation
 From beginning of the linked list
 From the end of the linked list
 From specified position i.e. between any two nodes
 Deleting a node is a more than one step activity
Deletion
 Here we want to delete third node i.e. Node C from the
linked list
 Next pointer of node B points to Node D
 Similarly other deletion process will be done
Traversing
 It is a process of examine all nodes of linked list i.e.
one end to the other end
 Recursive function is used to traverse a linked list in a
reverse order
 Going through first node to last node is called forward
traversing
 Going through last node to first node is called
backward traversing
Searching
 Process to find a desired element in the linked list
 Sequential or linear search is the most common search
used in linked list
 Traverse all nodes one by one and matches with key
value
 There are two outcomes
 Search is successful, if desired element is found in the
linked list
 Search is unsuccessful, is desired element is not found in
the linked list
Concatenation
 Process of appending second list to the end of the first
list
 After concatenation, the linked list size will increases
 This is simply done by pointing next pointer of last
node of first linked list to first node of the second
linked list
Display
 Used to print information of each nodes in a linked list
 Also display complete linked list
Linked List

More Related Content

What's hot

linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
KristinaBorooah
 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
Md. Israil Fakir
 
Array data structure
Array data structureArray data structure
Array data structure
maamir farooq
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structureghhgj jhgh
 
Linked list
Linked listLinked list
Linked list
akshat360
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
Zidny Nafan
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
03446940736
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Linked list
Linked listLinked list
Linked list
Md. Afif Al Mamun
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sort
May Ann Mendoza
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
Kamran Zafar
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
Kathirvel Ayyaswamy
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
Sangani Ankur
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 
Data structures using c
Data structures using cData structures using c
Data structures using c
Prof. Dr. K. Adisesha
 

What's hot (20)

linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Linked list
Linked listLinked list
Linked list
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Array data structure
Array data structureArray data structure
Array data structure
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Linked list
Linked listLinked list
Linked list
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Linked List
Linked ListLinked List
Linked List
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Linked list
Linked listLinked list
Linked list
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sort
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 

Similar to Linked List

1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna
 
Link list
Link listLink list
Link list
zzzubair
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
ASADAHMAD811380
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
EmilyMengich
 
Linked List Basics
Linked List BasicsLinked List Basics
Linked List Basics
KaustavRoy40
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
Linked List
Linked ListLinked List
Linked List
BHARATH KUMAR
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
Estiak Khan
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
DarbhalaPavanKumar
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
ThenmozhiK5
 
Data structure and algorithms chapter three LINKED LIST
Data structure and algorithms chapter three LINKED LISTData structure and algorithms chapter three LINKED LIST
Data structure and algorithms chapter three LINKED LIST
binakasehun2026
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
Akila Krishnamoorthy
 
Data structure
 Data structure Data structure
Data structure
Shahariar limon
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data Structure
Meghaj Mallick
 
Static arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfStatic arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdf
anjanacottonmills
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxSIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
edgar6wallace88877
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 

Similar to Linked List (20)

1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
 
Link list
Link listLink list
Link list
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Linked List Basics
Linked List BasicsLinked List Basics
Linked List Basics
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Linked List
Linked ListLinked List
Linked List
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
 
Data structure and algorithms chapter three LINKED LIST
Data structure and algorithms chapter three LINKED LISTData structure and algorithms chapter three LINKED LIST
Data structure and algorithms chapter three LINKED LIST
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Data structure
 Data structure Data structure
Data structure
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data Structure
 
Static arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfStatic arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdf
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxSIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 

More from CHANDAN KUMAR

Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
CHANDAN KUMAR
 
Raid technology
Raid technologyRaid technology
Raid technology
CHANDAN KUMAR
 
Pointers in c
Pointers in cPointers in c
Pointers in c
CHANDAN KUMAR
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
CHANDAN KUMAR
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
CHANDAN KUMAR
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
CHANDAN KUMAR
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
CHANDAN KUMAR
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
CHANDAN KUMAR
 
Stack and queue
Stack and queueStack and queue
Stack and queue
CHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
CHANDAN KUMAR
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
CHANDAN KUMAR
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
CHANDAN KUMAR
 

More from CHANDAN KUMAR (13)

Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
 
Raid technology
Raid technologyRaid technology
Raid technology
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
 

Recently uploaded

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 

Recently uploaded (20)

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 

Linked List

  • 1. Prepared By: Dr. Chandan Kumar Assistant Professor, Computer Science & Engineering Department Invertis University, Bareilly
  • 2. Introduction  A linked list is a linear data structure which is used to store a collection of elements.  Each element in a linked list is represented by node.  It is a best example of dynamic data structure that uses pointer for the implementation  Each node contain two parts  Data part or info part - which is used to store the element  Link part or address part- which is used to stores the link to the next node. Node Data Link
  • 3. Introduction  Linked list require more memory compare to array for the same size of the elements because along with data or value it also store pointer to next node.  It is the most common and simplest data structure. They can be used to implement other data structure like stack and queue etc.  Finally, we can say that a linked list is a set of dynamically allocated nodes, organized in such a way that each node has a value and a pointer.
  • 4. Introduction  Arrays and Linked Lists are both linear data structures so they do have some advantages and drawbacks over each other.  Now let us look at the difference between arrays and linked list.
  • 5. Arrays Vs Linked List Arrays Linked Lists  Collection of elements of similar data type  Support random access using indexing  Best suitable for fixed size elements implementation  Insertion and deletion of elements are inefficient i.e. elements are usually shifted  An ordered collection of elements of the same type where each element is linked using pointers to the next one.  Doesn’t support random access  Support Dynamic size  Insertion and deletion of elements are efficient i.e. no shifting
  • 6. Arrays Vs Linked List Arrays Linked Lists  Memory is allocated statically or compile time  Wastage of memory if the allocated memory is not fully utilized  Data elements are stored in computer memory in contiguous location; so access is faster  Size must be specified at the time of array declaration  Memory is allocated dynamically or run time  There is no wastage of memory  New elements can be stored anywhere, and use pointers to create a reference for the new element; so access is slow  Size of a Linked list grows/shrinks as and when new elements are inserted/deleted.
  • 7. Types of Linked List  There are two types of linked list  Single or Singly linked list (SLL)  Single Circular Linked List  Double or Doubly linked list (DLL)  Double Circular Linked List
  • 8. Singly Linked List (SLL)  This is a fundamental type of linked list  Each node has two part  Data or info part- contain actual value or information  Next or link part – contain pointer or address of the next node  Last node contain NULL value in link part which indicated end of the node  Traversing is allowed only in forward direction  It uses less memory as compare to doubly linked list per node ( Single pointer)
  • 9. Singly Linked List (SLL)  Complexity of insertion and deletion at a known position is O(n)  We prefer SLL If we need to save memory and searching is not required  Singly linked list can mostly be used for stacks
  • 10. Singly Linked List (SLL)  For Example The above figure shows a singly linked list. The first node is always used as a reference to traverse the list and is called HEAD. The last node points to NULL.
  • 11.
  • 12. Singly Linked List (SLL)  A Singly linked list can be implemented in C programming langauge using the structure and the pointer. struct LinkedList { int data; struct LinkedList *next; }; This definition is used to build every node in the list. The data field stores the element, and the next field is a pointer to store the next node's address.
  • 13. Implementation of SLL in C language #include<conio.h> #include<stdio.h> void main() { struct node { int value; struct node *next; }*a,*b,*c; clrscr(); a->value=5; b->value=6; c->value=7;
  • 14. Implementation of SLL in C language a->next=b; b->next=c; c->next=NULL; printf("nNode an value=%d and Next =%u",a->value,a->next); printf("nNode bn value=%d and next =%u",a->next->value,a- >next->next); printf("nNode cn value=%d and next=%u",a->next->next- >value,a->next->next->next); getch(); }
  • 16. Single Circular Linked List  Each node has two parts like SLL  No beginning and No end  Does not contain NULL pointer like SLL  Last node is connected to first node i.e. link part of last node contain address of first node  Traversing allowed only in forward direction  Time saving when we want to go from last node to first node  A good example where it is used is a timesharing problem solved by operating system
  • 17. Single Circular Linked List  For example
  • 18. Doubly Linked List (DLL)  Each node has three parts, one data part and two link part  Data part contain actual value  One link part contain next pointer to point next node  Another link part contain previous pointer to point previous node
  • 19. Doubly Linked List (DLL) // C language to represent a node for DLL struct node { int info; struct node *next; struct node *prev; };
  • 20. Doubly Linked List (DLL)  Traversing is possible in both directions i.e. forward and backward directions  Required more memory as compare to SLL for the same size ( two pointers required)  Previous link part value of first node and next link part value of last node has value NULL  Complexity of insertion and deletion at a known position is O(1)  We prefer DLL If we need better performance while searching and memory is not a limitation  Can be used to implement stacks, heaps, binary trees
  • 21. Doubly Linked List (DLL) For Example:
  • 22. Doubly Circular Linked List  Each node has three parts like DLL  No beginning and No end  Does not contain NULL pointer like DLL  First node is connected to the last node and Last node is connected to first node i.e. previous pointer of the first node contain address of last node and next pointer of last node contain address of first node  Traversing allowed in both directions i.e. forward and backward directions  Time saving when we want to go from last node to first node and vice versa
  • 23. Doubly Circular Linked List  For example
  • 24. Operation performed on Linked List The operations which can be performed on a linked list follow: 1. Creation 2. Insertion 3. Deletion 4. Traversing 5. Searching 6. Concatenation 7. Display
  • 25. Creation  This operation is used to create a linked list  Memory allocated for nodes Creating first node head = (node*) malloc (sizeof(node)); head -> data = 50; head -> next = NULL;
  • 26. Insertion  Used to insert a new node in the linked list  Insertion take place at different places such as  At beginning of the linked list  At the end of the linked list  At specified position i.e. between any two nodes  Inserting a node is a more than one step activity  Created node must be in same structure
  • 27. Insertion  At beginning of the linked list  Here we want to add Node X Before inserting Node X
  • 28. Insertion After inserting Node X New Node becomes new head of the linked list and next pointer points to the Node A
  • 29. Insertion  At the end of the linked list  Here we want to add Node X Before inserting Node X
  • 30. Insertion After inserting Node X next pointer of Node D pointes to new Node X and the value of next pointer of Node D becomes NULL
  • 31. Insertion  At specified position i.e. between any two nodes  Here we want to add Node X between Node B and Node C Before inserting Node X
  • 32. Insertion After inserting Node X Here, next pointer of Node B pointes to new Node X and next pointer of Node X pointes to Node C
  • 33. Deletion  Used to delete a node from the list  Deletion take place at different places such as similarly insertion operation  From beginning of the linked list  From the end of the linked list  From specified position i.e. between any two nodes  Deleting a node is a more than one step activity
  • 34. Deletion  Here we want to delete third node i.e. Node C from the linked list  Next pointer of node B points to Node D  Similarly other deletion process will be done
  • 35. Traversing  It is a process of examine all nodes of linked list i.e. one end to the other end  Recursive function is used to traverse a linked list in a reverse order  Going through first node to last node is called forward traversing  Going through last node to first node is called backward traversing
  • 36. Searching  Process to find a desired element in the linked list  Sequential or linear search is the most common search used in linked list  Traverse all nodes one by one and matches with key value  There are two outcomes  Search is successful, if desired element is found in the linked list  Search is unsuccessful, is desired element is not found in the linked list
  • 37. Concatenation  Process of appending second list to the end of the first list  After concatenation, the linked list size will increases  This is simply done by pointing next pointer of last node of first linked list to first node of the second linked list
  • 38. Display  Used to print information of each nodes in a linked list  Also display complete linked list