SlideShare a Scribd company logo
1 of 26
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
1
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 Recognize need of a Data Structure, which Dynamically
can Shrink and Grow
 Realization of Linked List as Dynamic Data StructureTo
understand the well-defined, clear, and simple approach of
program design
 Utilize Flexibility of the same Easily and EffectivelyTo
understand sequential organization of data
 Learn Variations of Linked List and Use them for
Appropriate Applications
2
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
3
 The linked list is a very effective and efficient dynamic
data structure
 Data items can be stored anywhere in memory in a
scattered manner
 To maintain the specific sequence of these data items we
need to maintain link(s) with successor (and/ or
predecessor)
 It is called as a linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 A linked list is an ordered collection of data in which each
element contains minimum two values, data and
link(s) to its successor (and/ or predecessor)
 The list with one link field using which every element is
associated to either its predecessor or successor is called
as singly linked list
 In a linked list, before adding any element to the list,
memory space for that node must be allocated
 A link is kept with each item to the next item in the list
4
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
5
Fig: 1 Data Organization
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
6
Fig: 2 (a): A linked list of n elements
Fig: 2 (b) : A linked list of weekdays
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 Each node of the linked list has minimum two elements :
The data member(s) being stored in the list
A pointer or link to the next element in the list
 The last node in the list contains a NULL (or -1) pointer to
indicate that it is the end or tail of the list
7
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 The last node in the list contains a NULL (or -1) pointer to indicate
that it is the end or tail of the list
 Provides static allocation, which means space allocation is done
by compiler once cannot be changed during execution and size has
to be known in advance.
 As individual objects are stored at fixed distance apart, we can access
any element randomly.
 Insertion and deletion of objects in between the list requires a lot of
data movement.
 Space inefficient for large objects and large quantity with often
insertions and deletions
 Element need not know/store keep address of its successive element.
8
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 Element can be placed anywhere in the memory
 Dynamic allocation (size need not be known in advance) i.e. space
allocation as per need can be done during execution.
 As objects are not placed at fixed distance apart, random access to
elements is not possible.
 Insertion and deletion of objects do not require any data shifting.
 Space efficient for large objects and large quantity with often
insertions and deletions
 Each element in general is a collection of data and a link. At least one
link field is must.
 Every element keeps address of its successor element in a link field.
9
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
10
 Some more operations, which are based on above basic
operations are:
 Searching a node
 Updating node.
 Printing the node or list.
 Counting length of the list.
 Reverse the list.
 Sort the list using pointer manipulation.
 Concatenate two lists.
 Merge two-sorted list into third sorted list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
11
 Data Structure of Node
 Insertion of a Node
 Linked List Traversal
Non-Recursive Method
Recursive Traversal Method
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
12
 Structure of Node
 Doubly linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
13
 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 linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
14
 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 the node
 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.
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
15
The other classification of linked lists is,
 Linear linked list
 Circular linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
16
 The linked list that we have seen so for are often known
as linear linked lists.
 All elements of such a linked list can be accessed by first
setting up a pointer pointing to the first node of the list
and then traversing the entire list.
Linear linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
17
 For example, consider a singly linked list.
 Given a pointer A to a node in a linear list, we cannot reach
any of the nodes that precede the node to which A is pointing.
 This disadvantage can be overcome by making a small
change. This change is without any additional data structure.
 The link field of last node is set to NULL in linear list to mark
end of list. This link field of last node can be set to point first
node rather than NULL. Such a linked list is called a circular
linked list.
Although a linear linked list is a useful and popular
data structure, it has some shortcomings.
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
18
Circular linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
19
Doubly Linked List
We can use doubly linked lists in which each node contain two links,
one to its predecessor and other to its successor
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
20
Polynomial Manipulations
A node will have 3 fields, which represent the
coefficient and exponent of a term and a pointer to
the next term
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
21
 For instance, the polynomial, say A = 6x7 + 3x5 + 4x3 +
12 would be stored as :
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
22
Operations on Polynomials
Polynomial evaluation
Polynomial addition
Multiplication of two polynomials
Representation of sparse matrix using
linked list
Linked list implementation of the stack
Generalized linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
23
 Overflow : Sometimes new data node is to be
inserted into data structure but there is no available
space i.e. free-pool is empty. This situation is called
overflow
 Underflow : This refers to situation where
programmer wants to delete a node from empty list
 For good memory utilization, operating system
periodically collects all the free blocks and inserts into
free-pool
 Any technique that does this collection is called garbage
collection
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
24
 There are two implementation of linked linear list; array and pointers
 There is a need is of such a data structure which can dynamically shrink and
grow
 Hence the popular implementation us using pointers and dynamic memory
management
 Singly linked lists are useful data structures, especially if you need to
automatically allocate and de-allocate space in a list
 The basic operation are create list, transverse the list, insert and delete a
node
 There are two variation of linked list singly and doubly linked list. Both
linked list can be circular lists
 The linked could be with or without head node. Head node is used to store
some information about the list, so that it can be accessed without
traversing the same
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
25
 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 the node
 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.
 Information could be like total number of nodes in the list and similarly any
other Linked list is the most popular data structure used. It has many
application such as process queue, print queue, garbage collection etc
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
26
End
of
Chapter 6 …!

More Related Content

What's hot

Graph representation
Graph representationGraph representation
Graph representation
Tech_MX
 

What's hot (20)

Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentation
 
Linked list
Linked listLinked list
Linked list
 
Graph representation
Graph representationGraph representation
Graph representation
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
Linked list
Linked listLinked list
Linked list
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Binary search python
Binary search pythonBinary search python
Binary search python
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
3.2 insertion sort
3.2 insertion sort3.2 insertion sort
3.2 insertion sort
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
 

Viewers also liked

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
Tushar Aneyrao
 

Viewers also liked (18)

Double linked list
Double linked listDouble linked list
Double linked list
 
7 Myths of AI
7 Myths of AI7 Myths of AI
7 Myths of AI
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
 
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
 
linked list
linked list linked list
linked list
 
Linked list
Linked listLinked list
Linked list
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
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...
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
 
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
 
Cyber Crime
Cyber CrimeCyber Crime
Cyber Crime
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Open Legal Data Workshop at Stanford
Open Legal Data Workshop at StanfordOpen Legal Data Workshop at Stanford
Open Legal Data Workshop at Stanford
 
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law OverviewHarry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law Overview
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
 

Similar to 6. Linked list - Data Structures using C++ by Varsha Patil

Static arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfStatic arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdf
anjanacottonmills
 
Data Structure the Basic Structure for Programming
Data Structure the Basic Structure for ProgrammingData Structure the Basic Structure for Programming
Data Structure the Basic Structure for Programming
paperpublications3
 
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
edgar6wallace88877
 
Data Structure the Basic Structure for Programming
Data Structure the Basic Structure for ProgrammingData Structure the Basic Structure for Programming
Data Structure the Basic Structure for Programming
paperpublications3
 

Similar to 6. Linked list - Data Structures using C++ by Varsha Patil (20)

9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
 
7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil
 
15. STL - Data Structures using C++ by Varsha Patil
15. STL - Data Structures using C++ by Varsha Patil15. STL - Data Structures using C++ by Varsha Patil
15. STL - Data Structures using C++ by Varsha Patil
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTES
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
AAT PPT format - oRGINAL.pptx
AAT PPT format - oRGINAL.pptxAAT PPT format - oRGINAL.pptx
AAT PPT format - oRGINAL.pptx
 
Static arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfStatic arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdf
 
Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...
 
5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Link list
Link listLink list
Link list
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
Lecture 2b lists
Lecture 2b listsLecture 2b lists
Lecture 2b lists
 
Data Structure the Basic Structure for Programming
Data Structure the Basic Structure for ProgrammingData Structure the Basic Structure for Programming
Data Structure the Basic Structure for Programming
 
Linked List
Linked ListLinked List
Linked List
 
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
 
Introduction to Data Structures .
Introduction to Data Structures        .Introduction to Data Structures        .
Introduction to Data Structures .
 
Data Structure the Basic Structure for Programming
Data Structure the Basic Structure for ProgrammingData Structure the Basic Structure for Programming
Data Structure the Basic Structure for Programming
 
linked_lists
linked_listslinked_lists
linked_lists
 

More from widespreadpromotion

More from widespreadpromotion (10)

Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. PatilDiscrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
 
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
 
14. Files - Data Structures using C++ by Varsha Patil
14. Files - Data Structures using C++ by Varsha Patil14. Files - Data Structures using C++ by Varsha Patil
14. Files - Data Structures using C++ by Varsha Patil
 
12. Heaps - Data Structures using C++ by Varsha Patil
12. Heaps - Data Structures using C++ by Varsha Patil12. Heaps - Data Structures using C++ by Varsha Patil
12. Heaps - Data Structures using C++ by Varsha Patil
 
11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil
 
8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil
 
4. Recursion - Data Structures using C++ by Varsha Patil
4. Recursion - Data Structures using C++ by Varsha Patil4. Recursion - Data Structures using C++ by Varsha Patil
4. Recursion - Data Structures using C++ by Varsha Patil
 
3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
 
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
 

Recently uploaded

Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
nirzagarg
 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
gajnagarg
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
HyderabadDolls
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
HyderabadDolls
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
gajnagarg
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Klinik kandungan
 

Recently uploaded (20)

Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
 
Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?
 
20240412-SmartCityIndex-2024-Full-Report.pdf
20240412-SmartCityIndex-2024-Full-Report.pdf20240412-SmartCityIndex-2024-Full-Report.pdf
20240412-SmartCityIndex-2024-Full-Report.pdf
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 

6. Linked list - Data Structures using C++ by Varsha Patil

  • 1. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 1
  • 2. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  Recognize need of a Data Structure, which Dynamically can Shrink and Grow  Realization of Linked List as Dynamic Data StructureTo understand the well-defined, clear, and simple approach of program design  Utilize Flexibility of the same Easily and EffectivelyTo understand sequential organization of data  Learn Variations of Linked List and Use them for Appropriate Applications 2
  • 3. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 3  The linked list is a very effective and efficient dynamic data structure  Data items can be stored anywhere in memory in a scattered manner  To maintain the specific sequence of these data items we need to maintain link(s) with successor (and/ or predecessor)  It is called as a linked list
  • 4. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  A linked list is an ordered collection of data in which each element contains minimum two values, data and link(s) to its successor (and/ or predecessor)  The list with one link field using which every element is associated to either its predecessor or successor is called as singly linked list  In a linked list, before adding any element to the list, memory space for that node must be allocated  A link is kept with each item to the next item in the list 4
  • 5. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 5 Fig: 1 Data Organization
  • 6. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 6 Fig: 2 (a): A linked list of n elements Fig: 2 (b) : A linked list of weekdays
  • 7. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  Each node of the linked list has minimum two elements : The data member(s) being stored in the list A pointer or link to the next element in the list  The last node in the list contains a NULL (or -1) pointer to indicate that it is the end or tail of the list 7
  • 8. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  The last node in the list contains a NULL (or -1) pointer to indicate that it is the end or tail of the list  Provides static allocation, which means space allocation is done by compiler once cannot be changed during execution and size has to be known in advance.  As individual objects are stored at fixed distance apart, we can access any element randomly.  Insertion and deletion of objects in between the list requires a lot of data movement.  Space inefficient for large objects and large quantity with often insertions and deletions  Element need not know/store keep address of its successive element. 8
  • 9. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  Element can be placed anywhere in the memory  Dynamic allocation (size need not be known in advance) i.e. space allocation as per need can be done during execution.  As objects are not placed at fixed distance apart, random access to elements is not possible.  Insertion and deletion of objects do not require any data shifting.  Space efficient for large objects and large quantity with often insertions and deletions  Each element in general is a collection of data and a link. At least one link field is must.  Every element keeps address of its successor element in a link field. 9
  • 10. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 10  Some more operations, which are based on above basic operations are:  Searching a node  Updating node.  Printing the node or list.  Counting length of the list.  Reverse the list.  Sort the list using pointer manipulation.  Concatenate two lists.  Merge two-sorted list into third sorted list
  • 11. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 11  Data Structure of Node  Insertion of a Node  Linked List Traversal Non-Recursive Method Recursive Traversal Method
  • 12. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 12  Structure of Node  Doubly linked list
  • 13. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 13  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 linked list
  • 14. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 14  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 the node  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.
  • 15. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 15 The other classification of linked lists is,  Linear linked list  Circular linked list
  • 16. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 16  The linked list that we have seen so for are often known as linear linked lists.  All elements of such a linked list can be accessed by first setting up a pointer pointing to the first node of the list and then traversing the entire list. Linear linked list
  • 17. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 17  For example, consider a singly linked list.  Given a pointer A to a node in a linear list, we cannot reach any of the nodes that precede the node to which A is pointing.  This disadvantage can be overcome by making a small change. This change is without any additional data structure.  The link field of last node is set to NULL in linear list to mark end of list. This link field of last node can be set to point first node rather than NULL. Such a linked list is called a circular linked list. Although a linear linked list is a useful and popular data structure, it has some shortcomings.
  • 18. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 18 Circular linked list
  • 19. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 19 Doubly Linked List We can use doubly linked lists in which each node contain two links, one to its predecessor and other to its successor
  • 20. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 20 Polynomial Manipulations A node will have 3 fields, which represent the coefficient and exponent of a term and a pointer to the next term
  • 21. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 21  For instance, the polynomial, say A = 6x7 + 3x5 + 4x3 + 12 would be stored as :
  • 22. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 22 Operations on Polynomials Polynomial evaluation Polynomial addition Multiplication of two polynomials Representation of sparse matrix using linked list Linked list implementation of the stack Generalized linked list
  • 23. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 23  Overflow : Sometimes new data node is to be inserted into data structure but there is no available space i.e. free-pool is empty. This situation is called overflow  Underflow : This refers to situation where programmer wants to delete a node from empty list  For good memory utilization, operating system periodically collects all the free blocks and inserts into free-pool  Any technique that does this collection is called garbage collection
  • 24. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 24  There are two implementation of linked linear list; array and pointers  There is a need is of such a data structure which can dynamically shrink and grow  Hence the popular implementation us using pointers and dynamic memory management  Singly linked lists are useful data structures, especially if you need to automatically allocate and de-allocate space in a list  The basic operation are create list, transverse the list, insert and delete a node  There are two variation of linked list singly and doubly linked list. Both linked list can be circular lists  The linked could be with or without head node. Head node is used to store some information about the list, so that it can be accessed without traversing the same
  • 25. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 25  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 the node  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.  Information could be like total number of nodes in the list and similarly any other Linked list is the most popular data structure used. It has many application such as process queue, print queue, garbage collection etc
  • 26. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 26 End of Chapter 6 …!