SlideShare a Scribd company logo
1 of 17
Download to read offline
StudentName : Vinay Kamriya
StudentName : Vinay Kamriya
Year/Branch : 3rd year (CS)
Topic : Linked List
Table of content
• Introduction
• Keeping track of linked list
• Basic operations
– Traversing
– Insertion
– Insertion
– Deletion
• Types of linked list
– Singly linked list
– Circular linked list
– Doubly linked list
Spring 2012 Programming and Data Structure 2
Introduction
• A linked list is a data structure which can change
during execution.
– Successive elements are connected by pointers.
– Last element points to NULL.
– It can grow or shrink in size during execution of a
– It can grow or shrink in size during execution of a
program.
– It can be made just as long as required.
– It does not waste memory space.
Spring 2012 Programming and Data Structure 3
A B C
head
• Keeping track of a linked list:
– Must know the pointer to the first element of the
list (called start, head, etc.).
• Linked lists provide flexibility in allowing the
items to be rearranged efficiently.
items to be rearranged efficiently.
– Insert an element.
– Delete an element.
Spring 2012 Programming and Data Structure 4
Basic Operations on a List
• Traversing the list
• Inserting an item in the list
• Deleting an item from the list
• Deleting an item from the list
Spring 2012 Programming and Data Structure 5
Traversing a linked list
Spring 2012 Programming and Data Structure 6
Time complexcity of traversing an linkedlist
- O(n)
Pseudo-code for traversal
public static void traversal(Node head)
{
while(head!=null)
{
{
System.out.print(head.data + " ");
head = head.next;
}
}
Spring 2012 Programming and Data Structure 7
Illustration: Insertion
Item to be
inserted
X
A B C
tmp
Spring 2012 Programming and Data Structure 8
A
A
X
B C
curr
•For insertion:
–A record is created holding the new
item.
–The next pointer of the new record is
set to link it to the item which is to
follow it in the list.
Spring 2012 Programming and Data Structure 9
follow it in the list.
–The next pointer of the item which is
to precede it must be modified to point
to the new item.
Pseudo-code for insertion
public static Node insertAtFirst(Node head , int
data)
{
Node newNode = new Node(data);
newNode.next = head;
return newNode;
Spring 2012 Programming and Data Structure 10
return newNode;
}
Illustration: Deletion
A B C
Item to be deleted
curr
tmp
Spring 2012 Programming and Data Structure 11
A B C
curr
• For deletion:
– The next pointer of the item immediately
preceding the one to be deleted is altered, and
made to point to the item following the deleted
item.
item.
Spring 2012 Programming and Data Structure 12
Pseudo-code for deletion
public static Node deletionAtFirst(Node
head)
{
head = head.next;
Spring 2012 Programming and Data Structure 13
head = head.next;
return head;
}
Types of Lists
• Depending on the way in which the links are
used to maintain adjacency, several different
types of linked lists are possible.
– Linear singly-linked list (or simply linear list)
• One we have discussed so far.
Spring 2012 Programming and Data Structure 14
A B C
head
– Circular linked list
• The pointer from the last element in the list points back
to the first element.
head
Spring 2012 Programming and Data Structure 15
A B C
– Doubly linked list
• Pointers exist between adjacent nodes in both
directions.
• The list can be traversed either forward or backward.
• Usually two pointers are maintained to keep track of
• Usually two pointers are maintained to keep track of
the list, head and tail.
Spring 2012 Programming and Data Structure 16
A B C
head tail
Spring 2012 Programming and Data Structure 17

More Related Content

Similar to linklked lisdi.pdf

Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
FaheemMahmood2
 
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
 

Similar to linklked lisdi.pdf (20)

linkedlist (1).ppt
linkedlist (1).pptlinkedlist (1).ppt
linkedlist (1).ppt
 
linked list
linked listlinked list
linked list
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
 
Data structure
 Data structure Data structure
Data structure
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
 
Linked list
Linked listLinked list
Linked list
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
linked.ppt
linked.pptlinked.ppt
linked.ppt
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
module 3-.pptx
module 3-.pptxmodule 3-.pptx
module 3-.pptx
 
Unit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfUnit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdf
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
 
Linked list (1).pptx
Linked list (1).pptxLinked list (1).pptx
Linked list (1).pptx
 
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
linked list linked list
linked list
 
Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture Notes
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

linklked lisdi.pdf

  • 1. StudentName : Vinay Kamriya StudentName : Vinay Kamriya Year/Branch : 3rd year (CS) Topic : Linked List
  • 2. Table of content • Introduction • Keeping track of linked list • Basic operations – Traversing – Insertion – Insertion – Deletion • Types of linked list – Singly linked list – Circular linked list – Doubly linked list Spring 2012 Programming and Data Structure 2
  • 3. Introduction • A linked list is a data structure which can change during execution. – Successive elements are connected by pointers. – Last element points to NULL. – It can grow or shrink in size during execution of a – It can grow or shrink in size during execution of a program. – It can be made just as long as required. – It does not waste memory space. Spring 2012 Programming and Data Structure 3 A B C head
  • 4. • Keeping track of a linked list: – Must know the pointer to the first element of the list (called start, head, etc.). • Linked lists provide flexibility in allowing the items to be rearranged efficiently. items to be rearranged efficiently. – Insert an element. – Delete an element. Spring 2012 Programming and Data Structure 4
  • 5. Basic Operations on a List • Traversing the list • Inserting an item in the list • Deleting an item from the list • Deleting an item from the list Spring 2012 Programming and Data Structure 5
  • 6. Traversing a linked list Spring 2012 Programming and Data Structure 6 Time complexcity of traversing an linkedlist - O(n)
  • 7. Pseudo-code for traversal public static void traversal(Node head) { while(head!=null) { { System.out.print(head.data + " "); head = head.next; } } Spring 2012 Programming and Data Structure 7
  • 8. Illustration: Insertion Item to be inserted X A B C tmp Spring 2012 Programming and Data Structure 8 A A X B C curr
  • 9. •For insertion: –A record is created holding the new item. –The next pointer of the new record is set to link it to the item which is to follow it in the list. Spring 2012 Programming and Data Structure 9 follow it in the list. –The next pointer of the item which is to precede it must be modified to point to the new item.
  • 10. Pseudo-code for insertion public static Node insertAtFirst(Node head , int data) { Node newNode = new Node(data); newNode.next = head; return newNode; Spring 2012 Programming and Data Structure 10 return newNode; }
  • 11. Illustration: Deletion A B C Item to be deleted curr tmp Spring 2012 Programming and Data Structure 11 A B C curr
  • 12. • For deletion: – The next pointer of the item immediately preceding the one to be deleted is altered, and made to point to the item following the deleted item. item. Spring 2012 Programming and Data Structure 12
  • 13. Pseudo-code for deletion public static Node deletionAtFirst(Node head) { head = head.next; Spring 2012 Programming and Data Structure 13 head = head.next; return head; }
  • 14. Types of Lists • Depending on the way in which the links are used to maintain adjacency, several different types of linked lists are possible. – Linear singly-linked list (or simply linear list) • One we have discussed so far. Spring 2012 Programming and Data Structure 14 A B C head
  • 15. – Circular linked list • The pointer from the last element in the list points back to the first element. head Spring 2012 Programming and Data Structure 15 A B C
  • 16. – Doubly linked list • Pointers exist between adjacent nodes in both directions. • The list can be traversed either forward or backward. • Usually two pointers are maintained to keep track of • Usually two pointers are maintained to keep track of the list, head and tail. Spring 2012 Programming and Data Structure 16 A B C head tail
  • 17. Spring 2012 Programming and Data Structure 17