SlideShare a Scribd company logo
1 of 49
Download to read offline
LINKED LIST
Data Structure
Definition
A linked list is an ordered collection of finite, homogeneous data
elements called nodes where the linear order is maintained by means of
links or pointers.
• Linked list is called a dynamic data structure as the amount of
memory can be varied during use.
• Adjacency between memory elements is maintained by means of links
and nodes.
• A link is nothing but the address of the subsequent element.
• An element in a linked list is referred as Node, which consists of two
fields: DATA and LINK.
DS - Linked List
Single Linked List
 In a singly linked list, each node contains only one link which points to
the subsequent node in the list.
 HEADER is an empty node (data content NULL) and is used to store
a pointer to the first node N1.
 Starting from the first node one can reach the last node whose link
field does not contain any address but has a null value.
 In a single linked list one can move from left to right only, so its also
called one way list.
DS - Linked List
Representations of a Single Linked List
A single linked list can be represented in two ways:
 Static representation using Array
 Dynamic representation using free pool of storage
DS - Linked List
Static Representation
 2 arrays are maintained: one for
data, another for links.
 2 parallel arrays of equal size
are allocated which should be
sufficient to store the entire list.
 Though it contradicts the idea of
linked list but in programming
languages like ALGOL,
FORTRAN, BASIC etc. this is
the only way of representation.
DS - Linked List
Static Representation
DS - Linked List
Dynamic Representation
 In this process there’s a memory bank (a collection of memory spaces
available to the programmer) and a memory manager (a program).
 During creation of a linked list, when a node is required, the request is
sent to the memory manager.
 It then checks the memory bank for the requested block and if its
found then grants the block to the caller.
 There’s also a program called garbage collector. Whenever a node is
no more in use it send the unused node back to the memory bank.
 This type of memory management is known as Dynamic Memory
Management
DS - Linked List
Dynamic Representation
DS - Linked List
Operation on a Single Linked List
 Traversal
 Insertion
 Deletion
 Copy
 Merge
 Search
DS - Linked List
Traversing a Single Linked List
In traversing, we visit every single node in the list starting from the first to
last node.
Algorithm Traverse_SL
Input: HEADER is the pointer to the header node
Output: According to the Process()
Data Structure: A single linked list whose address of the starting node is
known from the HEADER.
DS - Linked List
1. ptr = HEADER → LINK
2. while(ptr=NULL)do
3. Process(ptr)
4. ptr=ptr → LINK
5. EndWhile
6. Stop
Inserting a node into a Single Linked List
Various positions are there for a node to be inserted:
 At the front (as a first element)
 At the end (as a last element)
 At any other position
DS - Linked List
Insertion…..contd….
Let us assume a procedure GetNode(NODE) to get a pointer of a
memory block which suits the type NODE. The procedure is to
understand how a node can be allocated. In C, C++ and Java, there are
library routines like alloc(), malloc() etc. to do the same.
Procedure GetNode
Input: NODE is the type of data for which a memory has to be allocated
Output: Return a message if the allocation fails else the pointer to the
memory block allocated.
DS - Linked List
Procedure GetNode
DS - Linked List
If(AVAIL=NULL)
Return(NULL)
Print "Insufficient memory: Unable to allocate memory"
Else
ptr=AVAIL //Start from location where AVAIL points
While(Sizeof(ptr)!=SizeOf(NODE)) and (ptr->LINK!=NULL) do
ptr1=ptr //to keep track of previous block
ptr=ptr->LINK //move to the next block
EndWhile
If(SizeOf(ptr)=SizeOf(NODE)) //memory block of right size is found
ptr1->LINK=ptr->LINK //update the avail list
Return(ptr)
Else
Print"The memory block is too large to fit"
Return(NULL)
EndIf
EndIf
Stop
Insertion at the front
Algorithm InsertFront_SL
Input: HEADER is the pointer to the header node and X is the data of the
node to be inserted
Output: A single linked list with a newly inserted node at the front
Data Structure: A single linked list whose address of the starting node is
known from the header
DS - Linked List
new = GetNode(NODE)
If(new=NULL)then
Print"Memory underflow: No insertion"
Exit
Else
new->LINK=HEADER->LINK //change of pointer1 as in fig.
new->DATA=X //copy the data X to newly availed node
HEADER->LINK=new //change of pointer2 as in fig.
EndIf
Stop
Insertion……contd…
DS - Linked List
Insertion at the end
Algorithm InsertFront_SL
Input: HEADER is the pointer to the header node and X is the data of the
node to be inserted
Output: A single linked list with a newly inserted node at the end
Data Structure: A single linked list whose address of the starting node is
known from the header
DS - Linked List
new = GetNode(NODE)
If(new=NULL)then
Print"Memory is insufficient: insertion not possible"
Exit
Else
ptr=HEADER
While(ptr->LINK!=NULL)do
ptr=ptr->LINK
EndWhile
ptr->LINK=new
new->DATA=X
EndIf
Stop
Insertion at the end……contd…
DS - Linked List
Insertion at any position
Algorithm InsertAny_SL
Input: HEADER is the pointer to the header node and X is the data of the
node to be inserted
Output: A single linked list with a newly inserted node having data X after
the node with data KEY
Data Structure: A single linked list whose address of the starting node is
known from the header
DS - Linked List
Insertion at any position……contd…
DS - Linked List
new = GetNode(NODE)
If(new=NULL)then
Print"Memory is insufficient: insertion not possible"
Exit
Else
ptr=HEADER
While(ptr.DATA!=KEY) and (ptr.LINK!=NULL)do
ptr->LINK
EndWhile
If(ptr.LINK=NULL)then
Print"KEY is not available in the list"
Exit
Else
new->LINK=ptr->LINK
new->DATA=X
ptr->LINK=new
EndIf
EndIf
Stop
Deletion of a node from a Single Linked List
Like Insertion operation, Deletion operation can also be executed
different positions:
 At the front of the list
 At the end of the list
 At any position
Let us consider a procedure ReturnNode(ptr) which returns a node
having pointer ptr to the free pool of storage.
DS - Linked List
Procedure ReturnNode(ptr)
DS - Linked List
new = GetNode(NODE)
If(new=NULL)then
Print"Memory is insufficient: insertion not possible"
Exit
Else
ptr=HEADER
While(ptr.DATA!=KEY) and (ptr.LINK!=NULL)do
ptr->LINK
EndWhile
If(ptr.LINK=NULL)then
Print"KEY is not available in the list"
Exit
Else
new->LINK=ptr->LINK
new->DATA=X
ptr->LINK=new
EndIf
EndIf
Stop
Deletion from the front of list
Algortihm DeleteFront_SL
Input- HEADER is the pointer to the header node
Output: A single linked list eliminating the node at the front
Data Structure: A single linked list whose address of the starting node is
known from the header.
DS - Linked List
Deletion from the front of list
DS - Linked List
Deletion from the end of list
Algortihm DeleteEnd_SL
Input: HEADER is the pointer to the header node
Output: A single linked list eliminating the node at the end of list
Data Structure: A single linked list whose address of the starting node is
known from the header.
DS - Linked List
Deletion from the end of list
DS - Linked List
Deletion from any position in the list
Algortihm DeleteAny_SL
Input: HEADER is the pointer to the header node
Output: A single linked list eliminating the node at the end of list
Data Structure: A single linked list whose address of the starting node is
known from the header.
DS - Linked List
Deletion from any position in the list
DS - Linked List
Copying a Single Linked List
Algortihm Copy_SL
Input: HEADER is the pointer to the header node
Output: HEADER1 is the pointer to the duplicate list
Data Structure: Single linked list structure
DS - Linked List
Merging two linked lists into one
Algortihm Merge_SL
Input: HEADER1 and HEADER are the pointers to the header nodes
Output: HEADER is the pointer to the resultant list
Data Structure: Single linked list structure
DS - Linked List
Merging two linked lists into one
DS - Linked List
ptr = HEADER1
While(ptr->LINK!=NULL)do
ptr=ptr->LINK
EndWhile
ptr->LINK=HEADER2->LINK
ReturnNode(HEADER2)
HEADER=HEADER1
Stop
Searching for an element in a Singly Linked List
Algortihm Search_SL
Input: KEY, the item to be searched
Output: LOCATION, the pointer to a node where the KEY belongs to or
an error message
Data Structure: Single linked list structure
DS - Linked List
Circular Linked List
A linked list where the last node points the header node is called the
Circular Linked List.
 In a Circular Linked List, every member node is accessible from any
node by chaining through the list.
DS - Linked List
Searching an element in Circular Linked List
Algortihm Search_CL
Input: KEY, the item to be searched
Output: LOCATION, the pointer to a node where the KEY belongs to or
an error message
Data Structure: A circular linked list
DS - Linked List
Merging of two Circular Linked Lists
Algortihm Merge_CL
Input: HEADER1 and HEADER are the pointers to the header nodes
Output: A large circular linked list containing all the nodes from
HEADER1 and HEADER2
Data Structure: Circular linked list structure
DS - Linked List
Merging of two Circular Linked Lists
DS - Linked List
Double Linked List
 A Doubly Linked List is a two way list as, one can move either from
left to right or from right to left.
 The two-way process is maintained using two link fields instead of one
as in a single linked list.
DS – Linked List
Inserting a node in the front a Doubly Linked List
Algorithm InsertFront_DL
Input: X is the data content of the node to be inserted
Output: A double linked list enriched with a node in the front
containing data X
Data Structure: Double linked list whose pointer to the
header node is HEADER
DS – Linked List
Inserting a node in the front of a Doubly Linked List
DS – Linked List
Inserting a node in a Doubly Linked List
DS – Linked List
Inserting a node at the end of a Doubly Linked List
Algorithm InsertEnd_DL
Input: X is the data content of the node to be inserted
Output: A double linked list enriched with a node at the end containing
data X
Data Structure: Double linked list whose pointer to the header node is
HEADER
DS – Linked List
Inserting a node at the end a Doubly Linked List
DS – Linked List
Inserting a node at any point of a Doubly Linked List
Algorithm InsertAny_DL
Input: X is the data content of the node to be inserted, and KEY the data
content of the node after which the new node is to be inserted.
Output: A double linked list enriched with a node containing data X after
the node with data KEY, if KEY is not present in the list then it is
inserted at the end.
Data Structure: Double linked list whose pointer to the header node is
HEADER
DS – Linked List
Inserting a node at any point of a Doubly Linked List
DS – Linked List
Deleting a node from the front of a Doubly Linked List
DS – Linked List
Algorithm DeleteFront_DL
Input: A doubly linked list with data
Output: A reduced doubly linked list
Data Structure: Double linked list whose pointer to the header node is
HEADER
Deleting a node from the end of a Doubly Linked List
Algorithm DeleteEnd_DL
Input: A doubly linked list with data
Output: A reduced doubly linked list
Data Structure: Double linked list whose pointer to the header node is
HEADER
DS – Linked List
Deleting a node from any position in a Doubly Linked List
Algorithm DeleteAny_DL
Input: X is the data content of the node to be inserted, and KEY the data
content of the node to be deleted.
Output: A double linked list without a node having data content KEY, if
any.
Data Structure: Doubly linked list whose pointer to the header node is
HEADER
DS – Linked List
Deleting a node from any position in a Doubly Linked List
DS – Linked List
Image
DS – Linked List
THANK YOU
If any doubt contact @9038540603
Or
Email me: kaustavr25@gmail.com

More Related Content

What's hot

What's hot (20)

Data Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceData Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer Science
 
Latex
LatexLatex
Latex
 
introduction to_trees
introduction to_treesintroduction to_trees
introduction to_trees
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mapping
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Latex for beginner
Latex for beginnerLatex for beginner
Latex for beginner
 
SWT Lecture Session 11 - R2RML part 2
SWT Lecture Session 11 - R2RML part 2SWT Lecture Session 11 - R2RML part 2
SWT Lecture Session 11 - R2RML part 2
 
Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for files
 
LaTeX Part 1
LaTeX Part 1LaTeX Part 1
LaTeX Part 1
 
Data Structures(Part 1)
Data Structures(Part 1)Data Structures(Part 1)
Data Structures(Part 1)
 
Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture Notes
 
Latex workshop
Latex workshopLatex workshop
Latex workshop
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Introduction to Latex
Introduction to LatexIntroduction to Latex
Introduction to Latex
 
Ii pu cs practical viva voce questions
Ii pu cs  practical viva voce questionsIi pu cs  practical viva voce questions
Ii pu cs practical viva voce questions
 
Sql
SqlSql
Sql
 
scientific writing 01 - latex
scientific writing   01 - latexscientific writing   01 - latex
scientific writing 01 - latex
 
Introduction of Data Structures and Algorithms by GOWRU BHARATH KUMAR
Introduction of Data Structures and Algorithms by GOWRU BHARATH KUMARIntroduction of Data Structures and Algorithms by GOWRU BHARATH KUMAR
Introduction of Data Structures and Algorithms by GOWRU BHARATH KUMAR
 

Similar to Linked List Basics

1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
Data Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptxData Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptxJoannahClaireAlforqu
 
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
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseoJinTaek Seo
 
Data structure
Data structureData structure
Data structureNida Ahmed
 
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 searchEstiak Khan
 
46267037-Data-Structures-PPT.ppt
46267037-Data-Structures-PPT.ppt46267037-Data-Structures-PPT.ppt
46267037-Data-Structures-PPT.pptRizwanBasha12
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notesDreamers6
 

Similar to Linked List Basics (20)

Linked List
Linked ListLinked List
Linked List
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Data Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptxData Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptx
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked 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...
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Linked list
Linked listLinked list
Linked list
 
02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo
 
Linked list
Linked list Linked list
Linked list
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Data structure
 Data structure Data structure
Data structure
 
Data structure
Data structureData structure
Data structure
 
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
Linked ListLinked List
Linked List
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
 
46267037-Data-Structures-PPT.ppt
46267037-Data-Structures-PPT.ppt46267037-Data-Structures-PPT.ppt
46267037-Data-Structures-PPT.ppt
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Data Structure
Data StructureData Structure
Data Structure
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notes
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Linked List Basics

  • 2. Definition A linked list is an ordered collection of finite, homogeneous data elements called nodes where the linear order is maintained by means of links or pointers. • Linked list is called a dynamic data structure as the amount of memory can be varied during use. • Adjacency between memory elements is maintained by means of links and nodes. • A link is nothing but the address of the subsequent element. • An element in a linked list is referred as Node, which consists of two fields: DATA and LINK. DS - Linked List
  • 3. Single Linked List  In a singly linked list, each node contains only one link which points to the subsequent node in the list.  HEADER is an empty node (data content NULL) and is used to store a pointer to the first node N1.  Starting from the first node one can reach the last node whose link field does not contain any address but has a null value.  In a single linked list one can move from left to right only, so its also called one way list. DS - Linked List
  • 4. Representations of a Single Linked List A single linked list can be represented in two ways:  Static representation using Array  Dynamic representation using free pool of storage DS - Linked List
  • 5. Static Representation  2 arrays are maintained: one for data, another for links.  2 parallel arrays of equal size are allocated which should be sufficient to store the entire list.  Though it contradicts the idea of linked list but in programming languages like ALGOL, FORTRAN, BASIC etc. this is the only way of representation. DS - Linked List
  • 7. Dynamic Representation  In this process there’s a memory bank (a collection of memory spaces available to the programmer) and a memory manager (a program).  During creation of a linked list, when a node is required, the request is sent to the memory manager.  It then checks the memory bank for the requested block and if its found then grants the block to the caller.  There’s also a program called garbage collector. Whenever a node is no more in use it send the unused node back to the memory bank.  This type of memory management is known as Dynamic Memory Management DS - Linked List
  • 9. Operation on a Single Linked List  Traversal  Insertion  Deletion  Copy  Merge  Search DS - Linked List
  • 10. Traversing a Single Linked List In traversing, we visit every single node in the list starting from the first to last node. Algorithm Traverse_SL Input: HEADER is the pointer to the header node Output: According to the Process() Data Structure: A single linked list whose address of the starting node is known from the HEADER. DS - Linked List 1. ptr = HEADER → LINK 2. while(ptr=NULL)do 3. Process(ptr) 4. ptr=ptr → LINK 5. EndWhile 6. Stop
  • 11. Inserting a node into a Single Linked List Various positions are there for a node to be inserted:  At the front (as a first element)  At the end (as a last element)  At any other position DS - Linked List
  • 12. Insertion…..contd…. Let us assume a procedure GetNode(NODE) to get a pointer of a memory block which suits the type NODE. The procedure is to understand how a node can be allocated. In C, C++ and Java, there are library routines like alloc(), malloc() etc. to do the same. Procedure GetNode Input: NODE is the type of data for which a memory has to be allocated Output: Return a message if the allocation fails else the pointer to the memory block allocated. DS - Linked List
  • 13. Procedure GetNode DS - Linked List If(AVAIL=NULL) Return(NULL) Print "Insufficient memory: Unable to allocate memory" Else ptr=AVAIL //Start from location where AVAIL points While(Sizeof(ptr)!=SizeOf(NODE)) and (ptr->LINK!=NULL) do ptr1=ptr //to keep track of previous block ptr=ptr->LINK //move to the next block EndWhile If(SizeOf(ptr)=SizeOf(NODE)) //memory block of right size is found ptr1->LINK=ptr->LINK //update the avail list Return(ptr) Else Print"The memory block is too large to fit" Return(NULL) EndIf EndIf Stop
  • 14. Insertion at the front Algorithm InsertFront_SL Input: HEADER is the pointer to the header node and X is the data of the node to be inserted Output: A single linked list with a newly inserted node at the front Data Structure: A single linked list whose address of the starting node is known from the header DS - Linked List new = GetNode(NODE) If(new=NULL)then Print"Memory underflow: No insertion" Exit Else new->LINK=HEADER->LINK //change of pointer1 as in fig. new->DATA=X //copy the data X to newly availed node HEADER->LINK=new //change of pointer2 as in fig. EndIf Stop
  • 16. Insertion at the end Algorithm InsertFront_SL Input: HEADER is the pointer to the header node and X is the data of the node to be inserted Output: A single linked list with a newly inserted node at the end Data Structure: A single linked list whose address of the starting node is known from the header DS - Linked List new = GetNode(NODE) If(new=NULL)then Print"Memory is insufficient: insertion not possible" Exit Else ptr=HEADER While(ptr->LINK!=NULL)do ptr=ptr->LINK EndWhile ptr->LINK=new new->DATA=X EndIf Stop
  • 17. Insertion at the end……contd… DS - Linked List
  • 18. Insertion at any position Algorithm InsertAny_SL Input: HEADER is the pointer to the header node and X is the data of the node to be inserted Output: A single linked list with a newly inserted node having data X after the node with data KEY Data Structure: A single linked list whose address of the starting node is known from the header DS - Linked List
  • 19. Insertion at any position……contd… DS - Linked List new = GetNode(NODE) If(new=NULL)then Print"Memory is insufficient: insertion not possible" Exit Else ptr=HEADER While(ptr.DATA!=KEY) and (ptr.LINK!=NULL)do ptr->LINK EndWhile If(ptr.LINK=NULL)then Print"KEY is not available in the list" Exit Else new->LINK=ptr->LINK new->DATA=X ptr->LINK=new EndIf EndIf Stop
  • 20. Deletion of a node from a Single Linked List Like Insertion operation, Deletion operation can also be executed different positions:  At the front of the list  At the end of the list  At any position Let us consider a procedure ReturnNode(ptr) which returns a node having pointer ptr to the free pool of storage. DS - Linked List
  • 21. Procedure ReturnNode(ptr) DS - Linked List new = GetNode(NODE) If(new=NULL)then Print"Memory is insufficient: insertion not possible" Exit Else ptr=HEADER While(ptr.DATA!=KEY) and (ptr.LINK!=NULL)do ptr->LINK EndWhile If(ptr.LINK=NULL)then Print"KEY is not available in the list" Exit Else new->LINK=ptr->LINK new->DATA=X ptr->LINK=new EndIf EndIf Stop
  • 22. Deletion from the front of list Algortihm DeleteFront_SL Input- HEADER is the pointer to the header node Output: A single linked list eliminating the node at the front Data Structure: A single linked list whose address of the starting node is known from the header. DS - Linked List
  • 23. Deletion from the front of list DS - Linked List
  • 24. Deletion from the end of list Algortihm DeleteEnd_SL Input: HEADER is the pointer to the header node Output: A single linked list eliminating the node at the end of list Data Structure: A single linked list whose address of the starting node is known from the header. DS - Linked List
  • 25. Deletion from the end of list DS - Linked List
  • 26. Deletion from any position in the list Algortihm DeleteAny_SL Input: HEADER is the pointer to the header node Output: A single linked list eliminating the node at the end of list Data Structure: A single linked list whose address of the starting node is known from the header. DS - Linked List
  • 27. Deletion from any position in the list DS - Linked List
  • 28. Copying a Single Linked List Algortihm Copy_SL Input: HEADER is the pointer to the header node Output: HEADER1 is the pointer to the duplicate list Data Structure: Single linked list structure DS - Linked List
  • 29. Merging two linked lists into one Algortihm Merge_SL Input: HEADER1 and HEADER are the pointers to the header nodes Output: HEADER is the pointer to the resultant list Data Structure: Single linked list structure DS - Linked List
  • 30. Merging two linked lists into one DS - Linked List ptr = HEADER1 While(ptr->LINK!=NULL)do ptr=ptr->LINK EndWhile ptr->LINK=HEADER2->LINK ReturnNode(HEADER2) HEADER=HEADER1 Stop
  • 31. Searching for an element in a Singly Linked List Algortihm Search_SL Input: KEY, the item to be searched Output: LOCATION, the pointer to a node where the KEY belongs to or an error message Data Structure: Single linked list structure DS - Linked List
  • 32. Circular Linked List A linked list where the last node points the header node is called the Circular Linked List.  In a Circular Linked List, every member node is accessible from any node by chaining through the list. DS - Linked List
  • 33. Searching an element in Circular Linked List Algortihm Search_CL Input: KEY, the item to be searched Output: LOCATION, the pointer to a node where the KEY belongs to or an error message Data Structure: A circular linked list DS - Linked List
  • 34. Merging of two Circular Linked Lists Algortihm Merge_CL Input: HEADER1 and HEADER are the pointers to the header nodes Output: A large circular linked list containing all the nodes from HEADER1 and HEADER2 Data Structure: Circular linked list structure DS - Linked List
  • 35. Merging of two Circular Linked Lists DS - Linked List
  • 36. Double Linked List  A Doubly Linked List is a two way list as, one can move either from left to right or from right to left.  The two-way process is maintained using two link fields instead of one as in a single linked list. DS – Linked List
  • 37. Inserting a node in the front a Doubly Linked List Algorithm InsertFront_DL Input: X is the data content of the node to be inserted Output: A double linked list enriched with a node in the front containing data X Data Structure: Double linked list whose pointer to the header node is HEADER DS – Linked List
  • 38. Inserting a node in the front of a Doubly Linked List DS – Linked List
  • 39. Inserting a node in a Doubly Linked List DS – Linked List
  • 40. Inserting a node at the end of a Doubly Linked List Algorithm InsertEnd_DL Input: X is the data content of the node to be inserted Output: A double linked list enriched with a node at the end containing data X Data Structure: Double linked list whose pointer to the header node is HEADER DS – Linked List
  • 41. Inserting a node at the end a Doubly Linked List DS – Linked List
  • 42. Inserting a node at any point of a Doubly Linked List Algorithm InsertAny_DL Input: X is the data content of the node to be inserted, and KEY the data content of the node after which the new node is to be inserted. Output: A double linked list enriched with a node containing data X after the node with data KEY, if KEY is not present in the list then it is inserted at the end. Data Structure: Double linked list whose pointer to the header node is HEADER DS – Linked List
  • 43. Inserting a node at any point of a Doubly Linked List DS – Linked List
  • 44. Deleting a node from the front of a Doubly Linked List DS – Linked List Algorithm DeleteFront_DL Input: A doubly linked list with data Output: A reduced doubly linked list Data Structure: Double linked list whose pointer to the header node is HEADER
  • 45. Deleting a node from the end of a Doubly Linked List Algorithm DeleteEnd_DL Input: A doubly linked list with data Output: A reduced doubly linked list Data Structure: Double linked list whose pointer to the header node is HEADER DS – Linked List
  • 46. Deleting a node from any position in a Doubly Linked List Algorithm DeleteAny_DL Input: X is the data content of the node to be inserted, and KEY the data content of the node to be deleted. Output: A double linked list without a node having data content KEY, if any. Data Structure: Doubly linked list whose pointer to the header node is HEADER DS – Linked List
  • 47. Deleting a node from any position in a Doubly Linked List DS – Linked List
  • 49. THANK YOU If any doubt contact @9038540603 Or Email me: kaustavr25@gmail.com