SlideShare a Scribd company logo
Introduction: memory representation, allocation
and garbage collection.
Operations: Traversal, insertion and deletion.
Header linked lists: Grounded and Circular
Two-way lists: operations on two way linked lists
Introduction
Linked list
Linear collection of self-referential class objects, called
nodes
Connected by pointer links
Accessed via a pointer to the first node of the list
Link pointer in the last node is set to null to mark the
list’s end
Use a linked list instead of an array when
You have an unpredictable number of data elements
You want to insert and delete quickly.
Self-Referential Structures
Self-referential structures
 Structure that contains a pointer to a structure of the same type
 Can be linked together to form useful data structures such as lists, queues,
stacks and trees
 Terminated with a NULL pointer (0)
Diagram of two self-referential structure objects linked together
struct node {
int data;
struct node *nextPtr;
};
nextPtr
Points to an object of type node
Referred to as a link
100
NULL pointer (points to nothing)Data member and pointer
500…
3 2
Linked Lists
Types of linked lists:
Singly linked list
 Begins with a pointer to the first node
 Terminates with a null pointer
 Only traversed in one direction
Circular, singly linked
 Pointer in the last node points
back to the first node
Doubly linked list
 Two “start pointers” – first element and last element
 Each node has a forward pointer and a backward pointer
 Allows traversals both forwards and backwards
Circular, doubly linked list
 Forward pointer of the last node points to the first node and
backward pointer of the first node points to the last node
Linked Representation of Data
In a linked representation, data is
not stored in a contiguous
manner. Instead, data is stored at
random locations and the current
data location provides the
information regarding the
location of the next data.
Adding item 498 on to the linked list
Q: What is the cost of adding an item?
Q: how about adding 300 and 800
onto the linked list
Deleting item 358 from the linked list
Q: What is the cost of deleting an item?
Q: What is the cost of searching for an
item?
345
358
490
501
513
724
797
701
561
555
345
358
490
501
513
724
797
701
561
555
498
345
358
490
501
513
724
797
701
561
555
498
Linked List
How do we represent a linked list in the memory
Each location has two fields: Data Field and Pointer (Link)
Field.
Linked List Implementation
 struct node {
int data;
struct node *link;
};
struct node my_node;
Example:
START Node
Element
Pointer (Link)
Field
Data
Field
Null Pointer
300 5
500 0
100 4
200 1
400 2
1
2
3
4
5
3
NULL
Conventions of Linked List
There are several conventions for the link to indicate
the end of the list.
1. a null link that points to no node (0 or NULL)
2. a dummy node that contains no item
3. a reference back to the first node, making it a
circular list.
bat  cat  sat  vat NULL
Linked List Manipulation Algorithms
 List Traversal
 Let START be a pointer to a linked list in memory. Write an
algorithm to print the contents of each node of the list
 Algorithm:
 TRAVERSE(DATA, LINK, START)
1. set PTR = START
2. repeat step 3 and 4 while PTR ≠ NULL
3. print PTR->DATA
4. set PTR = PTR -> LINK
5. stop
1000
START
2000 3000 4000
PTR
PTR = LINK[PTR]
10 20 30 40
10 20 30 40 00
Data Link
Search for an Item
 Search for an ITEM
 Let START be a pointer to a linked list in memory. Write an
algorithm that finds the location LOC of the node where ITEM first
appears in the list, or sets LOC=NULL if search is unsuccessful.
 Algorithm:
SEARCH (DATA, LINK, START, ITEM, LOC)
1. set PTR = START
2. repeat step 3 while PTR ≠ NULL
3. if ITEM == PTR -> DATA, then
4. set LOC = PTR, and Exit
5. else
6. set PTR = PTR -> LINK
7. set LOC = NULL /*search unsuccessful */
8. Stop
1000
START
2000 3000 4000
PTR
PTR = LINK[PTR]
Insert an Item
 Insertion into a Listed List
 Let START be a pointer to a linked list in memory with
successive nodes A and B. Write an algorithm to insert node N
between nodes A and B.
 Algorithm:
 INSERT(DATA, LINK, START, A, B, N)
1. Set PTR = START
2. Repeat step 3 while PTR ≠ NULL
3. If PTR == A, then
4. Set N->LINK = PTR -> LINK (or = B)
5. Set PTR->LINK = N
6. exit
7. else
8. Set PTR=PTR->LINK
9. If PTR == NULL insertion unsuccessful
10. Stop
START
1000 2000 3000 4000 5000
Node A Node B
PTR
START
1000 2000 3000 4000 5000
Node A Node B
3500
Node N
3 cases: first node, last node, in-between node. (ex: if ITEM = 500? if ITEM = 6000?)
Delete an Item
 Deletion from a Linked List
 Let START be a pointer to a linked list in memory that contains integer data.
Write an algorithm to delete note which contains ITEM.
 Algorithm
 DELETE (DATA, LINK, START, ITEM)
1. Set PTR=START and TEMP = START
2. Repeat step 3 while PTR ≠ NULL
3. If PTR->DATA == ITEM, then
4. Set TEMP->LINK = PTR -> LINK, exit
5. else
6. TEMP = PTR
7. PTR = PTR -> LINK
8. Stop
3 cases: first node, last node, in-between node. (ex: if ITEM = 1000? if ITEM = 5000?)
PTR
START
1000 2000 3000 4000 5000
Node A Node B
3500
Node N
START
1000 2000 3000 4000 5000
Node A Node B
3500
Node N
3500
ITEM
…..
TEMP
Header Linked Lists
 Header linked list is a linked list which always contains a
special node called the Header Node, at the beginning of
the list.
It has two types:
a) Grounded Header List
Last Node Contains the NULL Pointer
b) Circular Header List
Last Node Points Back to the Header Node
13
Header linked list
Grounded Header linked list Circular Header linked list
Grounded Header Link List
A grounded header list is a header list where the last
node contains the null pointer.
The term “grounded” comes from the fact that many
texts use the electrical ground symbol to indicate the
null pointer.
Header Node
Start
Figure: Grounded Header Link List
Circular Header Linked List
A circular header Link list is a header list where the last
node points back to the header node.
The chains do not indicate the last node and first node of
the link list.
In this case, external pointers provide a frame reference
because last node of a circular link list does not contain
null pointer.
Header Node
Figure: Circular Header Link List
Start
Benefit of using Header Node
One way to simplify insertion and deletion is never to
insert an item before the first or after the last item and
never to delete the first node
You can set a header node at the beginning of the list
containing a value smaller than the smallest value in the
data set
You can set a trailer node at the end of the list containing
a value larger than the largest value in the data set.
These two nodes, header and trailer, serve merely to
simplify the insertion and deletion algorithms and are not
part of the actual list.
The actual list is between these two nodes.
Two-way lists
A two-way list is a linear collection of data elements,
called nodes, where each node N is divided into three
parts:
Information field
Forward Link which points to the next node
Backward Link which points to the previous node
The starting address or the address of first node is
stored in START / FIRST pointer .
Another pointer can be used to traverse list from end.
This pointer is called END or LAST.
Two-way lists(cont…)
Every node (except the last node) contains the
address of the next node, and every node (except
the first node) contains the address of the
previous node.
A two-way list (doubly linked list) can be
traversed in either direction.
Representations of
Two-way lists
Start
X 4 2 10
Last
INFO Field
BACK Pointer
FORE Pointer
X
Thank You
Ad

More Related Content

What's hot (20)

Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
single linked list
single linked listsingle linked list
single linked list
Sathasivam Rangasamy
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
Ashish Arun
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
RacksaviR
 
Sorting
SortingSorting
Sorting
Ashim Lamichhane
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
Tirthika Bandi
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Linked list
Linked listLinked list
Linked list
eShikshak
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
Then Murugeshwari
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
Vardhil Patel
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
junnubabu
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
RacksaviR
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
Tirthika Bandi
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
Vardhil Patel
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
junnubabu
 

Similar to Data Structure and Algorithms Linked List (20)

Engineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notesEngineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
Chandan Singh
 
linked list in dsa python (presentation)
linked list in dsa python (presentation)linked list in dsa python (presentation)
linked list in dsa python (presentation)
MirzaAbdullahTariq
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
Aakash deep Singhal
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notes
Dreamers6
 
Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
naymulhaque
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
JITTAYASHWANTHREDDY
 
linked list1.ppt linked list ppts and notes
linked list1.ppt linked list ppts and noteslinked list1.ppt linked list ppts and notes
linked list1.ppt linked list ppts and notes
nisharaheja1986
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
Axmedcarb
 
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
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
PranavMakwana6
 
unit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdfunit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdf
soniasharmafdp
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptxDSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
nikhilcse1
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna
 
Engineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notesEngineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
Chandan Singh
 
linked list in dsa python (presentation)
linked list in dsa python (presentation)linked list in dsa python (presentation)
linked list in dsa python (presentation)
MirzaAbdullahTariq
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
Aakash deep Singhal
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notes
Dreamers6
 
linked list1.ppt linked list ppts and notes
linked list1.ppt linked list ppts and noteslinked list1.ppt linked list ppts and notes
linked list1.ppt linked list ppts and notes
nisharaheja1986
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
Axmedcarb
 
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
 
unit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdfunit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdf
soniasharmafdp
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptxDSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
nikhilcse1
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna
 
Ad

More from ManishPrajapati78 (15)

Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
ManishPrajapati78
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
ManishPrajapati78
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
ManishPrajapati78
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Data Structure and Algorithms Sorting
Data Structure and Algorithms SortingData Structure and Algorithms Sorting
Data Structure and Algorithms Sorting
ManishPrajapati78
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Data Structure and Algorithms Graphs
Data Structure and Algorithms GraphsData Structure and Algorithms Graphs
Data Structure and Algorithms Graphs
ManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
ManishPrajapati78
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
ManishPrajapati78
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
ManishPrajapati78
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Data Structure and Algorithms Sorting
Data Structure and Algorithms SortingData Structure and Algorithms Sorting
Data Structure and Algorithms Sorting
ManishPrajapati78
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Data Structure and Algorithms Graphs
Data Structure and Algorithms GraphsData Structure and Algorithms Graphs
Data Structure and Algorithms Graphs
ManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Ad

Recently uploaded (20)

Microsoft Excel Core Points Training.pptx
Microsoft Excel Core Points Training.pptxMicrosoft Excel Core Points Training.pptx
Microsoft Excel Core Points Training.pptx
Mekonnen
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025
younisnoman75
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Top 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdfTop 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdf
AffinityCore
 
Microsoft Excel Core Points Training.pptx
Microsoft Excel Core Points Training.pptxMicrosoft Excel Core Points Training.pptx
Microsoft Excel Core Points Training.pptx
Mekonnen
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025
younisnoman75
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Top 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdfTop 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdf
AffinityCore
 

Data Structure and Algorithms Linked List

  • 1. Introduction: memory representation, allocation and garbage collection. Operations: Traversal, insertion and deletion. Header linked lists: Grounded and Circular Two-way lists: operations on two way linked lists
  • 2. Introduction Linked list Linear collection of self-referential class objects, called nodes Connected by pointer links Accessed via a pointer to the first node of the list Link pointer in the last node is set to null to mark the list’s end Use a linked list instead of an array when You have an unpredictable number of data elements You want to insert and delete quickly.
  • 3. Self-Referential Structures Self-referential structures  Structure that contains a pointer to a structure of the same type  Can be linked together to form useful data structures such as lists, queues, stacks and trees  Terminated with a NULL pointer (0) Diagram of two self-referential structure objects linked together struct node { int data; struct node *nextPtr; }; nextPtr Points to an object of type node Referred to as a link 100 NULL pointer (points to nothing)Data member and pointer 500… 3 2
  • 4. Linked Lists Types of linked lists: Singly linked list  Begins with a pointer to the first node  Terminates with a null pointer  Only traversed in one direction Circular, singly linked  Pointer in the last node points back to the first node Doubly linked list  Two “start pointers” – first element and last element  Each node has a forward pointer and a backward pointer  Allows traversals both forwards and backwards Circular, doubly linked list  Forward pointer of the last node points to the first node and backward pointer of the first node points to the last node
  • 5. Linked Representation of Data In a linked representation, data is not stored in a contiguous manner. Instead, data is stored at random locations and the current data location provides the information regarding the location of the next data. Adding item 498 on to the linked list Q: What is the cost of adding an item? Q: how about adding 300 and 800 onto the linked list Deleting item 358 from the linked list Q: What is the cost of deleting an item? Q: What is the cost of searching for an item? 345 358 490 501 513 724 797 701 561 555 345 358 490 501 513 724 797 701 561 555 498 345 358 490 501 513 724 797 701 561 555 498
  • 6. Linked List How do we represent a linked list in the memory Each location has two fields: Data Field and Pointer (Link) Field. Linked List Implementation  struct node { int data; struct node *link; }; struct node my_node; Example: START Node Element Pointer (Link) Field Data Field Null Pointer 300 5 500 0 100 4 200 1 400 2 1 2 3 4 5 3 NULL
  • 7. Conventions of Linked List There are several conventions for the link to indicate the end of the list. 1. a null link that points to no node (0 or NULL) 2. a dummy node that contains no item 3. a reference back to the first node, making it a circular list.
  • 8. bat  cat  sat  vat NULL
  • 9. Linked List Manipulation Algorithms  List Traversal  Let START be a pointer to a linked list in memory. Write an algorithm to print the contents of each node of the list  Algorithm:  TRAVERSE(DATA, LINK, START) 1. set PTR = START 2. repeat step 3 and 4 while PTR ≠ NULL 3. print PTR->DATA 4. set PTR = PTR -> LINK 5. stop 1000 START 2000 3000 4000 PTR PTR = LINK[PTR] 10 20 30 40 10 20 30 40 00 Data Link
  • 10. Search for an Item  Search for an ITEM  Let START be a pointer to a linked list in memory. Write an algorithm that finds the location LOC of the node where ITEM first appears in the list, or sets LOC=NULL if search is unsuccessful.  Algorithm: SEARCH (DATA, LINK, START, ITEM, LOC) 1. set PTR = START 2. repeat step 3 while PTR ≠ NULL 3. if ITEM == PTR -> DATA, then 4. set LOC = PTR, and Exit 5. else 6. set PTR = PTR -> LINK 7. set LOC = NULL /*search unsuccessful */ 8. Stop 1000 START 2000 3000 4000 PTR PTR = LINK[PTR]
  • 11. Insert an Item  Insertion into a Listed List  Let START be a pointer to a linked list in memory with successive nodes A and B. Write an algorithm to insert node N between nodes A and B.  Algorithm:  INSERT(DATA, LINK, START, A, B, N) 1. Set PTR = START 2. Repeat step 3 while PTR ≠ NULL 3. If PTR == A, then 4. Set N->LINK = PTR -> LINK (or = B) 5. Set PTR->LINK = N 6. exit 7. else 8. Set PTR=PTR->LINK 9. If PTR == NULL insertion unsuccessful 10. Stop START 1000 2000 3000 4000 5000 Node A Node B PTR START 1000 2000 3000 4000 5000 Node A Node B 3500 Node N 3 cases: first node, last node, in-between node. (ex: if ITEM = 500? if ITEM = 6000?)
  • 12. Delete an Item  Deletion from a Linked List  Let START be a pointer to a linked list in memory that contains integer data. Write an algorithm to delete note which contains ITEM.  Algorithm  DELETE (DATA, LINK, START, ITEM) 1. Set PTR=START and TEMP = START 2. Repeat step 3 while PTR ≠ NULL 3. If PTR->DATA == ITEM, then 4. Set TEMP->LINK = PTR -> LINK, exit 5. else 6. TEMP = PTR 7. PTR = PTR -> LINK 8. Stop 3 cases: first node, last node, in-between node. (ex: if ITEM = 1000? if ITEM = 5000?) PTR START 1000 2000 3000 4000 5000 Node A Node B 3500 Node N START 1000 2000 3000 4000 5000 Node A Node B 3500 Node N 3500 ITEM ….. TEMP
  • 13. Header Linked Lists  Header linked list is a linked list which always contains a special node called the Header Node, at the beginning of the list. It has two types: a) Grounded Header List Last Node Contains the NULL Pointer b) Circular Header List Last Node Points Back to the Header Node 13 Header linked list Grounded Header linked list Circular Header linked list
  • 14. Grounded Header Link List A grounded header list is a header list where the last node contains the null pointer. The term “grounded” comes from the fact that many texts use the electrical ground symbol to indicate the null pointer. Header Node Start Figure: Grounded Header Link List
  • 15. Circular Header Linked List A circular header Link list is a header list where the last node points back to the header node. The chains do not indicate the last node and first node of the link list. In this case, external pointers provide a frame reference because last node of a circular link list does not contain null pointer. Header Node Figure: Circular Header Link List Start
  • 16. Benefit of using Header Node One way to simplify insertion and deletion is never to insert an item before the first or after the last item and never to delete the first node You can set a header node at the beginning of the list containing a value smaller than the smallest value in the data set You can set a trailer node at the end of the list containing a value larger than the largest value in the data set. These two nodes, header and trailer, serve merely to simplify the insertion and deletion algorithms and are not part of the actual list. The actual list is between these two nodes.
  • 17. Two-way lists A two-way list is a linear collection of data elements, called nodes, where each node N is divided into three parts: Information field Forward Link which points to the next node Backward Link which points to the previous node The starting address or the address of first node is stored in START / FIRST pointer . Another pointer can be used to traverse list from end. This pointer is called END or LAST.
  • 18. Two-way lists(cont…) Every node (except the last node) contains the address of the next node, and every node (except the first node) contains the address of the previous node. A two-way list (doubly linked list) can be traversed in either direction.
  • 19. Representations of Two-way lists Start X 4 2 10 Last INFO Field BACK Pointer FORE Pointer X