SlideShare una empresa de Scribd logo
1 de 52
VELAMMAL ENGINEERING COLLEGE
An Autonomous Institution, Affiliated to Anna University Chennai, & Approved by AICTE Delhi
Department of Computer Science and
Engineering
UNIT 1 - LINEARDATASTRUCTURES–
LIST
Dr.M.Usha, AP
List ADT
Mrs. G. Sumathi
Assistant Professor
Velammal Engineering College
Chennai
Agenda
• Introduction to Data Structures
• List ADT
• Issues in Array Implementation
• Linked List Representation
• Types
• Applications of Linked List
Introduction to Data Structures
Data
Values or set of values
of different data types
such as int, float, etc.,
Way of organizing and
storing information so
that it is easy to use
Structure
Data + Structure
Way of organizing and
storing data on a computer
so that it can be used easily
and effectively
Introduction to Data Structures
Definition:
Data Structure is a way of organizing,
storing and retrieving data and their relationships
with each other
Classification of Data Structures
Data Structure
Primitive
int char float boolean
Non - Primitive
Linear
Array Linked List Stack Queue
Non - Linear
Tree Graph
• It is a type for objects whose behavior is defined by set of
values and set of operations from user point of view
• Mentions only what operations are to be performed but
not how they will be implemented
• Thus, ADT is the specification of a data type within some
language, independent of implementation
ADT – Abstract Data Type
Examples – List ADT, Stack ADT, Queue ADT, etc.,
Some operations on these ADT are:
List:
• insert(x)
• delete(x)
• find(x)
Stack:
• Push (x)
• Pop()
• isFull()
• isEmpty()
Queue:
• enqueue()
• dequeue()
• isFull()
• isEmpty()
ADT – Abstract Data Type
• List ADT can be represented in two ways
– Array
– Linked List
List ADT
• Collection of elements of same data type
• Elements in an array is stored in adjacent memory
location
Syntax:
• datatype arrayname [size]
• Eg: int a [50];
Operations:
• insertion()
• deletion()
• search()
Array ADT
• Fixed size: Resizing is expensive
• Requires continuous memory for allocation
– Difficult when array size is larger
• Insertions and deletions are inefficient
– Elements are usually shifted
• Wastage of memory space unless the array is
full
Issues in Array
• Linked list is a linear data structure
• Made up of chain of nodes
• Each node contains a data and a pointer to the next
node in the chain
• Last node of the list is pointed to NULL
Linked List ADT
• Each node contains two fields:
– Data field: Contains data element to be stored
– Pointer field: Contains the address of next node
Representation of Node in Linked List
Declaration of a node:
struct node
{
int data;
struct node *next;
};
• Singly linked list
• Doubly linked list
• Circular linked list
Types of Linked List
• Type of linked list
• Each node contains only one pointer field that
contains the address of the next node in the list
Singly Linked List (SLL)
Statement to create a node:
n= (struct node*) malloc(sizeof(sturct node))
Creating a Node
struct node
{
int data;
struct node *next;
} *n;
Major operations are:
• Insertion
– At the beginning
– At the middle
– At the end
• Deletion
– At the beginning
– At the middle
– At the end
• Search
Operations on Singly Linked List
Global declaration of a
Node:
struct node
{
int data;
struct node *next;
} *head, *tail, *n, *t;
Routine for Insertion at the Beginning
void ins_beg (int num) //Let num=10
{
n=(struct node *) malloc (size of(struct node));
nnext=NULL;
ndata=num;
if (head==NULL) //case 1
{
head=n;
tail=n;
}
else //case 2
{
nnext=head;
head=n;
}
}
10
Routine for Insertion at the End
void ins_end (int num) //Let num=10
{
n=(struct node *) malloc (size of(struct node));
nnext=NULL;
ndata=num;
if (head==NULL) //case 1
{
head=n;
tail=n;
}
else //case 2
{
tailnext=n;
tail=n;
}
}
10
Routine for Insertion at the Middle
void ins_end (int num, int mid_data) //Let num=10, mid_data=9
{
n=(struct node *) malloc (size of(struct node));
nnext=NULL;
ndata=num;
for(t=head; t!=NULL; t=tnext)
{
if(tdata==mid_data)
break;
}
nnext=tnext;
tnext=n;
}
10
83==9 ? NO 9==9 ? Yes
10
300
300
1500
300
Routine for Deletion at the Beginning
void del_beg ()
{
t=head;
head=tnext;
free(t);
}
Routine for Deletion at the End
void del_end ()
{
struct node *tp;
t=head;
while(tnext!=NULL)
{
tp=t;
t=tnext;
}
tail=tp;
tailnext=NULL;
free(t);
}
Routine for Deletion at the Middle
void del_mid (int num) //Let num=70
{
struct node *tp;
t=head;
while(tdata!=num)
{
tp=t;
t=tnext;
}
tpnext=tnext;
free(t);
}
2800
83!=70? Yes 9!=70? Yes 70!=70? No
1500
Routine for Search an Element
struct node* search (int num) //Let num=9
{
t=head;
while(t!=NULL && tdata!=num)
{
t=tnext;
}
return t;
}
t!=NULL? Yes
83!=9? Yes
t!=NULL? Yes
9!=9? No
Element Found!!
Linked List – Advantages & Disadvantages
Advantages:
• No wastage of memory
– Memory allocated and deallocated as per
requirement
• Efficient insertion and deletion operations
Disadvantages:
• Occupies more space than array to store a data
– Due to the need of a pointer to the next node
• Does not support random or direct access
Doubly Linked List (DLL)
• Type of linked list
• Each node contains two pointer fields that contains
the address of the next node and that of previous
node in the list
• Each node contains three fields:
– Data: Contains data element to be stored
– next: Contains the address of next node
– prev: Contains address of previous node
Representation of Node in DLL
Declaration of a node:
struct node
{
int data;
struct node *next, *prev;
};
A Node in DLL
Major operations are:
• Insertion
– At the beginning
– At the middle
– At the end
• Deletion
– At the beginning
– At the middle
– At the end
• Search
Operations on Doubly Linked List
Global declaration of a Node:
struct node
{
int data;
struct node *next, prev;
} *head, *tail, *n, *t;
Routine for Insertion at the Beginning
void ins_beg_dll (int num) //Let num=70
{
n=(struct node *) malloc(size of(struct node));
nnext=NULL;
nprev=NULL;
ndata=num;
if(head==NULL) //case 1
{
head=n;
tail=n;
}
else //case 2
{
nnext=head;
headprev=n;
head=n;
}
}
70
500
1000
void ins_end_dll (int num) //Let num=10
{
n=(struct node *) malloc (size of(struct node));
nnext=NULL;
nprev=NULL;
ndata=num;
if (head==NULL) //case 1
{
head=n;
tail=n;
}
else //case 2
{
tailnext=n;
nprev=tail;
tail=n;
}
}
Routine for Insertion at the End
void ins_end_dll (int num, int mid_data) //Let num=10, mid_data=9
{
n=(struct node *) malloc (size of(struct node));
nnext=NULL;
nprev=NULL;
ndata=num;
for(t=head; t!=NULL; t=tnext)
{
if(tdata==mid_data)
break;
}
nnext=tnext;
nprev=t;
tnextprev=n;
tnext=n;
}
Routine for Insertion at the Middle
void del_beg_dll ()
{
t=head;
head=headnext;
headprev=NULL;
free(t);
}
Routine for Deletion at the Beginning
t is freed
Routine for Deletion at the End
void del_end_dll ()
{
t=head;
while(tnext!=NULL)
{
t=tnext;
}
tail=tailprev;//tail=tprev;
tailnext=NULL;
free(t);
}
Routine for Deletion at the Middle
void del_mid_dll (int num) //Let num=9
{
t=head;
while(tdata!=num)
{
tp=t;
t=tnext;
}
tprevnext=tnext;
tnextprev=tprev;
free(t);
}
Routine for Search an Element
struct node* search_dll (int num) //Let num=9
{
t=head;
while(t!=NULL && tdata!=num)
{
t=tnext;
}
return t;
}
Element Found!!
t is returned
Advantages:
• Can traverse in both directions
• Operations in the middle of the list can be done
efficiently
– No need of extra pointer (tp) to track the previous
node
• Reversing the list is easy
Disadvantage:
• Space required to store a data is even more higher
than SLL
– Due to the use of two pointers
DLL – Advantages & Disadvantages
• Type of linked list
• The last node will be pointing to the first node
• It can be either singly or doubly linked
Circular Linked List (CLL)
Global declaration of a node:
struct node
{
int data;
struct node *next, *prev;
}*head,*n,*t;
100
Routine for Insertion at the Beginning
void ins_beg_cll (int num) //Let num=10
{
n=(struct node *) malloc (size of(struct node));
nnext=NULL;
ndata=num;
if (head==NULL) //case 1
{ head=n;
nnext=head;
}
else //case 2
{ t=head;
while(tnext!=head)
t=tnext;
tnext=n;
nnext=head;
head=n;
}
}
10
10 100
Routine for Insertion at the End
void ins_end_cll (int num) //Let num=10
{
n=(struct node *) malloc (size of(struct node));
nnext=NULL;
ndata=num;
t=head;
while(tnext!=head)
t=tnext;
tnext=n;
nnext=head;
}
10
1000
Routine for Insertion at the Middle
void ins_end_cll (int num, int mid_data) //Let num=10, mid_data=9
{
n=(struct node *) malloc (size of(struct node));
nnext=NULL;
ndata=num;
for(t=head; tnext!=head; t=tnext)
{
if(tdata==mid_data)
break;
}
nnext=tnext;
tnext=n;
}
10
1000
Routine for Deletion at the Beginning
void del_beg_cll ()
{
struct node *t1;
t=head;
t1=head;
while(tnext!=head)
t=tnext;
tnext=headnext;
head=tnext;
free(t1);
} 100
t1 is freed!!
Routine for Deletion at the End
void del_end_cll ()
{
struct node *tp;
t=head;
while(tnext!=head)
{
tp=t;
t=tnext;
}
tpnext=head;
free(t);
}
100
t is freed !!
Routine for Deletion at the Middle
void del_mid_cll (int num) //Let num=9
{
struct node *tp;
t=head;
while(tdata!=num)
{
tp=t;
t=tnext;
}
tpnext=tnext;
free(t);
} t is freed!!
Routine for Search
struct node* search_cll (int num) //Let num=9
{
t=head;
while(tnext!=head && tdata!=num)
{
t=tnext;
}
return t;
}
Advantage:
• Comparing to SLL, moving to any node from a node is
possible
Disadvantages:
• Reversing a list is complex compared to linear linked
list
• If proper care is not taken in managing the pointers,
it leads to infinite loop
• Moving to previous node is difficult, as it is needed
to complete an entire circle
CLL – Advantages & Disadvantages
Applications of List
Lists can be used to
• Sort elements
• Implement stack and queue
• Represent graph (adjacent list representation)
• Implement hash table
• Implement multiprocessing of applications
• Manipulate polynomial equations
Polynomial ADT
struct node
{
int coeff;
int pow;
struct node *next;
}*n;
Examples of polynomial equations:
– 9x5 + 7x3 – 4x2 + 8
7x4 – 17x3 – 8x2
To store the data of polynomial equations in the linked
list, each node contains two data fields, namely
coefficient and power and one next pointer field
Creating a Polynomial List
struct node* createpoly (int c, int p, struct node *t)
{
struct node *head, *tail;
head=t;
n=(struct node*) malloc(size of(struct node));
ncoeff=c;
npow=p;
nnext=NULL;
if (head==NULL)
{ head=n;
tail=n;
}
else
{ tailnext=n;
tail=n;
}
return head;
}
Polynomial Addition
Void addpoly (struct node *poly1, struct node *poly2, struct node *poly)
{
while(ploy1!=NULL && poly2!=NULL)
{
if(poly1pow>poly2pow)
{
polypow=ploy1pow;
polycoeff=poly1coeff;
ploy1=poly1next;
}
else if(poly1pow < poly2pow)
{
polypow=ploy2pow;
polycoeff=poly2coeff;
ploy2=poly2next;
}
else
{ polypow=ploy1pow;
polycoeff=poly1coeff + poly2coeff;
ploy1=poly1next;
ploy2=poly2next;
}
}
while(poly1 != NULL || poly2 != NULL)
{ if (poly1 != NULL)
{ polypow=ploy1pow;
polycoeff=poly1coeff;
ploy1=poly1next;
}
if (poly2 != NULL)
{ polypow=ploy2pow;
polycoeff=poly2coeff;
ploy2=poly2next;
}
}
}
Polynomial Addition Contd.,
Queries ??
Thank You!!!

Más contenido relacionado

La actualidad más candente

Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)Elavarasi K
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsAfaq Mansoor Khan
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES Kathirvel Ayyaswamy
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structureVardhil Patel
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structuresDurgaDeviCbit
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Anand Ingle
 

La actualidad más candente (20)

Stack
StackStack
Stack
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Data structures
Data structuresData structures
Data structures
 
BINARY SEARCH TREE
BINARY SEARCH TREE BINARY SEARCH TREE
BINARY SEARCH TREE
 
Tree
TreeTree
Tree
 
Binary tree
Binary tree Binary tree
Binary tree
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
stack & queue
stack & queuestack & queue
stack & queue
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Linked list
Linked listLinked list
Linked list
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Stack
StackStack
Stack
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
 

Similar a Unit 1 LINEAR DATA STRUCTURES

UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptxjack881
 
Data Structures - Unit 1 linked list
Data Structures - Unit 1 linked listData Structures - Unit 1 linked list
Data Structures - Unit 1 linked listRajeswariA8
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocationkiran Patel
 
What is Linked List in C.docx
What is Linked List in C.docxWhat is Linked List in C.docx
What is Linked List in C.docxnona800027
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
Data structure
Data structureData structure
Data structureNida Ahmed
 
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
 
Unit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfUnit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfKanchanPatil34
 
What is Link list? explained with animations
What is Link list? explained with animationsWhat is Link list? explained with animations
What is Link list? explained with animationsPratikNaik41
 

Similar a Unit 1 LINEAR DATA STRUCTURES (20)

UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptx
 
Data Structures - Unit 1 linked list
Data Structures - Unit 1 linked listData Structures - Unit 1 linked list
Data Structures - Unit 1 linked list
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocation
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
What is Linked List in C.docx
What is Linked List in C.docxWhat is Linked List in C.docx
What is Linked List in C.docx
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Data structure
Data structureData structure
Data structure
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Unit II Data Structure 2hr topic - List - Operations.pptx
Unit II  Data Structure 2hr topic - List - Operations.pptxUnit II  Data Structure 2hr topic - List - Operations.pptx
Unit II Data Structure 2hr topic - List - Operations.pptx
 
Team 10
Team 10Team 10
Team 10
 
Linked list
Linked list Linked list
Linked list
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
 
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...
 
1st lecture.ppt
1st lecture.ppt1st lecture.ppt
1st lecture.ppt
 
Unit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfUnit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdf
 
What is Link list? explained with animations
What is Link list? explained with animationsWhat is Link list? explained with animations
What is Link list? explained with animations
 

Último

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 

Último (20)

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 

Unit 1 LINEAR DATA STRUCTURES

  • 1. VELAMMAL ENGINEERING COLLEGE An Autonomous Institution, Affiliated to Anna University Chennai, & Approved by AICTE Delhi Department of Computer Science and Engineering UNIT 1 - LINEARDATASTRUCTURES– LIST Dr.M.Usha, AP
  • 2. List ADT Mrs. G. Sumathi Assistant Professor Velammal Engineering College Chennai
  • 3. Agenda • Introduction to Data Structures • List ADT • Issues in Array Implementation • Linked List Representation • Types • Applications of Linked List
  • 4. Introduction to Data Structures Data Values or set of values of different data types such as int, float, etc., Way of organizing and storing information so that it is easy to use Structure Data + Structure Way of organizing and storing data on a computer so that it can be used easily and effectively
  • 5. Introduction to Data Structures Definition: Data Structure is a way of organizing, storing and retrieving data and their relationships with each other
  • 6. Classification of Data Structures Data Structure Primitive int char float boolean Non - Primitive Linear Array Linked List Stack Queue Non - Linear Tree Graph
  • 7. • It is a type for objects whose behavior is defined by set of values and set of operations from user point of view • Mentions only what operations are to be performed but not how they will be implemented • Thus, ADT is the specification of a data type within some language, independent of implementation ADT – Abstract Data Type
  • 8. Examples – List ADT, Stack ADT, Queue ADT, etc., Some operations on these ADT are: List: • insert(x) • delete(x) • find(x) Stack: • Push (x) • Pop() • isFull() • isEmpty() Queue: • enqueue() • dequeue() • isFull() • isEmpty() ADT – Abstract Data Type
  • 9. • List ADT can be represented in two ways – Array – Linked List List ADT
  • 10. • Collection of elements of same data type • Elements in an array is stored in adjacent memory location Syntax: • datatype arrayname [size] • Eg: int a [50]; Operations: • insertion() • deletion() • search() Array ADT
  • 11. • Fixed size: Resizing is expensive • Requires continuous memory for allocation – Difficult when array size is larger • Insertions and deletions are inefficient – Elements are usually shifted • Wastage of memory space unless the array is full Issues in Array
  • 12. • Linked list is a linear data structure • Made up of chain of nodes • Each node contains a data and a pointer to the next node in the chain • Last node of the list is pointed to NULL Linked List ADT
  • 13. • Each node contains two fields: – Data field: Contains data element to be stored – Pointer field: Contains the address of next node Representation of Node in Linked List Declaration of a node: struct node { int data; struct node *next; };
  • 14. • Singly linked list • Doubly linked list • Circular linked list Types of Linked List
  • 15. • Type of linked list • Each node contains only one pointer field that contains the address of the next node in the list Singly Linked List (SLL)
  • 16. Statement to create a node: n= (struct node*) malloc(sizeof(sturct node)) Creating a Node struct node { int data; struct node *next; } *n;
  • 17. Major operations are: • Insertion – At the beginning – At the middle – At the end • Deletion – At the beginning – At the middle – At the end • Search Operations on Singly Linked List Global declaration of a Node: struct node { int data; struct node *next; } *head, *tail, *n, *t;
  • 18. Routine for Insertion at the Beginning void ins_beg (int num) //Let num=10 { n=(struct node *) malloc (size of(struct node)); nnext=NULL; ndata=num; if (head==NULL) //case 1 { head=n; tail=n; } else //case 2 { nnext=head; head=n; } } 10
  • 19. Routine for Insertion at the End void ins_end (int num) //Let num=10 { n=(struct node *) malloc (size of(struct node)); nnext=NULL; ndata=num; if (head==NULL) //case 1 { head=n; tail=n; } else //case 2 { tailnext=n; tail=n; } } 10
  • 20. Routine for Insertion at the Middle void ins_end (int num, int mid_data) //Let num=10, mid_data=9 { n=(struct node *) malloc (size of(struct node)); nnext=NULL; ndata=num; for(t=head; t!=NULL; t=tnext) { if(tdata==mid_data) break; } nnext=tnext; tnext=n; } 10 83==9 ? NO 9==9 ? Yes 10 300 300 1500 300
  • 21. Routine for Deletion at the Beginning void del_beg () { t=head; head=tnext; free(t); }
  • 22. Routine for Deletion at the End void del_end () { struct node *tp; t=head; while(tnext!=NULL) { tp=t; t=tnext; } tail=tp; tailnext=NULL; free(t); }
  • 23. Routine for Deletion at the Middle void del_mid (int num) //Let num=70 { struct node *tp; t=head; while(tdata!=num) { tp=t; t=tnext; } tpnext=tnext; free(t); } 2800 83!=70? Yes 9!=70? Yes 70!=70? No 1500
  • 24. Routine for Search an Element struct node* search (int num) //Let num=9 { t=head; while(t!=NULL && tdata!=num) { t=tnext; } return t; } t!=NULL? Yes 83!=9? Yes t!=NULL? Yes 9!=9? No Element Found!!
  • 25. Linked List – Advantages & Disadvantages Advantages: • No wastage of memory – Memory allocated and deallocated as per requirement • Efficient insertion and deletion operations Disadvantages: • Occupies more space than array to store a data – Due to the need of a pointer to the next node • Does not support random or direct access
  • 26. Doubly Linked List (DLL) • Type of linked list • Each node contains two pointer fields that contains the address of the next node and that of previous node in the list
  • 27. • Each node contains three fields: – Data: Contains data element to be stored – next: Contains the address of next node – prev: Contains address of previous node Representation of Node in DLL Declaration of a node: struct node { int data; struct node *next, *prev; }; A Node in DLL
  • 28. Major operations are: • Insertion – At the beginning – At the middle – At the end • Deletion – At the beginning – At the middle – At the end • Search Operations on Doubly Linked List Global declaration of a Node: struct node { int data; struct node *next, prev; } *head, *tail, *n, *t;
  • 29. Routine for Insertion at the Beginning void ins_beg_dll (int num) //Let num=70 { n=(struct node *) malloc(size of(struct node)); nnext=NULL; nprev=NULL; ndata=num; if(head==NULL) //case 1 { head=n; tail=n; } else //case 2 { nnext=head; headprev=n; head=n; } } 70 500 1000
  • 30. void ins_end_dll (int num) //Let num=10 { n=(struct node *) malloc (size of(struct node)); nnext=NULL; nprev=NULL; ndata=num; if (head==NULL) //case 1 { head=n; tail=n; } else //case 2 { tailnext=n; nprev=tail; tail=n; } } Routine for Insertion at the End
  • 31. void ins_end_dll (int num, int mid_data) //Let num=10, mid_data=9 { n=(struct node *) malloc (size of(struct node)); nnext=NULL; nprev=NULL; ndata=num; for(t=head; t!=NULL; t=tnext) { if(tdata==mid_data) break; } nnext=tnext; nprev=t; tnextprev=n; tnext=n; } Routine for Insertion at the Middle
  • 33. Routine for Deletion at the End void del_end_dll () { t=head; while(tnext!=NULL) { t=tnext; } tail=tailprev;//tail=tprev; tailnext=NULL; free(t); }
  • 34. Routine for Deletion at the Middle void del_mid_dll (int num) //Let num=9 { t=head; while(tdata!=num) { tp=t; t=tnext; } tprevnext=tnext; tnextprev=tprev; free(t); }
  • 35. Routine for Search an Element struct node* search_dll (int num) //Let num=9 { t=head; while(t!=NULL && tdata!=num) { t=tnext; } return t; } Element Found!! t is returned
  • 36. Advantages: • Can traverse in both directions • Operations in the middle of the list can be done efficiently – No need of extra pointer (tp) to track the previous node • Reversing the list is easy Disadvantage: • Space required to store a data is even more higher than SLL – Due to the use of two pointers DLL – Advantages & Disadvantages
  • 37. • Type of linked list • The last node will be pointing to the first node • It can be either singly or doubly linked Circular Linked List (CLL) Global declaration of a node: struct node { int data; struct node *next, *prev; }*head,*n,*t; 100
  • 38. Routine for Insertion at the Beginning void ins_beg_cll (int num) //Let num=10 { n=(struct node *) malloc (size of(struct node)); nnext=NULL; ndata=num; if (head==NULL) //case 1 { head=n; nnext=head; } else //case 2 { t=head; while(tnext!=head) t=tnext; tnext=n; nnext=head; head=n; } } 10 10 100
  • 39. Routine for Insertion at the End void ins_end_cll (int num) //Let num=10 { n=(struct node *) malloc (size of(struct node)); nnext=NULL; ndata=num; t=head; while(tnext!=head) t=tnext; tnext=n; nnext=head; } 10 1000
  • 40. Routine for Insertion at the Middle void ins_end_cll (int num, int mid_data) //Let num=10, mid_data=9 { n=(struct node *) malloc (size of(struct node)); nnext=NULL; ndata=num; for(t=head; tnext!=head; t=tnext) { if(tdata==mid_data) break; } nnext=tnext; tnext=n; } 10 1000
  • 41. Routine for Deletion at the Beginning void del_beg_cll () { struct node *t1; t=head; t1=head; while(tnext!=head) t=tnext; tnext=headnext; head=tnext; free(t1); } 100 t1 is freed!!
  • 42. Routine for Deletion at the End void del_end_cll () { struct node *tp; t=head; while(tnext!=head) { tp=t; t=tnext; } tpnext=head; free(t); } 100 t is freed !!
  • 43. Routine for Deletion at the Middle void del_mid_cll (int num) //Let num=9 { struct node *tp; t=head; while(tdata!=num) { tp=t; t=tnext; } tpnext=tnext; free(t); } t is freed!!
  • 44. Routine for Search struct node* search_cll (int num) //Let num=9 { t=head; while(tnext!=head && tdata!=num) { t=tnext; } return t; }
  • 45. Advantage: • Comparing to SLL, moving to any node from a node is possible Disadvantages: • Reversing a list is complex compared to linear linked list • If proper care is not taken in managing the pointers, it leads to infinite loop • Moving to previous node is difficult, as it is needed to complete an entire circle CLL – Advantages & Disadvantages
  • 46. Applications of List Lists can be used to • Sort elements • Implement stack and queue • Represent graph (adjacent list representation) • Implement hash table • Implement multiprocessing of applications • Manipulate polynomial equations
  • 47. Polynomial ADT struct node { int coeff; int pow; struct node *next; }*n; Examples of polynomial equations: – 9x5 + 7x3 – 4x2 + 8 7x4 – 17x3 – 8x2 To store the data of polynomial equations in the linked list, each node contains two data fields, namely coefficient and power and one next pointer field
  • 48. Creating a Polynomial List struct node* createpoly (int c, int p, struct node *t) { struct node *head, *tail; head=t; n=(struct node*) malloc(size of(struct node)); ncoeff=c; npow=p; nnext=NULL; if (head==NULL) { head=n; tail=n; } else { tailnext=n; tail=n; } return head; }
  • 49. Polynomial Addition Void addpoly (struct node *poly1, struct node *poly2, struct node *poly) { while(ploy1!=NULL && poly2!=NULL) { if(poly1pow>poly2pow) { polypow=ploy1pow; polycoeff=poly1coeff; ploy1=poly1next; } else if(poly1pow < poly2pow) { polypow=ploy2pow; polycoeff=poly2coeff; ploy2=poly2next; }
  • 50. else { polypow=ploy1pow; polycoeff=poly1coeff + poly2coeff; ploy1=poly1next; ploy2=poly2next; } } while(poly1 != NULL || poly2 != NULL) { if (poly1 != NULL) { polypow=ploy1pow; polycoeff=poly1coeff; ploy1=poly1next; } if (poly2 != NULL) { polypow=ploy2pow; polycoeff=poly2coeff; ploy2=poly2next; } } } Polynomial Addition Contd.,

Notas del editor

  1. If element not found, t=NULL, so NULL will be returned
  2. In CLL, ins at begin and ins at end are almost same with a difference that n will not be assigned as head in ins at end
  3. Multiprocessing of applications – all the applications will be stored in nodes of the list. OS has a fixed time for running each application