SlideShare a Scribd company logo
Linked List
-Afif
What is Linked List
A linked list is a linear collection of data elements, called nodes, each
pointing to the next node by means of a pointer. It is a data
structure consisting of a group of nodes which together represent
a sequence. Linked lists were developed in 1955–1956 by Allen
Newell, Cliff Shaw and Herbert A. Simon.
It contains data field & Address field or Link field.
A graphical view of a linked list
Why do we use Linked List?
Linked lists are preferable over arrays when:
a) we need constant-time insertions/deletions from the list (such as in
real-time computing where time predictability is absolutely critical )
b) We don't know how many items will be in the list. With arrays, you
may need to re-declare and copy memory if the array grows too big
c) We don't need random access to any elements
d) We want to be able to insert items in the middle of the list (such as
a priority queue)
Types of Linked List
There are three types of linked list as given below:
1. Singly Linked List
2. Doubly Linked List
3. Circular Linked List
Singly Linked List
A graphical view of a singly linked list
Doubly Linked List
In doubly linked list each node is divided into three parts:
1. The first part is PREV part.
2. The second part is the INFO part.
3. The third part is NEXT part.
A graphical view of a doubly linked list
Circular Linked List
A graphical view of a circular linked list
Singly Linked List Operations
There are several operations in singly linked list:
1.Creation
2. Insertion
3. Deletion
4. Searching
5. Display
Nodes
• Nodes are the units which makes up linked list.
• In singly linked list, nodes are actually structures made up of data and a
pointer to another node.
• Usually we denote the pointer as “*next”
*Nodes structure
struct node
{
int data; //This is where we will store data
struct node *next; //This is the link part
}*head=NULL;
/*Initially we assign “NULL” to the head for later operational purpose*/
*Visual Representation of Node
data next
Node
Creation
• Creation operation is used to create a linked list.
• Generally, we use dynamic memory allocation to create our desired
number of nodes for linked list in program run time.
void create()
{
struct node *newnode, *current;
newnode = (struct node*)malloc(sizeof(struct node));
newnode->next = NULL;
if(head == NULL)
{
head = newnode;
current = newnode;
}
else
{
current->next = newnode;
current = newnode;
}
}
//Creating linked list in ‘C’
*Visual Representation of Linked List
data next
Head
data next data next
NULL
Insertion
• Insertion operation is used to insert a new node in the linked list.
• Insertion is of three types. They are:
 Inserting at first
 Inserting at last
 Inserting at mid
Insertion at first
• There are two steps to be followed to insert a node at first position.
They are:
 Make the next pointer of the node point towards
the first node of the list.
 Make the head pointer point towards this new node.
*Visual Representation of Insertion at First
data next
Head
data next data next
NULL
Newnode
nextdata
void first_insert()
{
struct node *newnode, *current;
newnode = (struct node*)malloc(sizeof(struct node));
newnode->next = NULL;
if(head == NULL)
{
head = newnode;
current = newnode;
}
else
{
newnode->next = head;
head = newnode;
}
}
//Inserting at first
Insertion at last
• Inserting at the last position is a simple process.
 To insert at last we just simply need to make the next pointer of last
node to the new node.
*Visual Representation of Insertion at Last
data next
Head
data next data next
NULLdata next
Newnode
Current/
Last
void last_insert()
{
struct node *newnode, *current;
newnode = (struct node*)malloc(sizeof(struct node));
newnode->next = NULL;
if(head == NULL)
{
head = newnode;
current = newnode;
}
else
{
current->next = newnode;
current = newnode;
}
}
//Inserting at last
Insertion at mid
• There are several steps to be followed to insert a node at mid position.
They are:
 Find the position after which and before which node the new node
is going to be inserted.
 Assign their locations to two different pointers named ‘temp’,
‘temp2’
respectively.
 Make the next pointer of ‘temp’ to point newnode, and the next
pointer of newnode to ‘temp2’.
*Visual Representation of Insertion at Last
data next
Head
data next data next NULL
data next
Newnode
temp temp2
void mid_insert()
{
struct node *newnode, *temp, *temp2;
int position;
newnode = (struct node*)malloc(sizeof(struct
node));
newnode->next = NULL;
if(head == NULL)
{
head = newnode;
current = newnode;
}
else
{
temp=head;
for(i=1;i<position;i++)
temp = temp->next;
temp2 = temp->next;
temp->next = newnode;
newnode->next=temp2;
}
//Inserting at mid
Deletion
• Deleting is a simple process.
 At first we need to find the previous and the next node
of that particular node.
 Then we need to point the next pointer of the previous node to
the next node of the particular node we want to delete.
*Visual Representation of Deletion
data next
Head
data next data next NULL
temp temp2
void delete_node(int n){
int i;
struct node* temp,*p;
temp=root;
if(n==1){
root=temp->link;
}
else{
for(i=1;i<n-1;i++){
temp=temp->link;
}
p=temp->link;
temp->link=p->link;
}
}
//Deletion
Searching
• To search in a linked list we need to follow the steps given below:
 We need a pointer which is assigned with the address of head
pointer.
 Then we start a loop until the last node of the linked list to search.
int search(int n){
int i;
struct node* temp;
temp=root;
int l=length();
for(i=1;i<=l;i++){
if(temp->data==n){
return i;
}
temp=temp->link;
}
if(i>l){
return 0;
}
}
//Searching
Display
• To display thelinked list we need to follow the steps given below:
 We need a pointer which is assigned with the address of head
pointer.
 Then we start a loop until the last node of the linked list to display
the
the list.
void display(){
struct node* temp;
temp=root;
if(temp==NULL){
printf("no data foundn");
}
else{
while(temp!=NULL){
printf("%d-->>",temp->data);
temp=temp->link;
}
}
}
//Display
Uses of Linked List
1. Web-browsers
A good example I see is web-browsers, where it creates a
linked list of web-pages visited, so that when you check
history (traversal of a list) or press back button, the previous
node's data is fetched.
2. Stacks and queues
It is used to develop stacks and queues which have lots of
applications.
3. Image viewer
4. Phonebook
In phonebook the names are
sorting in ascending order. If we
want to add a new contact then
the memory for the new
contact is created by linked
list.
Advantages
• Linked lists are a dynamic data structure, allocating the needed
memory while the program is running.
• Insertion and deletion node operations are easily implemented
in a linked list.
• Linear data structures such as stacks and queues are easily
executed with a linked list.
• They can reduce access time and may expand in real time
without memory overhead.
Disadvantages
• They have a quite difficult to use more memory due to pointers
requiring extra storage space.
• Nodes in a linked list must be read in order from the beginning
as linked lists are inherently sequential access.
• Nodes are stored in continuously, greatly increasing the time
required to access individual elements within the list.
• Difficulties arise in linked lists when it comes to reverse traversing.
For instance, singly linked lists are cumbersome to navigate
backwards and while doubly linked lists are somewhat easier to
read, memory is wasted in allocating space for a back pointer.
Thank you!

More Related Content

What's hot

1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
Digvijay Singh Karakoti
 
Linked List
Linked ListLinked List
Linked List
RaaviKapoor
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
Äshïsh Jäïn
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
Single linked list
Single linked listSingle linked list
Single linked list
jasbirsingh chauhan
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
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
 
Expression trees
Expression treesExpression trees
Expression trees
Salman Vadsarya
 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
 

What's hot (20)

1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Linked List
Linked ListLinked List
Linked List
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Linked list
Linked listLinked list
Linked list
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Linked list
Linked list Linked list
Linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Linked lists
Linked listsLinked lists
Linked lists
 
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...
 
Expression trees
Expression treesExpression trees
Expression trees
 
Linked list
Linked listLinked list
Linked list
 

Viewers also liked

Single linked list
Single linked listSingle linked list
Single linked list
Sayantan Sur
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 
Link List
Link ListLink List
Link List
umiekalsum
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
Papu Kumar
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
Michael Heron
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
Vivek Bhargav
 
Linked list
Linked listLinked list
Linked list
Lovelyn Rose
 
Linked List data structure
Linked List data structureLinked List data structure
Linked List data structure
Marcus Biel
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
pinkpreet_kaur
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Parallel Circuits
Parallel CircuitsParallel Circuits
Parallel Circuits
Md. Afif Al Mamun
 
Files in c++
Files in c++Files in c++
Files in c++
Selvin Josy Bai Somu
 
File handling
File handlingFile handling
File handling
Nilesh Dalvi
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
Ahmed Farag
 
linked list
linked list linked list
linked list
Narendra Chauhan
 
Linked lists
Linked listsLinked lists
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
Tushar Aneyrao
 
File Handling in C++
File Handling in C++File Handling in C++
file handling c++
file handling c++file handling c++
file handling c++
Guddu Spy
 
File Handling In C++
File Handling In C++File Handling In C++

Viewers also liked (20)

Single linked list
Single linked listSingle linked list
Single linked list
 
linked list
linked list linked list
linked list
 
Link List
Link ListLink List
Link List
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked List data structure
Linked List data structureLinked List data structure
Linked List data structure
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Parallel Circuits
Parallel CircuitsParallel Circuits
Parallel Circuits
 
Files in c++
Files in c++Files in c++
Files in c++
 
File handling
File handlingFile handling
File handling
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
linked list
linked list linked list
linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
file handling c++
file handling c++file handling c++
file handling c++
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 

Similar to Linked list

Unit II Data Structure 2hr topic - List - Operations.pptx
Unit II  Data Structure 2hr topic - List - Operations.pptxUnit II  Data Structure 2hr topic - List - Operations.pptx
Unit II Data Structure 2hr topic - List - Operations.pptx
Mani .S (Specialization in Semantic Web)
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
Dabbal Singh Mahara
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
arnold 7490
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
ThenmozhiK5
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptx
jack881
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
KylaMaeGarcia1
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
KasthuriKAssistantPr
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
JITTAYASHWANTHREDDY
 
Linked List
Linked ListLinked List
Linked List
CHANDAN KUMAR
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
MatthPYNashd
 
Data structure
 Data structure Data structure
Data structure
Shahariar limon
 
Linked list
Linked listLinked list
Linked list
A. S. M. Shafi
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
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
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
PoonamPatil120
 
Data Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptxData Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptx
RashidFaridChishti
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
EmilyMengich
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
shalins6
 

Similar to Linked list (20)

Unit II Data Structure 2hr topic - List - Operations.pptx
Unit II  Data Structure 2hr topic - List - Operations.pptxUnit II  Data Structure 2hr topic - List - Operations.pptx
Unit II Data Structure 2hr topic - List - Operations.pptx
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
 
Linked list
Linked listLinked list
Linked list
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptx
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 
Linked List
Linked ListLinked List
Linked List
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
 
Data structure
 Data structure Data structure
Data structure
 
Linked list
Linked listLinked list
Linked list
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
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
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
Data Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptxData Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptx
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
 

More from Md. Afif Al Mamun

Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
Md. Afif Al Mamun
 
Relational Algebra Introduction
Relational Algebra IntroductionRelational Algebra Introduction
Relational Algebra Introduction
Md. Afif Al Mamun
 
Internet of Things(IoT)
Internet of Things(IoT)Internet of Things(IoT)
Internet of Things(IoT)
Md. Afif Al Mamun
 
Introduction to Software
Introduction to SoftwareIntroduction to Software
Introduction to Software
Md. Afif Al Mamun
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
Md. Afif Al Mamun
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
Md. Afif Al Mamun
 
Mechanism of a Microwave Oven.
Mechanism of a Microwave Oven.Mechanism of a Microwave Oven.
Mechanism of a Microwave Oven.
Md. Afif Al Mamun
 
George Harrison
George HarrisonGeorge Harrison
George Harrison
Md. Afif Al Mamun
 
Artificial Intelligence(AI).
Artificial Intelligence(AI).Artificial Intelligence(AI).
Artificial Intelligence(AI).
Md. Afif Al Mamun
 

More from Md. Afif Al Mamun (9)

Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
 
Relational Algebra Introduction
Relational Algebra IntroductionRelational Algebra Introduction
Relational Algebra Introduction
 
Internet of Things(IoT)
Internet of Things(IoT)Internet of Things(IoT)
Internet of Things(IoT)
 
Introduction to Software
Introduction to SoftwareIntroduction to Software
Introduction to Software
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
Mechanism of a Microwave Oven.
Mechanism of a Microwave Oven.Mechanism of a Microwave Oven.
Mechanism of a Microwave Oven.
 
George Harrison
George HarrisonGeorge Harrison
George Harrison
 
Artificial Intelligence(AI).
Artificial Intelligence(AI).Artificial Intelligence(AI).
Artificial Intelligence(AI).
 

Recently uploaded

5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 

Recently uploaded (20)

5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 

Linked list

  • 2. What is Linked List A linked list is a linear collection of data elements, called nodes, each pointing to the next node by means of a pointer. It is a data structure consisting of a group of nodes which together represent a sequence. Linked lists were developed in 1955–1956 by Allen Newell, Cliff Shaw and Herbert A. Simon. It contains data field & Address field or Link field.
  • 3. A graphical view of a linked list
  • 4. Why do we use Linked List? Linked lists are preferable over arrays when: a) we need constant-time insertions/deletions from the list (such as in real-time computing where time predictability is absolutely critical ) b) We don't know how many items will be in the list. With arrays, you may need to re-declare and copy memory if the array grows too big c) We don't need random access to any elements d) We want to be able to insert items in the middle of the list (such as a priority queue)
  • 5. Types of Linked List There are three types of linked list as given below: 1. Singly Linked List 2. Doubly Linked List 3. Circular Linked List
  • 6. Singly Linked List A graphical view of a singly linked list
  • 7. Doubly Linked List In doubly linked list each node is divided into three parts: 1. The first part is PREV part. 2. The second part is the INFO part. 3. The third part is NEXT part.
  • 8. A graphical view of a doubly linked list
  • 9. Circular Linked List A graphical view of a circular linked list
  • 10. Singly Linked List Operations There are several operations in singly linked list: 1.Creation 2. Insertion 3. Deletion 4. Searching 5. Display
  • 11. Nodes • Nodes are the units which makes up linked list. • In singly linked list, nodes are actually structures made up of data and a pointer to another node. • Usually we denote the pointer as “*next”
  • 12. *Nodes structure struct node { int data; //This is where we will store data struct node *next; //This is the link part }*head=NULL; /*Initially we assign “NULL” to the head for later operational purpose*/
  • 13. *Visual Representation of Node data next Node
  • 14. Creation • Creation operation is used to create a linked list. • Generally, we use dynamic memory allocation to create our desired number of nodes for linked list in program run time.
  • 15. void create() { struct node *newnode, *current; newnode = (struct node*)malloc(sizeof(struct node)); newnode->next = NULL; if(head == NULL) { head = newnode; current = newnode; } else { current->next = newnode; current = newnode; } } //Creating linked list in ‘C’
  • 16. *Visual Representation of Linked List data next Head data next data next NULL
  • 17. Insertion • Insertion operation is used to insert a new node in the linked list. • Insertion is of three types. They are:  Inserting at first  Inserting at last  Inserting at mid
  • 18. Insertion at first • There are two steps to be followed to insert a node at first position. They are:  Make the next pointer of the node point towards the first node of the list.  Make the head pointer point towards this new node.
  • 19. *Visual Representation of Insertion at First data next Head data next data next NULL Newnode nextdata
  • 20. void first_insert() { struct node *newnode, *current; newnode = (struct node*)malloc(sizeof(struct node)); newnode->next = NULL; if(head == NULL) { head = newnode; current = newnode; } else { newnode->next = head; head = newnode; } } //Inserting at first
  • 21. Insertion at last • Inserting at the last position is a simple process.  To insert at last we just simply need to make the next pointer of last node to the new node.
  • 22. *Visual Representation of Insertion at Last data next Head data next data next NULLdata next Newnode Current/ Last
  • 23. void last_insert() { struct node *newnode, *current; newnode = (struct node*)malloc(sizeof(struct node)); newnode->next = NULL; if(head == NULL) { head = newnode; current = newnode; } else { current->next = newnode; current = newnode; } } //Inserting at last
  • 24. Insertion at mid • There are several steps to be followed to insert a node at mid position. They are:  Find the position after which and before which node the new node is going to be inserted.  Assign their locations to two different pointers named ‘temp’, ‘temp2’ respectively.  Make the next pointer of ‘temp’ to point newnode, and the next pointer of newnode to ‘temp2’.
  • 25. *Visual Representation of Insertion at Last data next Head data next data next NULL data next Newnode temp temp2
  • 26. void mid_insert() { struct node *newnode, *temp, *temp2; int position; newnode = (struct node*)malloc(sizeof(struct node)); newnode->next = NULL; if(head == NULL) { head = newnode; current = newnode; } else { temp=head; for(i=1;i<position;i++) temp = temp->next; temp2 = temp->next; temp->next = newnode; newnode->next=temp2; } //Inserting at mid
  • 27. Deletion • Deleting is a simple process.  At first we need to find the previous and the next node of that particular node.  Then we need to point the next pointer of the previous node to the next node of the particular node we want to delete.
  • 28. *Visual Representation of Deletion data next Head data next data next NULL temp temp2
  • 29. void delete_node(int n){ int i; struct node* temp,*p; temp=root; if(n==1){ root=temp->link; } else{ for(i=1;i<n-1;i++){ temp=temp->link; } p=temp->link; temp->link=p->link; } } //Deletion
  • 30. Searching • To search in a linked list we need to follow the steps given below:  We need a pointer which is assigned with the address of head pointer.  Then we start a loop until the last node of the linked list to search.
  • 31. int search(int n){ int i; struct node* temp; temp=root; int l=length(); for(i=1;i<=l;i++){ if(temp->data==n){ return i; } temp=temp->link; } if(i>l){ return 0; } } //Searching
  • 32. Display • To display thelinked list we need to follow the steps given below:  We need a pointer which is assigned with the address of head pointer.  Then we start a loop until the last node of the linked list to display the the list.
  • 33. void display(){ struct node* temp; temp=root; if(temp==NULL){ printf("no data foundn"); } else{ while(temp!=NULL){ printf("%d-->>",temp->data); temp=temp->link; } } } //Display
  • 34. Uses of Linked List 1. Web-browsers A good example I see is web-browsers, where it creates a linked list of web-pages visited, so that when you check history (traversal of a list) or press back button, the previous node's data is fetched. 2. Stacks and queues It is used to develop stacks and queues which have lots of applications.
  • 36. 4. Phonebook In phonebook the names are sorting in ascending order. If we want to add a new contact then the memory for the new contact is created by linked list.
  • 37. Advantages • Linked lists are a dynamic data structure, allocating the needed memory while the program is running. • Insertion and deletion node operations are easily implemented in a linked list. • Linear data structures such as stacks and queues are easily executed with a linked list. • They can reduce access time and may expand in real time without memory overhead.
  • 38. Disadvantages • They have a quite difficult to use more memory due to pointers requiring extra storage space. • Nodes in a linked list must be read in order from the beginning as linked lists are inherently sequential access. • Nodes are stored in continuously, greatly increasing the time required to access individual elements within the list. • Difficulties arise in linked lists when it comes to reverse traversing. For instance, singly linked lists are cumbersome to navigate backwards and while doubly linked lists are somewhat easier to read, memory is wasted in allocating space for a back pointer.