SlideShare a Scribd company logo
1 of 46
Singly &
Circular
Linked List
Presented by
Md. Zabirul Islam
Md. Sharzul Mostafa
Manon Rahman
Aparajita Dola and
Shahriar Parvej
Department of CSE, KUET
Outlines
 Introduction
 Advantage of a Link List over Array
 Link List Declaration
 Basic Link List Operation
 Circular Link List
 Application
 Disadvantage
Computer Science & Engineering , KUET 01/43
Introduction
What Is Linked List?
 The most commonly used data structure to store data in memory.
 A linear collection of data elements, called nodes.
 Unlike arrays, linked list elements are not stored at adjacent location.
 The nodes connect by pointers.
Computer Science & Engineering , KUET 02/43
What’s wrong with Array and Why linked lists?
 Insertions and deletions are simple and faster.
 Linked list is able to grow in size.
 Linked List reduces the access time.
 No wastage of memory.
Computer Science & Engineering , KUET 03/43
 Disadvantages of arrays as storage data structures:
Linked lists solve some of these problems :
Insertion and deletion operations are slow.
Slow searching in unordered array.
Wastage of memory.
Fixed size.
Singly Linked List
Singly linked list is a collection of nodes.
Each node contains two parts.
 The data contains elements .
 Link contains address of next node .
data link
Computer Science & Engineering , KUET 04/43
Node
Structure of singly linked list
linkdata
A B C
linklink datadata
head
 The head always points to the first node .
 All nodes are connected to each other through Link fields.
 Null pointer indicated end of the list.
Computer Science & Engineering , KUET 05/43
X
Circular linked list
A circular linked list is one which has
 No ending.
 The null pointer in the last node of a linked list is replaced with the
address of its first node .
Computer Science & Engineering , KUET 06/43
Structure of circular linked list
CIRCULAR LINKED LIST:-
4000 1000 2000
B 2000 C 4000A 1000
Computer Science & Engineering , KUET 07/43
Operations on linked list
The basic operations on linked lists are :
1. Creation
2. Insertion
3. Deletion
4. Traversing
5. Searching
Computer Science & Engineering , KUET 08/43
The creation operation is used to create a linked list.
Declare Node struct for nodes.
 Data - any type
 Link - a pointer to the next node.
Struct node{
int data;
Struct node *link;
}
Computer Science & Engineering , KUET 09/43
What Is creation
 Allocate a new node
 Insert new element
 Make new node point to null
 Create head to point to new node
Algorithm
 create a new node
 new->data=item
 new->link=NULL
 head=new
What Is creation
Computer Science & Engineering , KUET 10/43
Creation
 new->data=item
 new->link=NULL
 head=new
Computer Science & Engineering , KUET 11/43
X
head
New Node
A
What Is Insertion
Insertion operation is used to insert a new node in the
linked list at the specified position.
When the list itself is empty , the new node is inserted
as a first node.
Computer Science & Engineering , KUET 12/43
Types of Insertion
There are many ways to insert a new node
into a list :
 As the new first element.
 As the new last element.
 Before a given value.
 After a given value.
Computer Science & Engineering , KUET 13/43
Inserting at the beginng
 Allocate a new node
 Insert new element
 Make new nodetopoint to old head
 Update head topoint to new node
Algorithm
 create a new node
 new->data=item
 new->link=head
 head=new
Computer Science & Engineering , KUET 14/43
Inserting at the beginning
X
linklink datadata
head
New Node
B C
A
Computer Science & Engineering , KUET 15/43
 new->link=head
 head=new
Inserting at the last
 Allocate a new node
 Insert new element
 Searching the last node
 Have old last node point to new node
 Update new node that point to null
 create a new node
 new->data=item
 ptr=head while(ptr->link!=null) ptr=ptr>link
 ptr->link=new
 new->link=NULL
Computer Science & Engineering , KUET 16/43
Algorithm
Inserting at the last
B C
linklink datadata
A
X
New Node
Computer Science & Engineering , KUET 17/43
head
ptr->link=new
new->link=NULL
Inserting before given a value
 Allocate a new node
 Insert new element
 Searching the given node
 Store the previous node
 Update new to point to previous node link
 Update previous node to point to new
node
 create a new node
 new->data=item
 ptr=head while(ptr->info!=data) temp=ptr
ptr=ptr>link
 new->link=temp->link
 temp->link=new
Computer Science & Engineering , KUET 18/43
 Algorithm
Inserting before given a value
linkdata
A
X
B
linklink datadata
head
New Node
D
Computer Science & Engineering , KUET 19/43
C
temp ptr
new->link=temp->link
temp->link=new
Inserting after given a value
 Allocate a new node, new
 Insert new element
 Searching the node
 Update new to point to the link of the
given node
 Update given node to point to new
node
 create a new node
 new->data=item
 ptr=headwhile(ptr->info!=data) ptr=ptr>link
 new->link=ptr->link
 ptr->link=new
 Algorithm
Computer Science & Engineering , KUET 20/43
 Algorithm
Inserting after given a value
linkdata
A
X
B
linklink datadata
New Node
D
Computer Science & Engineering , KUET 21/43
C
ptr
head
new->link=ptr->link
ptr->link=new
What Is Deletion?
Deletion operation is used to delete a particular node in
the linked list.
we simply have to perform operation on the link of the
nodes(which contains the address of the next node) to
delete a particular element.
Computer Science & Engineering , KUET 22/43
Types of Deletion
Deletion operation may be performed in
the following conditions:
 Delete first element.
 Delete last element.
 Delete before a given value.
 Delete after a given value.
 Delete a particular element
Computer Science & Engineering , KUET 23/43
Deleting the first node
 Declare anode
 Assignheadtothenewnode
 Update head with thelinkof the
new node
Algorithm
 srt=head
 head=srt->link
Computer Science & Engineering , KUET 24/43
Deleting the first node
X
linklink datadata
head
data link
B CA
Computer Science & Engineering , KUET 25/43
 srt=head
 head=srt->link
srt
Deleting the last node
 Declare nodessrt,temp
 Traversethelistandupdate temp
withthevalueofsrt
 IfthelinkofsrtisNULL,updatethelink
oftempwithNULLandbreaktheloop
Algorithm
declare srt, temp
for(srt=head;;temp=srt,
srt=srt->link)
if(srt->link==NULL)temp-
>link=NULL;Exit;
Computer Science & Engineering , KUET 26/43
Deleting the last node
X
linklink datadata
head
data link
B CA
Computer Science & Engineering , KUET 27/43
X
Deleting after a given value
 Declare a node srt
 Search the element to delete after
 Update link of the node with the link of the
next node
 Node *srt
 srt=head while(srt->info!=data) srt=srt>link
 srt->link=srt->link->link
 ptr->link=new
 Algorithm
Computer Science & Engineering , KUET 28/43
 Algorithm
Deleting after a given value
linkdata
A
X
B
linklink datadata
C
Computer Science & Engineering , KUET 29/43
srt
head
C
Deleting before a given value
 Declare nodes srt, temp and prev
 Search the element to delete before
 Update link of the previous node with the
link of the next node
 Node *srt, *temp, *prev
 srt=head while(srt->info!=data) srt=srt>link
 prev = temp; temp = srt;
 Prev->link = srt
 Algorithm
Computer Science & Engineering , KUET 30/43
 Algorithm
Deleting before a given value
linkdata
A B
linklink datadata
C
Computer Science & Engineering , KUET 31/43
prev
head
X
D
linkdata
temp srt
Deleting a given value
 Declare nodes srt and temp
 Search the element to delete
 Update link of the previous node with
the link of the selected node
 Node *srt, *temp
 Srt=head while(srt->info!=data) srt=srt->link
 temp = srt;
 temp->link = srt->link
 Algorithm
Computer Science & Engineering , KUET 32/43
 Algorithm
Deleting after a given value
linkdata
A B
linklink datadata
C
Computer Science & Engineering , KUET 33/43
head
X
D
linkdata
temp srt
Operations on a singly circular linked list
 The basic operations on singly circular linked lists are :
1. Creation
2. Insertion
3. Deletion
4. Traversing
5. Searching
Computer Science & Engineering , KUET 34/43
Operations on a singly circular linked list
 Creation of a circular linked list is same as singly list except that we will have to
use head instead of NULL
 To traverse the list we have to start from head and end until the link of a node is
head
 To insert a node at the beginning of the list we have to store the value of head
in a temporary node and operate accordingly
Computer Science & Engineering , KUET 35/43
The operations on a singly circular linked is almost same as that of a singly
linked list. The only difference between them is that the link of the last node of
a singly linked list contains NULL, whereas that of a circular list contains head
Operations on a singly circular linked list
 The operation insert last, is almost the same as that of the singly list, difference: head
instead of NULL in the link of new node
 The operation insert after, is same as that of the singly list. If the node is the last node
then we can perform the operation just by calling the insert last’s function
 The operation insert before, is same as that of the singly list
 The operation delete after and before, is same as that of the singly list. Deleting last
element is also almost the same, only have to update the link of previous node with
head. But the process of deleting the first element is different, it’ll be discussed in this
presentation
 The operation delete element, is same as that of the singly list
Computer Science & Engineering , KUET 36/43
Operations on a singly circular linked list
 Mostoftheoperationsarealmostthesameassinglylinkedlistincaseofasingly
circularlinkedlist, onlyalittlevariationinlistcreationanddeletingthefirstelement,
nextcontentscontaintheseoperations!
Computer Science & Engineering , KUET 37/43
 Allocate a new node
 Insert new element
 Make new node point to head
 Update head to point to new nodeoffirst
element
 Ifnotfirstelementupdatelinkofprevious
elementwithcurrentnodeaddress
Algorithm
 create a new node
 new->data=item
 new->link=head
 head=new, temp=new, if
head==NULL
 else temp->link=new,
temp=ptr
Creation of a circular list
Computer Science & Engineering , KUET 38/43
Creation
head
New Node
A
Computer Science & Engineering , KUET 39/43
headhead
B
New Node
 new->data=item
 new->link=head
Deleting the first node
 Declare anewnode,srt
 Assignheadtothenewnode
 Update head with thelinkof thenew
node
 Update thelinkoflastnode with thelink
of thenew node
Algorithm
 srt=head
 head=srt->link
 last->link=head
Computer Science & Engineering , KUET 40/43
Deleting the first node
head
linklink datadata
head
data link
B CA
Computer Science & Engineering , KUET 41/43
last
 head=srt->link
 last->link=head
Application
Linked lists are used in many other data structures.
Linked lists are used in polynomial manipulation.
Representation of trees, stacks, queues. etc.
Computer Science & Engineering , KUET 42/43
Disadvantages of Linked Lists
 The memory is wasted as pointers require extra memory for storage.
 No element can be accessed randomly.
 It has to access each node sequentially.
 Reverse Traversing is difficult in linked list.
 No binary search.
Computer Science & Engineering , KUET 43/43
Questions? 
Thank you 

More Related Content

What's hot

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 TutorialAfzal Badshah
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSAjunnubabu
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | EdurekaEdureka!
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)Huba Akhtar
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Treesagar yadav
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structureTushar Aneyrao
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queueRojan Pariyar
 
Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)pushpalathakrishnan
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked ListReazul Islam
 

What's hot (20)

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
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
 
Linklist
LinklistLinklist
Linklist
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
 
Linked lists
Linked listsLinked lists
Linked lists
 
Linked list
Linked listLinked list
Linked list
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Er diagram
Er diagramEr diagram
Er diagram
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)
 
List in Python
List in PythonList in Python
List in Python
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Linked list
Linked listLinked list
Linked list
 

Similar to Singly & Circular Linked list

Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked ListsAfaq Mansoor Khan
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked ListThenmozhiK5
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)Durga Devi
 
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxSIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxedgar6wallace88877
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUEDev Chauhan
 
Unit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfUnit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfKanchanPatil34
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Balwant Gorad
 
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 LISTbinakasehun2026
 

Similar to Singly & Circular Linked list (20)

linkedlist (1).ppt
linkedlist (1).pptlinkedlist (1).ppt
linkedlist (1).ppt
 
Link list
Link listLink list
Link list
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Linked List
Linked ListLinked List
Linked List
 
Team 10
Team 10Team 10
Team 10
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Linked Lists.pdf
Linked Lists.pdfLinked Lists.pdf
Linked Lists.pdf
 
module 3-.pptx
module 3-.pptxmodule 3-.pptx
module 3-.pptx
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
 
DSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdfDSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdf
 
L3
L3L3
L3
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
 
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxSIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
 
Unit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfUnit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdf
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
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
 

Recently uploaded

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
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
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
 
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
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
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
 
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
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
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
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 

Recently uploaded (20)

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
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
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
 
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
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
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
 
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 )
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
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
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
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
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
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
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 

Singly & Circular Linked list

  • 1. Singly & Circular Linked List Presented by Md. Zabirul Islam Md. Sharzul Mostafa Manon Rahman Aparajita Dola and Shahriar Parvej Department of CSE, KUET
  • 2. Outlines  Introduction  Advantage of a Link List over Array  Link List Declaration  Basic Link List Operation  Circular Link List  Application  Disadvantage Computer Science & Engineering , KUET 01/43
  • 3. Introduction What Is Linked List?  The most commonly used data structure to store data in memory.  A linear collection of data elements, called nodes.  Unlike arrays, linked list elements are not stored at adjacent location.  The nodes connect by pointers. Computer Science & Engineering , KUET 02/43
  • 4. What’s wrong with Array and Why linked lists?  Insertions and deletions are simple and faster.  Linked list is able to grow in size.  Linked List reduces the access time.  No wastage of memory. Computer Science & Engineering , KUET 03/43  Disadvantages of arrays as storage data structures: Linked lists solve some of these problems : Insertion and deletion operations are slow. Slow searching in unordered array. Wastage of memory. Fixed size.
  • 5. Singly Linked List Singly linked list is a collection of nodes. Each node contains two parts.  The data contains elements .  Link contains address of next node . data link Computer Science & Engineering , KUET 04/43 Node
  • 6. Structure of singly linked list linkdata A B C linklink datadata head  The head always points to the first node .  All nodes are connected to each other through Link fields.  Null pointer indicated end of the list. Computer Science & Engineering , KUET 05/43 X
  • 7. Circular linked list A circular linked list is one which has  No ending.  The null pointer in the last node of a linked list is replaced with the address of its first node . Computer Science & Engineering , KUET 06/43
  • 8. Structure of circular linked list CIRCULAR LINKED LIST:- 4000 1000 2000 B 2000 C 4000A 1000 Computer Science & Engineering , KUET 07/43
  • 9. Operations on linked list The basic operations on linked lists are : 1. Creation 2. Insertion 3. Deletion 4. Traversing 5. Searching Computer Science & Engineering , KUET 08/43
  • 10. The creation operation is used to create a linked list. Declare Node struct for nodes.  Data - any type  Link - a pointer to the next node. Struct node{ int data; Struct node *link; } Computer Science & Engineering , KUET 09/43 What Is creation
  • 11.  Allocate a new node  Insert new element  Make new node point to null  Create head to point to new node Algorithm  create a new node  new->data=item  new->link=NULL  head=new What Is creation Computer Science & Engineering , KUET 10/43
  • 12. Creation  new->data=item  new->link=NULL  head=new Computer Science & Engineering , KUET 11/43 X head New Node A
  • 13. What Is Insertion Insertion operation is used to insert a new node in the linked list at the specified position. When the list itself is empty , the new node is inserted as a first node. Computer Science & Engineering , KUET 12/43
  • 14. Types of Insertion There are many ways to insert a new node into a list :  As the new first element.  As the new last element.  Before a given value.  After a given value. Computer Science & Engineering , KUET 13/43
  • 15. Inserting at the beginng  Allocate a new node  Insert new element  Make new nodetopoint to old head  Update head topoint to new node Algorithm  create a new node  new->data=item  new->link=head  head=new Computer Science & Engineering , KUET 14/43
  • 16. Inserting at the beginning X linklink datadata head New Node B C A Computer Science & Engineering , KUET 15/43  new->link=head  head=new
  • 17. Inserting at the last  Allocate a new node  Insert new element  Searching the last node  Have old last node point to new node  Update new node that point to null  create a new node  new->data=item  ptr=head while(ptr->link!=null) ptr=ptr>link  ptr->link=new  new->link=NULL Computer Science & Engineering , KUET 16/43 Algorithm
  • 18. Inserting at the last B C linklink datadata A X New Node Computer Science & Engineering , KUET 17/43 head ptr->link=new new->link=NULL
  • 19. Inserting before given a value  Allocate a new node  Insert new element  Searching the given node  Store the previous node  Update new to point to previous node link  Update previous node to point to new node  create a new node  new->data=item  ptr=head while(ptr->info!=data) temp=ptr ptr=ptr>link  new->link=temp->link  temp->link=new Computer Science & Engineering , KUET 18/43  Algorithm
  • 20. Inserting before given a value linkdata A X B linklink datadata head New Node D Computer Science & Engineering , KUET 19/43 C temp ptr new->link=temp->link temp->link=new
  • 21. Inserting after given a value  Allocate a new node, new  Insert new element  Searching the node  Update new to point to the link of the given node  Update given node to point to new node  create a new node  new->data=item  ptr=headwhile(ptr->info!=data) ptr=ptr>link  new->link=ptr->link  ptr->link=new  Algorithm Computer Science & Engineering , KUET 20/43  Algorithm
  • 22. Inserting after given a value linkdata A X B linklink datadata New Node D Computer Science & Engineering , KUET 21/43 C ptr head new->link=ptr->link ptr->link=new
  • 23. What Is Deletion? Deletion operation is used to delete a particular node in the linked list. we simply have to perform operation on the link of the nodes(which contains the address of the next node) to delete a particular element. Computer Science & Engineering , KUET 22/43
  • 24. Types of Deletion Deletion operation may be performed in the following conditions:  Delete first element.  Delete last element.  Delete before a given value.  Delete after a given value.  Delete a particular element Computer Science & Engineering , KUET 23/43
  • 25. Deleting the first node  Declare anode  Assignheadtothenewnode  Update head with thelinkof the new node Algorithm  srt=head  head=srt->link Computer Science & Engineering , KUET 24/43
  • 26. Deleting the first node X linklink datadata head data link B CA Computer Science & Engineering , KUET 25/43  srt=head  head=srt->link srt
  • 27. Deleting the last node  Declare nodessrt,temp  Traversethelistandupdate temp withthevalueofsrt  IfthelinkofsrtisNULL,updatethelink oftempwithNULLandbreaktheloop Algorithm declare srt, temp for(srt=head;;temp=srt, srt=srt->link) if(srt->link==NULL)temp- >link=NULL;Exit; Computer Science & Engineering , KUET 26/43
  • 28. Deleting the last node X linklink datadata head data link B CA Computer Science & Engineering , KUET 27/43 X
  • 29. Deleting after a given value  Declare a node srt  Search the element to delete after  Update link of the node with the link of the next node  Node *srt  srt=head while(srt->info!=data) srt=srt>link  srt->link=srt->link->link  ptr->link=new  Algorithm Computer Science & Engineering , KUET 28/43  Algorithm
  • 30. Deleting after a given value linkdata A X B linklink datadata C Computer Science & Engineering , KUET 29/43 srt head C
  • 31. Deleting before a given value  Declare nodes srt, temp and prev  Search the element to delete before  Update link of the previous node with the link of the next node  Node *srt, *temp, *prev  srt=head while(srt->info!=data) srt=srt>link  prev = temp; temp = srt;  Prev->link = srt  Algorithm Computer Science & Engineering , KUET 30/43  Algorithm
  • 32. Deleting before a given value linkdata A B linklink datadata C Computer Science & Engineering , KUET 31/43 prev head X D linkdata temp srt
  • 33. Deleting a given value  Declare nodes srt and temp  Search the element to delete  Update link of the previous node with the link of the selected node  Node *srt, *temp  Srt=head while(srt->info!=data) srt=srt->link  temp = srt;  temp->link = srt->link  Algorithm Computer Science & Engineering , KUET 32/43  Algorithm
  • 34. Deleting after a given value linkdata A B linklink datadata C Computer Science & Engineering , KUET 33/43 head X D linkdata temp srt
  • 35. Operations on a singly circular linked list  The basic operations on singly circular linked lists are : 1. Creation 2. Insertion 3. Deletion 4. Traversing 5. Searching Computer Science & Engineering , KUET 34/43
  • 36. Operations on a singly circular linked list  Creation of a circular linked list is same as singly list except that we will have to use head instead of NULL  To traverse the list we have to start from head and end until the link of a node is head  To insert a node at the beginning of the list we have to store the value of head in a temporary node and operate accordingly Computer Science & Engineering , KUET 35/43 The operations on a singly circular linked is almost same as that of a singly linked list. The only difference between them is that the link of the last node of a singly linked list contains NULL, whereas that of a circular list contains head
  • 37. Operations on a singly circular linked list  The operation insert last, is almost the same as that of the singly list, difference: head instead of NULL in the link of new node  The operation insert after, is same as that of the singly list. If the node is the last node then we can perform the operation just by calling the insert last’s function  The operation insert before, is same as that of the singly list  The operation delete after and before, is same as that of the singly list. Deleting last element is also almost the same, only have to update the link of previous node with head. But the process of deleting the first element is different, it’ll be discussed in this presentation  The operation delete element, is same as that of the singly list Computer Science & Engineering , KUET 36/43
  • 38. Operations on a singly circular linked list  Mostoftheoperationsarealmostthesameassinglylinkedlistincaseofasingly circularlinkedlist, onlyalittlevariationinlistcreationanddeletingthefirstelement, nextcontentscontaintheseoperations! Computer Science & Engineering , KUET 37/43
  • 39.  Allocate a new node  Insert new element  Make new node point to head  Update head to point to new nodeoffirst element  Ifnotfirstelementupdatelinkofprevious elementwithcurrentnodeaddress Algorithm  create a new node  new->data=item  new->link=head  head=new, temp=new, if head==NULL  else temp->link=new, temp=ptr Creation of a circular list Computer Science & Engineering , KUET 38/43
  • 40. Creation head New Node A Computer Science & Engineering , KUET 39/43 headhead B New Node  new->data=item  new->link=head
  • 41. Deleting the first node  Declare anewnode,srt  Assignheadtothenewnode  Update head with thelinkof thenew node  Update thelinkoflastnode with thelink of thenew node Algorithm  srt=head  head=srt->link  last->link=head Computer Science & Engineering , KUET 40/43
  • 42. Deleting the first node head linklink datadata head data link B CA Computer Science & Engineering , KUET 41/43 last  head=srt->link  last->link=head
  • 43. Application Linked lists are used in many other data structures. Linked lists are used in polynomial manipulation. Representation of trees, stacks, queues. etc. Computer Science & Engineering , KUET 42/43
  • 44. Disadvantages of Linked Lists  The memory is wasted as pointers require extra memory for storage.  No element can be accessed randomly.  It has to access each node sequentially.  Reverse Traversing is difficult in linked list.  No binary search. Computer Science & Engineering , KUET 43/43