SlideShare a Scribd company logo
1 of 24
LINKED LIST
Lecture 05
IT 2301 / CS 2301
Dhanushka Jayasinghe
What is Linked List ?
• A linked list is the most sought-after data structure when it comes to
handling dynamic data elements.
• A linked list is a linear data structure that includes a series of connected
nodes. Here, each containing data fields and one or two references (links)
pointing to the next and/or previous nodes.
• The last node contains null in its second field because it will point to no node.
• A linked list can grow and shrink its size, as per the requirement.
• It does not waste memory space.
Linked List Representation
Why use linked list over Array?
Array contains following limitations:
• The size of array must be known in advance before using it in the program.
• Increasing size of the array is a time taking process. It is almost impossible to expand the size
of the array at run time.
• All the elements in the array need to be contiguously stored in the memory. Inserting any
element in the array needs shifting of all its predecessors.
Linked list is the data structure which can overcome all the limitations of an array. Using linked
list is useful because,
• It allocates the memory dynamically. All the nodes of linked list are non-contiguously stored
in the memory and linked together with the help of pointers.
• Sizing is no longer a problem since we do not need to define its size at the time of
declaration. List grows as per the program's demand and limited to the available memory
space.
Types of Linked List
Following are the various types of linked list.
1) Singly Linked List − The nodes only point to the address of the next node in the list.
1) Doubly Linked List − The nodes point to the addresses of both previous and next nodes.
1) Circular Linked List − The last node in the list will point to the first node in the list. It can
either be singly linked or doubly linked
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.
Doubly Linked Lists
Doubly Linked Lists contain three “buckets” in one node; one bucket holds the data and the
other buckets hold the addresses of the previous and next nodes in the list. The list is traversed
twice as the nodes in the list are connected to each other from both sides.
Circular Linked Lists
⮚ In a circularly linked list, the first and final nodes are linked together. This can be
done for both singly and doubly linked lists.
⮚ Begin at any node and follow the list in either direction until return to the original
node.
⮚ No beginning or end.
⮚ Since the last node and the first node of the circular linked list are connected, the
traversal in this linked list will go on forever until it is broken.
• Singly-circularly-linked List
• Doubly-circularly-inked List
Singly Circularly Linked List
Doubly Circularly Linked List
Linked List
Node
A node consists with the data stored in the node and a pointer to the next node in the list
How to declare a linked list?
Linked list contains two parts, and both are of different types, i.e., one is the simple
variable, while another is the pointer variable. We can declare the linked list by using
the user-defined data type structure.
struct node
{
int data;
struct node
*next;
} ;
Complexity of Linked List
Linked List Vs arrays
Operation Array Linked List
Indexing O(1) O(n)
Inserting/Deleting at the
end
O(1) O(1) or O(n)
Inserting/ deleting in the
middle with iterator
O(n) O(1)
Linked List vs Arrays
◦ Elements can be inserted into linked lists indefinitely
◦ An array will eventually either fill up or need to be resized
◦ Arrays allow random access while linked list allow only sequential
access to elements
◦ Singly linked lists can traverse only in one direction
◦ Linked lists require extra storage for reference
Doubly Linked vs Singly Linked
oDoubly Linked Lists required more space per node
oDLL is easier to manipulate because they allow sequential access to the list in
both directions.
oCan be insert or delete node in a constant number of operations given only
that nodes address
oSLL requires the previous nodes address in order to correctly insert or delete
Circularly Linked vs Linearly Linked
o Circular Linked Lists are most useful for describing naturally circular
structures
o Able to traverse the list starting at any point
o Quick access to the first and the last record through a single pointer
o Complexity of iteration
Advantages of Linked list
• Dynamic data structure - The size of the linked list may vary according to the
requirements. Linked list does not have a fixed size.
• Insertion and deletion - Unlike arrays, insertion, and deletion in linked list is
easier. Array elements are stored in the consecutive location, whereas the
elements in the linked list are stored at a random location. To insert or delete an
element in an array, we have to shift the elements for creating the space.
Whereas, in linked list, instead of shifting, we just have to update the address of
the pointer of the node.
• Memory efficient - The size of a linked list can grow or shrink according to the
requirements, so memory consumption in linked list is efficient.
• Implementation - Various advanced data structures can be implemented using a
linked list like a stack, queue, graph, hash maps, etc.
Disadvantages of Linked list
• Memory usage - In linked list, node occupies more memory than array. Each
node of the linked list occupies two types of variables, i.e., one is a simple
variable, and another one is the pointer variable.
• Traversal - Traversal is not easy in the linked list. If we have to access an
element in the linked list, we cannot access it randomly, while in case of array
we can randomly access it by index. For example, if we want to access the 3rd
node, then we need to traverse all the nodes before it. So, the time required
to access a particular node is large.
• Reverse traversing - Backtracking or reverse traversing is difficult in a linked
list. In a doubly-linked list, it is easier but requires more memory to store the
back pointer.
Linked List operations
1.Traversing: To traverse all nodes one by one.
2.Insertion: To insert new nodes at specific positions.
3.Deletion: To delete nodes from specific positions.
4.Searching: To search for an element from the linked list.
Linked List operations
SINGLY LINKED LIST
Insertion - At the front of the linked
list
1. START
2. Create a node to store the data
3. Check if the list is empty
4. If the list is empty, add the data to the node and assign the head pointer to it.
5. If the list is not empty, add the data to a node and link to the current head. Assign the head to
the newly added node.
6. END
Insertion - After a given node
1. START
2. Create a new node and assign data to it
3. Iterate until the node at position is found
4. Point first to new first node
5. END
Insertion - At the end of the linked list
1. START
2. Create a new node and assign the data
3. Find the last node
4. Point the last node to new node
5. END
To be Continued..

More Related Content

Similar to Data Structures and Algorithms - Lec 05.pptx

Introduction to Data Structures and Linked List
Introduction to Data Structures and Linked ListIntroduction to Data Structures and Linked List
Introduction to Data Structures and Linked ListSelvaraj Seerangan
 
Introduction to linked lists
Introduction to linked listsIntroduction to linked lists
Introduction to linked listspooja kumari
 
Different types of Linked list.
Different types of Linked list.Different types of Linked list.
Different types of Linked list.JAYANTAOJHA
 
LINKED LIST.pptx
LINKED LIST.pptxLINKED LIST.pptx
LINKED LIST.pptxDr.Shweta
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power pMeghaKulkarni27
 
Static arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfStatic arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfanjanacottonmills
 
Linked List-Types.pdf
Linked List-Types.pdfLinked List-Types.pdf
Linked List-Types.pdfMaryJacob24
 
mbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxmbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxjotaro11
 
linked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentslinked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentsSazzadulIslam42
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked listLavanyaJ28
 

Similar to Data Structures and Algorithms - Lec 05.pptx (20)

Introduction to Data Structures and Linked List
Introduction to Data Structures and Linked ListIntroduction to Data Structures and Linked List
Introduction to Data Structures and Linked List
 
Introduction to linked lists
Introduction to linked listsIntroduction to linked lists
Introduction to linked lists
 
Linkedlists
LinkedlistsLinkedlists
Linkedlists
 
Different types of Linked list.
Different types of Linked list.Different types of Linked list.
Different types of Linked list.
 
LINKED LIST.pptx
LINKED LIST.pptxLINKED LIST.pptx
LINKED LIST.pptx
 
Linked list
Linked listLinked list
Linked list
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power p
 
Link list
Link listLink list
Link list
 
Link list
Link listLink list
Link list
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
Static arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfStatic arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdf
 
Linked List-Types.pdf
Linked List-Types.pdfLinked List-Types.pdf
Linked List-Types.pdf
 
mbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxmbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptx
 
Linked list
Linked listLinked list
Linked list
 
Data structure day1
Data structure day1Data structure day1
Data structure day1
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
2- link-list.ppt
2- link-list.ppt2- link-list.ppt
2- link-list.ppt
 
linked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentslinked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate students
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked list
 

Recently uploaded

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 

Data Structures and Algorithms - Lec 05.pptx

  • 1. LINKED LIST Lecture 05 IT 2301 / CS 2301 Dhanushka Jayasinghe
  • 2. What is Linked List ? • A linked list is the most sought-after data structure when it comes to handling dynamic data elements. • A linked list is a linear data structure that includes a series of connected nodes. Here, each containing data fields and one or two references (links) pointing to the next and/or previous nodes. • The last node contains null in its second field because it will point to no node. • A linked list can grow and shrink its size, as per the requirement. • It does not waste memory space.
  • 4. Why use linked list over Array? Array contains following limitations: • The size of array must be known in advance before using it in the program. • Increasing size of the array is a time taking process. It is almost impossible to expand the size of the array at run time. • All the elements in the array need to be contiguously stored in the memory. Inserting any element in the array needs shifting of all its predecessors. Linked list is the data structure which can overcome all the limitations of an array. Using linked list is useful because, • It allocates the memory dynamically. All the nodes of linked list are non-contiguously stored in the memory and linked together with the help of pointers. • Sizing is no longer a problem since we do not need to define its size at the time of declaration. List grows as per the program's demand and limited to the available memory space.
  • 5. Types of Linked List Following are the various types of linked list. 1) Singly Linked List − The nodes only point to the address of the next node in the list. 1) Doubly Linked List − The nodes point to the addresses of both previous and next nodes. 1) Circular Linked List − The last node in the list will point to the first node in the list. It can either be singly linked or doubly linked
  • 6. 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.
  • 7. Doubly Linked Lists Doubly Linked Lists contain three “buckets” in one node; one bucket holds the data and the other buckets hold the addresses of the previous and next nodes in the list. The list is traversed twice as the nodes in the list are connected to each other from both sides.
  • 8. Circular Linked Lists ⮚ In a circularly linked list, the first and final nodes are linked together. This can be done for both singly and doubly linked lists. ⮚ Begin at any node and follow the list in either direction until return to the original node. ⮚ No beginning or end. ⮚ Since the last node and the first node of the circular linked list are connected, the traversal in this linked list will go on forever until it is broken. • Singly-circularly-linked List • Doubly-circularly-inked List
  • 11. Linked List Node A node consists with the data stored in the node and a pointer to the next node in the list
  • 12. How to declare a linked list? Linked list contains two parts, and both are of different types, i.e., one is the simple variable, while another is the pointer variable. We can declare the linked list by using the user-defined data type structure. struct node { int data; struct node *next; } ;
  • 13. Complexity of Linked List Linked List Vs arrays Operation Array Linked List Indexing O(1) O(n) Inserting/Deleting at the end O(1) O(1) or O(n) Inserting/ deleting in the middle with iterator O(n) O(1)
  • 14. Linked List vs Arrays ◦ Elements can be inserted into linked lists indefinitely ◦ An array will eventually either fill up or need to be resized ◦ Arrays allow random access while linked list allow only sequential access to elements ◦ Singly linked lists can traverse only in one direction ◦ Linked lists require extra storage for reference
  • 15. Doubly Linked vs Singly Linked oDoubly Linked Lists required more space per node oDLL is easier to manipulate because they allow sequential access to the list in both directions. oCan be insert or delete node in a constant number of operations given only that nodes address oSLL requires the previous nodes address in order to correctly insert or delete
  • 16. Circularly Linked vs Linearly Linked o Circular Linked Lists are most useful for describing naturally circular structures o Able to traverse the list starting at any point o Quick access to the first and the last record through a single pointer o Complexity of iteration
  • 17. Advantages of Linked list • Dynamic data structure - The size of the linked list may vary according to the requirements. Linked list does not have a fixed size. • Insertion and deletion - Unlike arrays, insertion, and deletion in linked list is easier. Array elements are stored in the consecutive location, whereas the elements in the linked list are stored at a random location. To insert or delete an element in an array, we have to shift the elements for creating the space. Whereas, in linked list, instead of shifting, we just have to update the address of the pointer of the node. • Memory efficient - The size of a linked list can grow or shrink according to the requirements, so memory consumption in linked list is efficient. • Implementation - Various advanced data structures can be implemented using a linked list like a stack, queue, graph, hash maps, etc.
  • 18. Disadvantages of Linked list • Memory usage - In linked list, node occupies more memory than array. Each node of the linked list occupies two types of variables, i.e., one is a simple variable, and another one is the pointer variable. • Traversal - Traversal is not easy in the linked list. If we have to access an element in the linked list, we cannot access it randomly, while in case of array we can randomly access it by index. For example, if we want to access the 3rd node, then we need to traverse all the nodes before it. So, the time required to access a particular node is large. • Reverse traversing - Backtracking or reverse traversing is difficult in a linked list. In a doubly-linked list, it is easier but requires more memory to store the back pointer.
  • 19. Linked List operations 1.Traversing: To traverse all nodes one by one. 2.Insertion: To insert new nodes at specific positions. 3.Deletion: To delete nodes from specific positions. 4.Searching: To search for an element from the linked list.
  • 21. Insertion - At the front of the linked list 1. START 2. Create a node to store the data 3. Check if the list is empty 4. If the list is empty, add the data to the node and assign the head pointer to it. 5. If the list is not empty, add the data to a node and link to the current head. Assign the head to the newly added node. 6. END
  • 22. Insertion - After a given node 1. START 2. Create a new node and assign data to it 3. Iterate until the node at position is found 4. Point first to new first node 5. END
  • 23. Insertion - At the end of the linked list 1. START 2. Create a new node and assign the data 3. Find the last node 4. Point the last node to new node 5. END