SlideShare a Scribd company logo
1 of 12
Lists, Stacks, and Queues
Third Week: Data Structures and Algorithms
Agenda
• Overview the concept of Abstract Data Types (ADT)
• Operations on Lists
• Stack and how to use it in recursions
• Queue and how to use it in operating systems and algorithm design
Sains Data - UNS 2
Abstract Data Types (ADTs)
• ADT is a collection of objects with their set of operations.
• ADTs consists of lists, sets, and graphs, and their respective operations just
as integers, reals, and booleans.
• So, the set of ADTs, typically have such operations such as add, remove,
and contains.
• Using Java, we can implement ADTs to perform an operation on the ADT.
• The three data structures (Lists, Stacks, and Queues) are the typical/usual
example of ADTs.
• We can use those ADTs in several ways. But once we use the ADTs correctly,
we don’t need to how to implement them (ADTs).
Sains Data - UNS 3
The List
• The basic form of a list is 𝐴0, 𝐴1, 𝐴2, … , 𝐴𝑁−1 with the size of this list
is N.
• If 𝑵 = 𝟎, we call this list as an empty list.
• For simplifications, we will assume that the elements of lists are in
integers. Although, complex elements are allowed.
• Here, we will discuss two types of lists, which are:
• Simple Implementation of Lists: Array and Linked Lists
• Lists in Java Collection API
• ArrayList implementation
Sains Data - UNS 4
Simple Linked Lists
• To prevent linear cost of insertion and deletion, we need to save
lists next to each other.
• Linked lists have a series of nodes.
• Each of those nodes contains the element and a link to a node
from the next successor.
Sains Data - UNS 5
General concepts of linked list -- Picture taken from (Weiss, 2012)
Head
Predeces
sor of X
Node
X
Successo
r of X
tail
Simple Linked Lists: remove and insert
methods
• The remove method can be executed in one next reference change.
• Next, the insert method needs a new node from the system by using a
new call and then executing two reference maneuvers.
Sains Data - UNS 6
Lists in the Java Collections API
• Collection interface:
• Resides in package java.util.
• Iterators:
• Any collection implements Iteratable, must have a method with a name of
iterator that returns an object of type Iterator.
• There are tow popular implementation of List ADT:
• ArrayList: growable array implementation with constant get and set time. But,
very expensive to insert or remove an item.
• LinkedList: double List Implementation of the List ADT.
Sains Data - UNS 7
Operations of ArrayList and LinkedList
• To create/destroy a list
• To expand/shrink the list
• Read/write operations
• Changing the existing node
• Get the current position in the list
• Get the status of the list
Sains Data - UNS 8
Stack
• A stack is a list with the restriction that insertions and deletions can
be performed in only one position, such as the end of the list, top.
• There are 2 operations on a stack, which are push (to insert) and pop
(delete the most recent element).
• Stacks sometimes are known as LIFO (last in, first out).
Sains Data - UNS 9
Operations of Stacks
• Stack_empty(S): Check if the stack is empty  return true
• Stack_full(S): Check if the stack is full return true
• Push(S, e): save item e into S whenever a place is still available
• Pop(S): get the last item stored in S (this item is considered as the last
item/element/top element) if S is not empty.
Sains Data - UNS 10
Queue
• Queues are list, where insertion is done at one end, and deletion is
performed at the other end.
Sains Data - UNS 11
References:
• Mark Allen Weiss, 2012, Data Structures and Algorithm Analysis in
Java, 3rd edition.
• GeeksforGeeks
Sains Data - UNS 12

More Related Content

Similar to Lists, Stacks, and Queues: Abstract Data Types

linked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentslinked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentsSazzadulIslam42
 
mbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxmbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxjotaro11
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power pMeghaKulkarni27
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfKamranAli649587
 
introduction_dst.pptx
introduction_dst.pptxintroduction_dst.pptx
introduction_dst.pptxHammadTariq51
 
Standard template library
Standard template libraryStandard template library
Standard template librarySukriti Singh
 
Data Structures and Algorithms - Lec 05.pptx
Data Structures and Algorithms - Lec 05.pptxData Structures and Algorithms - Lec 05.pptx
Data Structures and Algorithms - Lec 05.pptxRameshaFernando2
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptxBlueSwede
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptxAnuJoseph95
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyMalikireddy Bramhananda Reddy
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)Elavarasi K
 
unit-ids17-180709051413-1.pdf
unit-ids17-180709051413-1.pdfunit-ids17-180709051413-1.pdf
unit-ids17-180709051413-1.pdfKarthiKeyan326587
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTSwapnil Mishra
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1blessyboban92
 

Similar to Lists, Stacks, and Queues: Abstract Data Types (20)

STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
linked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentslinked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate students
 
mbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxmbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptx
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power p
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
 
introduction_dst.pptx
introduction_dst.pptxintroduction_dst.pptx
introduction_dst.pptx
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
Linked list (1).pptx
Linked list (1).pptxLinked list (1).pptx
Linked list (1).pptx
 
Data Structures and Algorithms - Lec 05.pptx
Data Structures and Algorithms - Lec 05.pptxData Structures and Algorithms - Lec 05.pptx
Data Structures and Algorithms - Lec 05.pptx
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
unit-ids17-180709051413-1.pdf
unit-ids17-180709051413-1.pdfunit-ids17-180709051413-1.pdf
unit-ids17-180709051413-1.pdf
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 

Recently uploaded

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
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
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
(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
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 

Recently uploaded (20)

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 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
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
(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...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 

Lists, Stacks, and Queues: Abstract Data Types

  • 1. Lists, Stacks, and Queues Third Week: Data Structures and Algorithms
  • 2. Agenda • Overview the concept of Abstract Data Types (ADT) • Operations on Lists • Stack and how to use it in recursions • Queue and how to use it in operating systems and algorithm design Sains Data - UNS 2
  • 3. Abstract Data Types (ADTs) • ADT is a collection of objects with their set of operations. • ADTs consists of lists, sets, and graphs, and their respective operations just as integers, reals, and booleans. • So, the set of ADTs, typically have such operations such as add, remove, and contains. • Using Java, we can implement ADTs to perform an operation on the ADT. • The three data structures (Lists, Stacks, and Queues) are the typical/usual example of ADTs. • We can use those ADTs in several ways. But once we use the ADTs correctly, we don’t need to how to implement them (ADTs). Sains Data - UNS 3
  • 4. The List • The basic form of a list is 𝐴0, 𝐴1, 𝐴2, … , 𝐴𝑁−1 with the size of this list is N. • If 𝑵 = 𝟎, we call this list as an empty list. • For simplifications, we will assume that the elements of lists are in integers. Although, complex elements are allowed. • Here, we will discuss two types of lists, which are: • Simple Implementation of Lists: Array and Linked Lists • Lists in Java Collection API • ArrayList implementation Sains Data - UNS 4
  • 5. Simple Linked Lists • To prevent linear cost of insertion and deletion, we need to save lists next to each other. • Linked lists have a series of nodes. • Each of those nodes contains the element and a link to a node from the next successor. Sains Data - UNS 5 General concepts of linked list -- Picture taken from (Weiss, 2012) Head Predeces sor of X Node X Successo r of X tail
  • 6. Simple Linked Lists: remove and insert methods • The remove method can be executed in one next reference change. • Next, the insert method needs a new node from the system by using a new call and then executing two reference maneuvers. Sains Data - UNS 6
  • 7. Lists in the Java Collections API • Collection interface: • Resides in package java.util. • Iterators: • Any collection implements Iteratable, must have a method with a name of iterator that returns an object of type Iterator. • There are tow popular implementation of List ADT: • ArrayList: growable array implementation with constant get and set time. But, very expensive to insert or remove an item. • LinkedList: double List Implementation of the List ADT. Sains Data - UNS 7
  • 8. Operations of ArrayList and LinkedList • To create/destroy a list • To expand/shrink the list • Read/write operations • Changing the existing node • Get the current position in the list • Get the status of the list Sains Data - UNS 8
  • 9. Stack • A stack is a list with the restriction that insertions and deletions can be performed in only one position, such as the end of the list, top. • There are 2 operations on a stack, which are push (to insert) and pop (delete the most recent element). • Stacks sometimes are known as LIFO (last in, first out). Sains Data - UNS 9
  • 10. Operations of Stacks • Stack_empty(S): Check if the stack is empty  return true • Stack_full(S): Check if the stack is full return true • Push(S, e): save item e into S whenever a place is still available • Pop(S): get the last item stored in S (this item is considered as the last item/element/top element) if S is not empty. Sains Data - UNS 10
  • 11. Queue • Queues are list, where insertion is done at one end, and deletion is performed at the other end. Sains Data - UNS 11
  • 12. References: • Mark Allen Weiss, 2012, Data Structures and Algorithm Analysis in Java, 3rd edition. • GeeksforGeeks Sains Data - UNS 12