SlideShare a Scribd company logo
Pune Vidyarthi Griha’s
COLLEGE OF ENGINEERING, NASHIK – 3.
“Linked List”
By
Prof. Anand N. Gharu
(Assistant Professor)
PVGCOE Computer Dept.
04 August 2019
.
1
Concept, Comparison of sequential and linked organizations, Primitive operations,
Realization of Linked Lists, Realization of linked list using arrays, Dynamic
Memory Management, Linked list using dynamic memory management, Linked
List Abstract Data Type, Linked list operations, Head pointer and header node,
Types of linked list- Linear and circular linked lists, Doubly Linked List and
operations, Circular Linked List, Singly circular linked list, Doubly circular linked
list, Polynomial Manipulations - Polynomial addition, Multiplication of two
polynomials using linked list. Generalized Linked List (GLL) concept,
representation of polynomial and sets using GLL. Case Study- GarbageCollection.2
UNIT – 2 SYLLABUS
“ Linked List is a very commonly used linear data structure
which consists of group of nodes in a sequence.
Each node holds its own data and the address of the next
node hence forming a chain like structure.”
Linked Lists are used to create trees and graphs.
3
INTRODUCTION OF LINKED LIST
Fig: 1 Data Organization
4
Fig: 2 (a): A linked list of nelements
Fig: 2 (b) : A linked list ofweekdays
5
Advantages of Linked Lists
 They are a dynamic in nature which allocates the memory when
required.
 Insertion and deletion operations can be easily implemented.
 Stacks and queues can be easily executed.
 Linked List reduces the access time.
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. 6
INTRODUCTION OF LINKED LIST
Applications of Linked Lists
1. Linked lists are used to implement stacks,
queues, graphs, etc.
2. Linked lists let you insert elements at the
beginning and end of the list.
3. In Linked Lists we don't need to know the size
in advance.
7
INTRODUCTION OF LINKED LIST
Node an item in a linked list. Each node contains a piece of list data
and the location of the next node (item).
Link (of a node) the location of the next node.
head node first node in a linked list
head pointer points to the head node.
Null pointer there is no need in it (linked list is empty)
8
TERMINOLOGIES OF LINKED LIST
PROF. ANAND GHARU 9
DIFFERENCE BETWEEN SEQUENTIAL AND
LINKED ORGANIZATION
PROF. ANAND GHARU 10
LINKED LIST PRIMITIVE OPERATION
Basic Operations
Following are the basic operations supported by a list.
Insertion − Adds an element at the beginning of the list.
Deletion − Deletes an element at the beginning of the list.
Display − Displays the complete list.
Search − Searches an element using the given key.
Delete − Deletes an element using the given key.
PROF. ANAND GHARU 11
DYNAMIC MEMORY MANAGEMENT
“ Dynamic Memory Allocation means memory which can
be allocated or deallocated as per requirement at run time”
Importance of memory allocation :
 no need to initially occupy large amount of memory.
 Memory can be allocated or deallocated as per need.
 It avoid wastage of memory.
 We can free the memory by de-allocating it using free( ).
PROF. ANAND GHARU 12
FUNCTION DYNAMIC
MEMORY ALLOCATION
PROF. ANAND GHARU 13
COMPARE Malloc( ) AND
Calloc( ) MEMORY
PROF. ANAND GHARU 14
Representation of Linked list
Realization stands for Representation of Linked List
A linked list can be represented in two ways :
1. Dynamic representation of linked list
2. Station representation of linked list
PROF. ANAND GHARU 15
Representation of Linked list
Dynamic Representation of linked list :
PROF. ANAND GHARU 16
Representation of Linked list
Static Representation of linked list :
PROF. ANAND GHARU 17
Linked list Abstract Data Type
“Linked List is an Abstract Data Type (ADT) that
holds a collection of Nodes,the nodes can be accessed
in a sequential way. Linked List doesn’t provide a
random access to a Node.”
Usually, those Nodes are connected to the next node
and/or with the previous one, this gives
the linked effect. When the Nodes are connected with
only the next pointer the list is called Singly Linked
List and when it’s connected by the next and
previous the list is called Doubly Linked List.
PROF. ANAND GHARU 18
Linked list Abstract Data Type
ADT — Interface
The Linked List interface can be implemented in
different ways, is important to have operations
to insert a new node and to remove a Node:
ADT Operation :
Create – Creation of linked list
Traversal – it can be traversed
Search – Data can be compare with data to be search.
Destroy – Free the memory
PROF. ANAND GHARU 19
TYPES OF LINKED LIST
There are 3 different implementations of Linked List
available, they are:
1. Linear/Singly Linked List
2. Doubly Linked List
3. Circular Linked List
PROF. ANAND GHARU 20
LINEAR/SINGLY LINKED LIST
“ A linked list in which every node has one link field, to
provide information about where the next node of list is, is
called as singly linkedlist ”
PROF. ANAND GHARU 21
LINEAR/SINGLY LINKED LIST
Singly linked list is a basic linked list type. Singly
linked list is a collection of nodes linked together in a
sequential way where each node of singly linked list
contains a data field and an address field which
contains the reference of the next node. Singly linked
list can contain multiple data fields but should contain
at least single address field pointing to its connected
next node.
PROF. ANAND GHARU 22
ADVANTAGES OF SINGLY
LINKED LIST
1. Singly linked list is probably the most easiest data structure to
implement.
2. Insertion and deletion of element can be done easily.
3. Insertion and deletion of elements doesn't requires movement
of all elements when compared to an array.
4. Requires less memory when compared to doubly, circular or
doubly circular linked list.
5. Can allocate or deallocate memory easily when required
during its execution.
6. It is one of most efficient data structure to implement when
traversing in one direction is required.
PROF. ANAND GHARU 23
DISADVANTAGES OF SINGLY
LINKED LIST
1. It uses more memory when compared to an array.
2. Since elements are not stored sequentially hence
requires more time to access each elements of list.
3. Traversing in reverse is not possible in case of Singly
linked list when compared to Doubly linked list.
4. Requires O(n) time on appending a new node to end.
Which is relatively very high when compared to array or
other linked list.
PROF. ANAND GHARU 24
SINGLY LINKED LIST
OPERATION
1. Creation
2. Insertion
3. Deletion
4. Searching
5. Display
PROF. ANAND GHARU 25
DOUBLY LINKED LIST
 In doubly linked list, each node has two link fields to
store information about who is the next and also about
who is ahead of thenode
 Hence each node has knowledge of its successor and
also its predecessor.
 In doubly linked list, from every node the list can be
traversed in both the directions.
PROF. ANAND GHARU 26
DOUBLY LINKED LIST
Doubly Linked List is a variation of Linked list in which
navigation is possible in both ways, either forward and backward
easily as compared to Single Linked List. Following are the
important terms to understand the concept of doubly linked list.
Link − Each link of a linked list can store a data called an element.
Next − Each link of a linked list contains a link to the next link
called Next.
Prev − Each link of a linked list contains a link to the previous
link called Prev.
LinkedList − A Linked List contains the connection link to the
first link called First and to the last link called Last.
PROF. ANAND GHARU 27
BASIC OPERATION OF DLL
Following are the basic operations supported by a list.
Insertion − Adds an element at the beginning of the list.
Deletion − Deletes an element at the beginning of the list.
Insert Last − Adds an element at the end of the list.
Delete Last − Deletes an element from the end of the list.
Insert After − Adds an element after an item of the list.
Delete − Deletes an element from the list using the key.
Display forward − Displays the complete list in a forward manner.
Display backward − Displays the complete list in a backward manner.
PROF. ANAND GHARU 28
ADVANTAGES OF DOUBLY
LINKED LIST
1) A DLL can be traversed in both forward and backward
direction.
2) The delete operation in DLL is more efficient if pointer to the
node to be deleted is given.
3) We can quickly insert a new node before a given node.
In singly linked list, to delete a node, pointer to the previous node
is needed. To get this previous node, sometimes the list is
traversed. In DLL, we can get the previous node using previous
pointer.
PROF. ANAND GHARU 29
DISADVANTAGES OF DOUBLY
LINKED LIST
1) Every node of DLL Require extra space for an previous pointer.
It is possible to implement DLL with single pointer though
2) All operations require an extra pointer previous to be
maintained. For example, in insertion, we need to modify previous
pointers together with next pointers. For example in following
functions for insertions at different positions, we need 1 or 2 extra
steps to set previous pointer.
PROF. ANAND GHARU 30
SINGLY CIRCULAR LINKED LIST
“Circular Linked List is a variation of Linked list in which
the first element points to the last element and the last
element points to the first element. Both Singly Linked List
and Doubly Linked List can be made into a circular linked
list”.
PROF. ANAND GHARU 31
CIRCULAR LINKED LIST
Circular linked list are mostly used in task
maintenance in operating systems. There are many
examples where circular linked list are being used in
computer science including browser surfing where a
record of pages visited in the past by the user, is
maintained in the form of circular linked lists and can
be accessed again on clicking the previous button.
PROF. ANAND GHARU 32
BASIC OPERATION OF CLL
Following are the important operations supported by a circular list.
insert − Inserts an element at the start of the list.
delete − Deletes an element from the start of the list.
display − Displays the list.
PROF. ANAND GHARU 33
ADVANTAGES OF CIRCULAR
LINKED LIST
1. Some problems are circular and a circular data structure would be
more natural when used to represent it.
2. The entire list can be traversed starting from any node (traverse means
visit every node just once)
3. fewer special cases when coding(all nodes have a node before and after
it)
PROF. ANAND GHARU 34
DISADVANTAGES OF
CIRCULAR LINKED LIST
1. Circular list are complex as compared to singly linked
lists.
2. Reversing of circular list is a complex as compared
to singly or doubly lists.
3. If not traversed carefully, then we could end up in an
infinite loop.
PROF. ANAND GHARU 35
DOUBLY CIRCULAR LINKED LIST
“Circular Doubly Linked List has properties of both doubly linked
list and circular linked list in which two consecutive elements are
linked or connected by previous and next pointer and the last node
points to first node by next pointer and also the first node points to
last node by previous pointer”.
PROF. ANAND GHARU 36
BASIC OPERATION OF
DOUBLY CIRCULAR LL
PROF. ANAND GHARU 37
ADVANTAGES OF CIRCULAR
LINKED LIST
1. List can be traversed from both the directions i.e. from head to
tail or from tail to head.
2. Jumping from head to tail or from tail to head is done in
constant time O(1).
3. Circular Doubly Linked Lists are used for implementation of
advanced data structures like Fibonacci Heap.
PROF. ANAND GHARU 38
DISADVANTAGES OF
CIRCULAR LINKED LIST
1. It takes slightly extra memory in each node to
accommodate previous pointer.
2. Lots of pointers involved while implementing or doing
operations on a list. So, pointers should be handled
carefully otherwise data of the list may get lost.
Applications of Circular doubly linked list
Managing songs playlist in media player applications.
Managing shopping cart in online shopping
PROF. ANAND GHARU 39
A node will have 3 fields, which represent the coefficient and
exponent of a term and a pointerto the next term
40
POLYNOMIAL MANIPULATIONS
 E.x. For instance, the polynomial, say A = 6x7 + 3x5 + 4x3 +
12 would be stored as:
41
POLYNOMIAL MANIPULATIONS
Operation on Polynomial
42
Polynomial evaluation
Polynomial addition
Multiplication of two polynomials of sparse
matrix using Representation linked list
Linked list implementation of the stack
Generalized linked list
ADDITION OF POLYNOMIAL
43
MULTIPLICATION OF POLYNOMIAL
44
GENERALIZED LINKED LIST
45
• “A generalized list, A, is a finite sequence of n > 0 elements, 1,
..., nwhere the i are either atoms or lists. The elements i,
1 i n which are not atoms are said to be the sublists of A.”
GENERALIZED LINKED LIST
46
GENERALIZED LINKED LIST
47
GENERALIZED LINKED LIST
48
GENERALIZED LINKED LIST
49
Representation of Polynomial
using GLL
50
GARBAGE COLLECTION
51
 garbage collection is the process of collecting all unused nodes
and returning them to available space.
 This process is carried out in essentially two phases. In the first
phase, known as the marking phase, all nodes in use are marked.
In the second phase all unmarked nodes are returned to the
available space list. This second phase is trivial when all nodes
are of a fixed size.
 In this case, the second phase requires only the examination of
each node to see whether or not it has been marked.

52
THANK YOU !!!!!
Blog : anandgharu.wordpress.com
gharu.anand@gmail.com
PROF. ANAND GHARU 52
GARBAGE COLLECTION
53
 If there are a total of n nodes, then the second phase of garbage
collection can be carried out in O(n) steps.
 In this situation it is only the first or marking phase that is of any
interest in designing an algorithm. When variable size nodes are in use,
it is desirable to compact memory so that all free nodes form a
contiguous block of memory.
 In this case the second phase is referred to as memory compaction.
Compaction of disk space to reduce average retrieval time is desirable
even for fixed size nodes. In this section we shall study two marking
algorithms and one compaction algorithm.
ADVANTAGES OF GARBAGE
COLLECTION
54
DISADVANTAGES OF GARBAGE
COLLECTION
55

More Related Content

PPTX
Singly & Circular Linked list
Khulna University of Engineering & Tecnology
 
PPT
Linked lists
SARITHA REDDY
 
PPTX
Insertion in singly linked list
Keval Bhogayata
 
PPTX
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
PPTX
Array implementation and linked list as datat structure
Tushar Aneyrao
 
PDF
Singly linked list
Amar Jukuntla
 
PDF
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
PPT
Circular linked list
chauhankapil
 
Singly & Circular Linked list
Khulna University of Engineering & Tecnology
 
Linked lists
SARITHA REDDY
 
Insertion in singly linked list
Keval Bhogayata
 
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
Array implementation and linked list as datat structure
Tushar Aneyrao
 
Singly linked list
Amar Jukuntla
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Circular linked list
chauhankapil
 

What's hot (20)

PPTX
Doubly Linked List
Ninad Mankar
 
PPTX
Circular link list.ppt
Tirthika Bandi
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
linked list in data structure
shameen khan
 
PPTX
queue & its applications
somendra kumar
 
PPT
Arrays
SARITHA REDDY
 
PPTX
Introduction to data structure ppt
NalinNishant3
 
PPTX
Linked list
akshat360
 
PPTX
Array in c++
Mahesha Mano
 
PPTX
single linked list
Sathasivam Rangasamy
 
PPTX
Queue in Data Structure
Janki Shah
 
PPTX
Linked list
KalaivaniKS1
 
PPTX
Presentation on array
topu93
 
PPTX
Queue ppt
SouravKumar328
 
PPTX
Infix to postfix conversion
Then Murugeshwari
 
PPT
12. Indexing and Hashing in DBMS
koolkampus
 
PPTX
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
PPTX
Data structure - Graph
Madhu Bala
 
PPTX
trees in data structure
shameen khan
 
PDF
Little o and little omega
Rajesh K Shukla
 
Doubly Linked List
Ninad Mankar
 
Circular link list.ppt
Tirthika Bandi
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
linked list in data structure
shameen khan
 
queue & its applications
somendra kumar
 
Introduction to data structure ppt
NalinNishant3
 
Linked list
akshat360
 
Array in c++
Mahesha Mano
 
single linked list
Sathasivam Rangasamy
 
Queue in Data Structure
Janki Shah
 
Linked list
KalaivaniKS1
 
Presentation on array
topu93
 
Queue ppt
SouravKumar328
 
Infix to postfix conversion
Then Murugeshwari
 
12. Indexing and Hashing in DBMS
koolkampus
 
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
Data structure - Graph
Madhu Bala
 
trees in data structure
shameen khan
 
Little o and little omega
Rajesh K Shukla
 
Ad

Similar to Unit 3 dsa LINKED LIST (20)

PPTX
Linked list in Data Structure and Algorithm
KristinaBorooah
 
PPTX
LINKED LIST.pptx
Dr.Shweta
 
PPTX
Data Structures and Algorithms - Lec 05.pptx
RameshaFernando2
 
PPTX
link list.pptx complete notes detailed ans
IqraHanif27
 
PPT
ANOITO2341988888888888888888888885555.ppt
robertobula2
 
PPTX
Link list
Didar Rashad
 
PPTX
Link list
Didar Rashad
 
PPT
Link list using array in Data structure amd algorithms
pwstudent403
 
PPTX
Linked list
MahammadAdil
 
PPTX
Linked lists linked lists vs Arrays.pptx
Sahar160629
 
PPT
Linked List
CHANDAN KUMAR
 
DOCX
Linked List
BHARATH KUMAR
 
DOCX
Introduction to linked lists
pooja kumari
 
PDF
Linked list (introduction) 1
DrSudeshna
 
PPTX
Linked List in Data Structure
Meghaj Mallick
 
PPTX
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
PDF
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
PPTX
Data Structures Introduction & Linear DS
sailaja156145
 
PDF
Linked list
Nurjahan Nipa
 
Linked list in Data Structure and Algorithm
KristinaBorooah
 
LINKED LIST.pptx
Dr.Shweta
 
Data Structures and Algorithms - Lec 05.pptx
RameshaFernando2
 
link list.pptx complete notes detailed ans
IqraHanif27
 
ANOITO2341988888888888888888888885555.ppt
robertobula2
 
Link list
Didar Rashad
 
Link list
Didar Rashad
 
Link list using array in Data structure amd algorithms
pwstudent403
 
Linked list
MahammadAdil
 
Linked lists linked lists vs Arrays.pptx
Sahar160629
 
Linked List
CHANDAN KUMAR
 
Linked List
BHARATH KUMAR
 
Introduction to linked lists
pooja kumari
 
Linked list (introduction) 1
DrSudeshna
 
Linked List in Data Structure
Meghaj Mallick
 
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
Data Structures Introduction & Linear DS
sailaja156145
 
Linked list
Nurjahan Nipa
 
Ad

More from PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK (20)

PDF
Wt unit 5 client & server side framework
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Wt unit 4 server side technology-2
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Wt unit 3 server side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Wt unit 2 ppts client sied technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Unit 6 dsa SEARCHING AND SORTING
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Unit 2 dsa LINEAR DATA STRUCTURE
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Wt unit 1 ppts web development process
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Wt unit 3 server side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
COMPUTER LABORATORY-4 LAB MANUAL BE COMPUTER ENGINEERING
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Wt unit 5 client & server side framework
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Wt unit 4 server side technology-2
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Wt unit 2 ppts client sied technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Wt unit 1 ppts web development process
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
COMPUTER LABORATORY-4 LAB MANUAL BE COMPUTER ENGINEERING
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 

Recently uploaded (20)

PDF
6th International Conference on Artificial Intelligence and Machine Learning ...
gerogepatton
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
demidovs1
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PPTX
EE3303-EM-I 25.7.25 electrical machines.pptx
Nagen87
 
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
5 Influence line.pdf for structural engineers
Endalkazene
 
PPTX
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
VinayB68
 
6th International Conference on Artificial Intelligence and Machine Learning ...
gerogepatton
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
demidovs1
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
EE3303-EM-I 25.7.25 electrical machines.pptx
Nagen87
 
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
5 Influence line.pdf for structural engineers
Endalkazene
 
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
VinayB68
 

Unit 3 dsa LINKED LIST

  • 1. Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK – 3. “Linked List” By Prof. Anand N. Gharu (Assistant Professor) PVGCOE Computer Dept. 04 August 2019 . 1
  • 2. Concept, Comparison of sequential and linked organizations, Primitive operations, Realization of Linked Lists, Realization of linked list using arrays, Dynamic Memory Management, Linked list using dynamic memory management, Linked List Abstract Data Type, Linked list operations, Head pointer and header node, Types of linked list- Linear and circular linked lists, Doubly Linked List and operations, Circular Linked List, Singly circular linked list, Doubly circular linked list, Polynomial Manipulations - Polynomial addition, Multiplication of two polynomials using linked list. Generalized Linked List (GLL) concept, representation of polynomial and sets using GLL. Case Study- GarbageCollection.2 UNIT – 2 SYLLABUS
  • 3. “ Linked List is a very commonly used linear data structure which consists of group of nodes in a sequence. Each node holds its own data and the address of the next node hence forming a chain like structure.” Linked Lists are used to create trees and graphs. 3 INTRODUCTION OF LINKED LIST
  • 4. Fig: 1 Data Organization 4
  • 5. Fig: 2 (a): A linked list of nelements Fig: 2 (b) : A linked list ofweekdays 5
  • 6. Advantages of Linked Lists  They are a dynamic in nature which allocates the memory when required.  Insertion and deletion operations can be easily implemented.  Stacks and queues can be easily executed.  Linked List reduces the access time. 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. 6 INTRODUCTION OF LINKED LIST
  • 7. Applications of Linked Lists 1. Linked lists are used to implement stacks, queues, graphs, etc. 2. Linked lists let you insert elements at the beginning and end of the list. 3. In Linked Lists we don't need to know the size in advance. 7 INTRODUCTION OF LINKED LIST
  • 8. Node an item in a linked list. Each node contains a piece of list data and the location of the next node (item). Link (of a node) the location of the next node. head node first node in a linked list head pointer points to the head node. Null pointer there is no need in it (linked list is empty) 8 TERMINOLOGIES OF LINKED LIST
  • 9. PROF. ANAND GHARU 9 DIFFERENCE BETWEEN SEQUENTIAL AND LINKED ORGANIZATION
  • 10. PROF. ANAND GHARU 10 LINKED LIST PRIMITIVE OPERATION Basic Operations Following are the basic operations supported by a list. Insertion − Adds an element at the beginning of the list. Deletion − Deletes an element at the beginning of the list. Display − Displays the complete list. Search − Searches an element using the given key. Delete − Deletes an element using the given key.
  • 11. PROF. ANAND GHARU 11 DYNAMIC MEMORY MANAGEMENT “ Dynamic Memory Allocation means memory which can be allocated or deallocated as per requirement at run time” Importance of memory allocation :  no need to initially occupy large amount of memory.  Memory can be allocated or deallocated as per need.  It avoid wastage of memory.  We can free the memory by de-allocating it using free( ).
  • 12. PROF. ANAND GHARU 12 FUNCTION DYNAMIC MEMORY ALLOCATION
  • 13. PROF. ANAND GHARU 13 COMPARE Malloc( ) AND Calloc( ) MEMORY
  • 14. PROF. ANAND GHARU 14 Representation of Linked list Realization stands for Representation of Linked List A linked list can be represented in two ways : 1. Dynamic representation of linked list 2. Station representation of linked list
  • 15. PROF. ANAND GHARU 15 Representation of Linked list Dynamic Representation of linked list :
  • 16. PROF. ANAND GHARU 16 Representation of Linked list Static Representation of linked list :
  • 17. PROF. ANAND GHARU 17 Linked list Abstract Data Type “Linked List is an Abstract Data Type (ADT) that holds a collection of Nodes,the nodes can be accessed in a sequential way. Linked List doesn’t provide a random access to a Node.” Usually, those Nodes are connected to the next node and/or with the previous one, this gives the linked effect. When the Nodes are connected with only the next pointer the list is called Singly Linked List and when it’s connected by the next and previous the list is called Doubly Linked List.
  • 18. PROF. ANAND GHARU 18 Linked list Abstract Data Type ADT — Interface The Linked List interface can be implemented in different ways, is important to have operations to insert a new node and to remove a Node: ADT Operation : Create – Creation of linked list Traversal – it can be traversed Search – Data can be compare with data to be search. Destroy – Free the memory
  • 19. PROF. ANAND GHARU 19 TYPES OF LINKED LIST There are 3 different implementations of Linked List available, they are: 1. Linear/Singly Linked List 2. Doubly Linked List 3. Circular Linked List
  • 20. PROF. ANAND GHARU 20 LINEAR/SINGLY LINKED LIST “ A linked list in which every node has one link field, to provide information about where the next node of list is, is called as singly linkedlist ”
  • 21. PROF. ANAND GHARU 21 LINEAR/SINGLY LINKED LIST Singly linked list is a basic linked list type. Singly linked list is a collection of nodes linked together in a sequential way where each node of singly linked list contains a data field and an address field which contains the reference of the next node. Singly linked list can contain multiple data fields but should contain at least single address field pointing to its connected next node.
  • 22. PROF. ANAND GHARU 22 ADVANTAGES OF SINGLY LINKED LIST 1. Singly linked list is probably the most easiest data structure to implement. 2. Insertion and deletion of element can be done easily. 3. Insertion and deletion of elements doesn't requires movement of all elements when compared to an array. 4. Requires less memory when compared to doubly, circular or doubly circular linked list. 5. Can allocate or deallocate memory easily when required during its execution. 6. It is one of most efficient data structure to implement when traversing in one direction is required.
  • 23. PROF. ANAND GHARU 23 DISADVANTAGES OF SINGLY LINKED LIST 1. It uses more memory when compared to an array. 2. Since elements are not stored sequentially hence requires more time to access each elements of list. 3. Traversing in reverse is not possible in case of Singly linked list when compared to Doubly linked list. 4. Requires O(n) time on appending a new node to end. Which is relatively very high when compared to array or other linked list.
  • 24. PROF. ANAND GHARU 24 SINGLY LINKED LIST OPERATION 1. Creation 2. Insertion 3. Deletion 4. Searching 5. Display
  • 25. PROF. ANAND GHARU 25 DOUBLY LINKED LIST  In doubly linked list, each node has two link fields to store information about who is the next and also about who is ahead of thenode  Hence each node has knowledge of its successor and also its predecessor.  In doubly linked list, from every node the list can be traversed in both the directions.
  • 26. PROF. ANAND GHARU 26 DOUBLY LINKED LIST Doubly Linked List is a variation of Linked list in which navigation is possible in both ways, either forward and backward easily as compared to Single Linked List. Following are the important terms to understand the concept of doubly linked list. Link − Each link of a linked list can store a data called an element. Next − Each link of a linked list contains a link to the next link called Next. Prev − Each link of a linked list contains a link to the previous link called Prev. LinkedList − A Linked List contains the connection link to the first link called First and to the last link called Last.
  • 27. PROF. ANAND GHARU 27 BASIC OPERATION OF DLL Following are the basic operations supported by a list. Insertion − Adds an element at the beginning of the list. Deletion − Deletes an element at the beginning of the list. Insert Last − Adds an element at the end of the list. Delete Last − Deletes an element from the end of the list. Insert After − Adds an element after an item of the list. Delete − Deletes an element from the list using the key. Display forward − Displays the complete list in a forward manner. Display backward − Displays the complete list in a backward manner.
  • 28. PROF. ANAND GHARU 28 ADVANTAGES OF DOUBLY LINKED LIST 1) A DLL can be traversed in both forward and backward direction. 2) The delete operation in DLL is more efficient if pointer to the node to be deleted is given. 3) We can quickly insert a new node before a given node. In singly linked list, to delete a node, pointer to the previous node is needed. To get this previous node, sometimes the list is traversed. In DLL, we can get the previous node using previous pointer.
  • 29. PROF. ANAND GHARU 29 DISADVANTAGES OF DOUBLY LINKED LIST 1) Every node of DLL Require extra space for an previous pointer. It is possible to implement DLL with single pointer though 2) All operations require an extra pointer previous to be maintained. For example, in insertion, we need to modify previous pointers together with next pointers. For example in following functions for insertions at different positions, we need 1 or 2 extra steps to set previous pointer.
  • 30. PROF. ANAND GHARU 30 SINGLY CIRCULAR LINKED LIST “Circular Linked List is a variation of Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list”.
  • 31. PROF. ANAND GHARU 31 CIRCULAR LINKED LIST Circular linked list are mostly used in task maintenance in operating systems. There are many examples where circular linked list are being used in computer science including browser surfing where a record of pages visited in the past by the user, is maintained in the form of circular linked lists and can be accessed again on clicking the previous button.
  • 32. PROF. ANAND GHARU 32 BASIC OPERATION OF CLL Following are the important operations supported by a circular list. insert − Inserts an element at the start of the list. delete − Deletes an element from the start of the list. display − Displays the list.
  • 33. PROF. ANAND GHARU 33 ADVANTAGES OF CIRCULAR LINKED LIST 1. Some problems are circular and a circular data structure would be more natural when used to represent it. 2. The entire list can be traversed starting from any node (traverse means visit every node just once) 3. fewer special cases when coding(all nodes have a node before and after it)
  • 34. PROF. ANAND GHARU 34 DISADVANTAGES OF CIRCULAR LINKED LIST 1. Circular list are complex as compared to singly linked lists. 2. Reversing of circular list is a complex as compared to singly or doubly lists. 3. If not traversed carefully, then we could end up in an infinite loop.
  • 35. PROF. ANAND GHARU 35 DOUBLY CIRCULAR LINKED LIST “Circular Doubly Linked List has properties of both doubly linked list and circular linked list in which two consecutive elements are linked or connected by previous and next pointer and the last node points to first node by next pointer and also the first node points to last node by previous pointer”.
  • 36. PROF. ANAND GHARU 36 BASIC OPERATION OF DOUBLY CIRCULAR LL
  • 37. PROF. ANAND GHARU 37 ADVANTAGES OF CIRCULAR LINKED LIST 1. List can be traversed from both the directions i.e. from head to tail or from tail to head. 2. Jumping from head to tail or from tail to head is done in constant time O(1). 3. Circular Doubly Linked Lists are used for implementation of advanced data structures like Fibonacci Heap.
  • 38. PROF. ANAND GHARU 38 DISADVANTAGES OF CIRCULAR LINKED LIST 1. It takes slightly extra memory in each node to accommodate previous pointer. 2. Lots of pointers involved while implementing or doing operations on a list. So, pointers should be handled carefully otherwise data of the list may get lost. Applications of Circular doubly linked list Managing songs playlist in media player applications. Managing shopping cart in online shopping
  • 40. A node will have 3 fields, which represent the coefficient and exponent of a term and a pointerto the next term 40 POLYNOMIAL MANIPULATIONS
  • 41.  E.x. For instance, the polynomial, say A = 6x7 + 3x5 + 4x3 + 12 would be stored as: 41 POLYNOMIAL MANIPULATIONS
  • 42. Operation on Polynomial 42 Polynomial evaluation Polynomial addition Multiplication of two polynomials of sparse matrix using Representation linked list Linked list implementation of the stack Generalized linked list
  • 45. GENERALIZED LINKED LIST 45 • “A generalized list, A, is a finite sequence of n > 0 elements, 1, ..., nwhere the i are either atoms or lists. The elements i, 1 i n which are not atoms are said to be the sublists of A.”
  • 51. GARBAGE COLLECTION 51  garbage collection is the process of collecting all unused nodes and returning them to available space.  This process is carried out in essentially two phases. In the first phase, known as the marking phase, all nodes in use are marked. In the second phase all unmarked nodes are returned to the available space list. This second phase is trivial when all nodes are of a fixed size.  In this case, the second phase requires only the examination of each node to see whether or not it has been marked. 
  • 52. 52 THANK YOU !!!!! Blog : anandgharu.wordpress.com [email protected] PROF. ANAND GHARU 52
  • 53. GARBAGE COLLECTION 53  If there are a total of n nodes, then the second phase of garbage collection can be carried out in O(n) steps.  In this situation it is only the first or marking phase that is of any interest in designing an algorithm. When variable size nodes are in use, it is desirable to compact memory so that all free nodes form a contiguous block of memory.  In this case the second phase is referred to as memory compaction. Compaction of disk space to reduce average retrieval time is desirable even for fixed size nodes. In this section we shall study two marking algorithms and one compaction algorithm.