SlideShare a Scribd company logo
UNIT - III
Linked List
DATA STRUCTURES
 A linked list is a linear data structure which can store a collection of "nodes" connected
together via links i.e. pointers.
 Linked lists nodes are not stored at a contiguous location, rather they are linked using
pointers to the different memory locations.
 A node consists of the data value and a pointer to the address of the next node within the
linked list.
 A linked list is a dynamic linear data structure whose memory size can be allocated or de-
allocated at run time based on the operation insertion or deletion, this helps in using
system memory efficiently.
 Linked lists can be used to implement various data structures like a stack, queue, graph,
hash maps, etc.
ArraysVs Linked List
15
45
25
50
22
35
30
20
10
a
b
c
d
e
f
g
h
i
j
40
k
15
45
25
50
22
35
30
20
10
h a c
d
e
f
g
b
i
40
k
15
45
25
50
22
35
30
20
10
h
a c
d
e f
g
i
40
k b
15
45
25
50
22
35
30
20
10
h
40
Singly Linked Lists
 Singly linked lists contain two "buckets" in one node; one bucket holds the
data and the other bucket holds the address of the next node of the list.
 Traversals can be done in one direction only as there is only a single link
between two nodes of the same list.
Basic Operations in Linked List
Insertion − Adds an element at the beginning of the list.
Deletion − Deletes an element at the beginning of the list.
Display − Displays the complete list.
Search − Searches an element using the given key.
Delete − Deletes an element using the given key.
Linked List - Insertion Operation
Adding a new node in linked list is a more than one step activity. We shall
learn this with diagrams here.
First, create a node using the same structure and find the location where it
has to be inserted.
Imagine that we are inserting a node B (NewNode), between A
(LeftNode) and C (RightNode). Then point B.next to C −
NewNode.next -> RightNode;
LeftNode.next -> NewNode;
Deletion Operation
 Deletion is also a more than one step process. We shall learn with pictorial representation.
 First, locate the target node to be removed, by using searching algorithms.
 The left (previous) node of the target node now should point to the next node of the target node
LeftNode.next -> TargetNode.next;
This will remove the link that was pointing to the target node. Now, using the following code, we will
remove what the target node is pointing at.
TargetNode.next -> NULL;
We need to use the deleted node. We can keep that in memory otherwise we can simply
deallocate memory and wipe off the target node completely.
Linked List - Reversal Operation
This operation is a thorough one. We need to make the last node to be pointed by the head
node and reverse the whole linked list.
First, we traverse to the end of the list. It should be pointing to NULL. Now, we shall
make it point to its previous node
We have to make sure that the last node is not the last node. So we'll have some temp node, which looks
like the head node pointing to the last node. Now, we shall make all left side nodes point to their previous
nodes one by one.
Except the node (first node) pointed by the head node, all nodes should point to their predecessor,
making them their new successor. The first node will point to NULL.
Doubly Linked List
 Doubly Linked List is a variation of Linked list in which navigation is possible in both ways, forward as well as
backward easily as compared to Single Linked List
 Doubly Linked List contains a link element called first and last.
 Each link carries a data field(s) and a link field called next.
 Each link is linked with its next link using its next link.
 Each link is linked with its previous link using its previous link.
 The last link carries a link as null to mark the end of the list.
 Doubly linked list is a collection of nodes linked together in a
sequential way.
 Doubly linked list is almost similar to singly linked list except it
contains two address or reference fields, where one of the address
field contains reference of the next node and other contains
reference of the previous node.
 First and last node of a linked list contains a terminator generally a
NULL value, that determines the start and end of the list.
 Doubly linked list is sometimes also referred as bi-directional linked
list since it allows traversal of nodes in both direction.
 Since doubly linked list allows the traversal of nodes in both
direction, we can keep track of both first and last nodes.
Basic Operations in Doubly Linked List
Insertion − Adds an element at the beginning of the list.
Insert Last − Adds an element at the end of the list.
Insert After − Adds an element after an item of the list.
Deletion − Deletes an element at the beginning of the list.
Delete Last − Deletes an element from the end of the list.
Delete − Deletes an element from the list using the key.
Display forward − Displays the complete list in a forward manner.
Display backward − Displays the complete list in a backward manner.

More Related Content

PDF
Linked list
maamir farooq
 
PPTX
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
PPT
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
PPTX
link list.pptx complete notes detailed ans
IqraHanif27
 
PPT
Link list using array in Data structure amd algorithms
pwstudent403
 
PPTX
Doubly Linked List
V.V.Vanniaperumal College for Women
 
PPT
linked_lists.ppt linked_lists linked_lists
AmsaAzeem
 
PPTX
Linked list
sweetysweety8
 
Linked list
maamir farooq
 
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
link list.pptx complete notes detailed ans
IqraHanif27
 
Link list using array in Data structure amd algorithms
pwstudent403
 
linked_lists.ppt linked_lists linked_lists
AmsaAzeem
 
Linked list
sweetysweety8
 

Similar to Linked list, Singly link list and its operations (20)

PPT
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
PPTX
1.3 Linked List.pptx
ssuserd2f031
 
ODP
Linked List
Keshav Vaswani
 
PPTX
Data Structures(Part 1)
Dr. SURBHI SAROHA
 
PPTX
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
PPTX
Linked List Representation of a Linked List.pptx
AAUsH2
 
PPT
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
PPTX
Linked list in Data Structure and Algorithm
KristinaBorooah
 
PPTX
data structures and applications power p
MeghaKulkarni27
 
PPTX
linked list in data structure
shameen khan
 
PPT
Linked List
CHANDAN KUMAR
 
DOCX
Linked list.docx
EmilyMengich
 
PPTX
Linked list (1).pptx
rajveersingh643731
 
PPTX
csc211_lecture_21.pptx
ASADAHMAD811380
 
DOCX
Introduction to linked lists
pooja kumari
 
PPTX
Linked list
Wasif Khan
 
PDF
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
PDF
In this lab we will write code for working with a Linked List. Node .pdf
fms12345
 
PPTX
linked list using c
Venkat Reddy
 
PPTX
Linked List in Data Structure
Meghaj Mallick
 
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
1.3 Linked List.pptx
ssuserd2f031
 
Linked List
Keshav Vaswani
 
Data Structures(Part 1)
Dr. SURBHI SAROHA
 
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
Linked List Representation of a Linked List.pptx
AAUsH2
 
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
Linked list in Data Structure and Algorithm
KristinaBorooah
 
data structures and applications power p
MeghaKulkarni27
 
linked list in data structure
shameen khan
 
Linked List
CHANDAN KUMAR
 
Linked list.docx
EmilyMengich
 
Linked list (1).pptx
rajveersingh643731
 
csc211_lecture_21.pptx
ASADAHMAD811380
 
Introduction to linked lists
pooja kumari
 
Linked list
Wasif Khan
 
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
In this lab we will write code for working with a Linked List. Node .pdf
fms12345
 
linked list using c
Venkat Reddy
 
Linked List in Data Structure
Meghaj Mallick
 
Ad

More from BackiyalakshmiVenkat (10)

PPT
DBMS-Unit-3.0 Functional dependencies.ppt
BackiyalakshmiVenkat
 
PPT
Functional Dependencies in rdbms with examples
BackiyalakshmiVenkat
 
PPTX
database models in database management systems
BackiyalakshmiVenkat
 
PPTX
Normalization in rdbms types and examples
BackiyalakshmiVenkat
 
PPTX
introduction to advanced operating systems
BackiyalakshmiVenkat
 
PPT
Introduction to Database Management Systems
BackiyalakshmiVenkat
 
PPTX
object oriented programming in PHP & Functions
BackiyalakshmiVenkat
 
PPTX
Linked Lists, Single Linked list and its operations
BackiyalakshmiVenkat
 
PPTX
Evlotion of Big Data in Big data vs traditional Business
BackiyalakshmiVenkat
 
PPTX
AN ANALYSIS OF THE REASONS FOR NON-PERFORMING ASSETS (NPAs) TO THE STATE BANK...
BackiyalakshmiVenkat
 
DBMS-Unit-3.0 Functional dependencies.ppt
BackiyalakshmiVenkat
 
Functional Dependencies in rdbms with examples
BackiyalakshmiVenkat
 
database models in database management systems
BackiyalakshmiVenkat
 
Normalization in rdbms types and examples
BackiyalakshmiVenkat
 
introduction to advanced operating systems
BackiyalakshmiVenkat
 
Introduction to Database Management Systems
BackiyalakshmiVenkat
 
object oriented programming in PHP & Functions
BackiyalakshmiVenkat
 
Linked Lists, Single Linked list and its operations
BackiyalakshmiVenkat
 
Evlotion of Big Data in Big data vs traditional Business
BackiyalakshmiVenkat
 
AN ANALYSIS OF THE REASONS FOR NON-PERFORMING ASSETS (NPAs) TO THE STATE BANK...
BackiyalakshmiVenkat
 
Ad

Recently uploaded (20)

PPTX
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PPTX
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
mansk2
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Understanding operators in c language.pptx
auteharshil95
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Week 4 Term 3 Study Techniques revisited.pptx
mansk2
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 

Linked list, Singly link list and its operations

  • 1. UNIT - III Linked List DATA STRUCTURES
  • 2.  A linked list is a linear data structure which can store a collection of "nodes" connected together via links i.e. pointers.  Linked lists nodes are not stored at a contiguous location, rather they are linked using pointers to the different memory locations.  A node consists of the data value and a pointer to the address of the next node within the linked list.  A linked list is a dynamic linear data structure whose memory size can be allocated or de- allocated at run time based on the operation insertion or deletion, this helps in using system memory efficiently.  Linked lists can be used to implement various data structures like a stack, queue, graph, hash maps, etc.
  • 3. ArraysVs Linked List 15 45 25 50 22 35 30 20 10 a b c d e f g h i j 40 k 15 45 25 50 22 35 30 20 10 h a c d e f g b i 40 k 15 45 25 50 22 35 30 20 10 h a c d e f g i 40 k b 15 45 25 50 22 35 30 20 10 h 40
  • 4. Singly Linked Lists  Singly linked lists contain two "buckets" in one node; one bucket holds the data and the other bucket holds the address of the next node of the list.  Traversals can be done in one direction only as there is only a single link between two nodes of the same list.
  • 5. Basic Operations in Linked List Insertion − Adds an element at the beginning of the list. Deletion − Deletes an element at the beginning of the list. Display − Displays the complete list. Search − Searches an element using the given key. Delete − Deletes an element using the given key.
  • 6. Linked List - Insertion Operation Adding a new node in linked list is a more than one step activity. We shall learn this with diagrams here. First, create a node using the same structure and find the location where it has to be inserted.
  • 7. Imagine that we are inserting a node B (NewNode), between A (LeftNode) and C (RightNode). Then point B.next to C − NewNode.next -> RightNode; LeftNode.next -> NewNode;
  • 8. Deletion Operation  Deletion is also a more than one step process. We shall learn with pictorial representation.  First, locate the target node to be removed, by using searching algorithms.  The left (previous) node of the target node now should point to the next node of the target node LeftNode.next -> TargetNode.next;
  • 9. This will remove the link that was pointing to the target node. Now, using the following code, we will remove what the target node is pointing at. TargetNode.next -> NULL; We need to use the deleted node. We can keep that in memory otherwise we can simply deallocate memory and wipe off the target node completely.
  • 10. Linked List - Reversal Operation This operation is a thorough one. We need to make the last node to be pointed by the head node and reverse the whole linked list. First, we traverse to the end of the list. It should be pointing to NULL. Now, we shall make it point to its previous node
  • 11. We have to make sure that the last node is not the last node. So we'll have some temp node, which looks like the head node pointing to the last node. Now, we shall make all left side nodes point to their previous nodes one by one. Except the node (first node) pointed by the head node, all nodes should point to their predecessor, making them their new successor. The first node will point to NULL.
  • 12. Doubly Linked List  Doubly Linked List is a variation of Linked list in which navigation is possible in both ways, forward as well as backward easily as compared to Single Linked List  Doubly Linked List contains a link element called first and last.  Each link carries a data field(s) and a link field called next.  Each link is linked with its next link using its next link.  Each link is linked with its previous link using its previous link.  The last link carries a link as null to mark the end of the list.
  • 13.  Doubly linked list is a collection of nodes linked together in a sequential way.  Doubly linked list is almost similar to singly linked list except it contains two address or reference fields, where one of the address field contains reference of the next node and other contains reference of the previous node.  First and last node of a linked list contains a terminator generally a NULL value, that determines the start and end of the list.  Doubly linked list is sometimes also referred as bi-directional linked list since it allows traversal of nodes in both direction.  Since doubly linked list allows the traversal of nodes in both direction, we can keep track of both first and last nodes.
  • 14. Basic Operations in Doubly Linked List Insertion − Adds an element at the beginning of the list. Insert Last − Adds an element at the end of the list. Insert After − Adds an element after an item of the list. Deletion − Deletes an element at the beginning of the list. Delete Last − Deletes an element from the end of the list. Delete − Deletes an element from the list using the key. Display forward − Displays the complete list in a forward manner. Display backward − Displays the complete list in a backward manner.