SlideShare a Scribd company logo
Name:-Sunipa Bera
B. Tech CSE (CSF)
Roll No. :-17
Subject: DS
Prn No.: 190105181016
Topic:- Stack & Queue
Stack
&
Queue
What is a
Stack?
A stack is a data structure of ordered items suc
h that items can be inserted and removed only
at one end.
• A stack is a LIFO (Last-In/ First-Out) data
structure
• A stack is sometimes also called a pushdown
store.
• What are some applications of stacks?
 Program execution
 Parsing
 Evaluating postfix expressions
PUSH
Place an item on the Stack
PEEK
Look at the item on top of the stack, but do not
remove it.
POP
Look at the item on the stack and remove it.
What
can we
do with
Stack?
Stacks
Using a IStack
 A balance of braces.
- (()) balanced braces
- ()(()()))) not balanced braces
 How can you use Istack to check a br
ace is balanced or not?
Interface IStack Answer:
Problem
When you implement the above requirement, you ignore the implementation details of Istack.
What happens if we try to pop an item off the stack
when the stack is empty?
This is called a stack underflow. The
pop method needs some way of telling
us that this has happened. In java we
use the
java.util.EmptyStackException
Interface Istack
{
boolean empty();
void push(char c);
char pop();
char peek();
}
Implementing a
stack using an
array is fairly easy.
• The bottom of the stack is at
data[0]
• The top of the stack is at
data[numItems-1]
• push onto the stack at
data[numItems]
• pop off of the stack at
data[numItems-1]
Implementing a
stack using a
linked list isn’t
that bad either…
• Store the items in the stack in a linked
list
• The top of the stack is the head node,
the bottom of the stack is the end of
the list
• push by adding to the front of the list
• pop by removing from the front of the
list
Reversing A Word
We can use a stack to reverse the letters in a word. How?
Read each letter in th
e word and push it o
nto the
stack
When you reach
the end of the
word, pop the
letters off the stack an
d print them out.
What is a
Queue?
A data structure of ordered items such that item
s can be inserted only at one end and removed a
t the other end.
e.g. A line at the supermarket
• A queue is called a FIFO (First in-First out)
data structure.
• What are some applications of queues?
 Round-robin scheduling in processors
 Input/ Output processing
 Queueing of packets for delivery in
networks
What we can do with Queue?
These ops are called insert ant getfront in order to simplify things.
Add an item to the queue.
Enqueue
Remove an item from the
queue
Dequeue
Implementation of
Queue
• Just like a stack, we can implementing a queue in two ways: 1) Using an array
2). Using a linked list.
Problems: Using an array to implement a queue is significantly harder than using
an array to implement a stack. Why?
Solution: Unlike a stack, where we add and remove at the same end, in a queue we
add to one end and remove from the other.
Implementing a queue using a
linked list is still easy:
• Front of the queue is stored as the head node
of the linked list, rear of the queue is stored
as the tail node.
• Enqueue by adding to the end of the list
• Dequeue by removing from the front of the
list.
Infographic Style
Insert the title of your subtitle Here
Option 1
Option 2
Option 2 Sketch of Insert
Option 2 sketch of
getforce
 Enqueue at data[0] and shift all of
the rest of the items in the array
down to make room.
 Dequeue from data[numItems-1]
• Enqueue at data[rear+1]
• Dequeue at data[front]
• The rear variable always contains the
index of the last item in the queue.
• The front variable always contains the
index of the first item in the queue.
• When we reach the end of the array,
wrap around to the front again.
insert(Object item)
{
if(manyItems == 0) front = rear = 0;
else rear = (rear + 1) mod size;
data[rear] = item;
manyItems++;
}
Object getFront()
{
answer = data[front];
front = (front + 1) mod size;
manyItems--;
return answer
Biblography
- W3school
- tutorialspoint
Thank You

More Related Content

What's hot

Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
Muhazzab Chouhadry
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queuesAbbott
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
SnehilKeshari
 
Queues
QueuesQueues
Data Structures
Data StructuresData Structures
Data Structures
Dr.Umadevi V
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
Buxoo Abdullah
 
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
gomathi chlm
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Rabin BK
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Queues in data structures
Queues in data structuresQueues in data structures
Queues in data structures
Edison Tusifu
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
shaik faroq
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structuresDeepa Rani
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Lovely Professional University
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Anil Kumar Prajapati
 
Fp growth algorithm
Fp growth algorithmFp growth algorithm
Fp growth algorithm
Pradip Kumar
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
Selvin Josy Bai Somu
 
Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Stack data structure in Data Structure using C
Stack data structure in Data Structure using C
Meghaj Mallick
 
Data Analysis packages
Data Analysis packagesData Analysis packages
Data Analysis packages
Devashish Kumar
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
Kuber Chandra
 
stack & queue
stack & queuestack & queue
stack & queue
manju rani
 

What's hot (20)

Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
Queues
QueuesQueues
Queues
 
Data Structures
Data StructuresData Structures
Data Structures
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
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
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Queues in data structures
Queues in data structuresQueues in data structures
Queues in data structures
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Fp growth algorithm
Fp growth algorithmFp growth algorithm
Fp growth algorithm
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Stack data structure in Data Structure using C
Stack data structure in Data Structure using C
 
Data Analysis packages
Data Analysis packagesData Analysis packages
Data Analysis packages
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
stack & queue
stack & queuestack & queue
stack & queue
 

Similar to Ds stack & queue

Lecture9_StackQueue.ppt
Lecture9_StackQueue.pptLecture9_StackQueue.ppt
Lecture9_StackQueue.ppt
MuhammadSheraz836877
 
StackQueue.ppt
StackQueue.pptStackQueue.ppt
StackQueue.ppt
AfrozAlamKiVines
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
Muhazzab Chouhadry
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
Dr.Shweta
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Pulkitmodi1998
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
mayankKatiyar17
 
Queues
Queues Queues
Queues
nidhisatija1
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
SeethaDinesh
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
Dr.Shweta
 
ppt.pptx
ppt.pptxppt.pptx
ppt.pptx
SandeepBhuma
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
Ddushb
 
Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...
abhaysingh19149
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
Hasan Mahadi Riaz
 
5.-Stacks.pptx
5.-Stacks.pptx5.-Stacks.pptx
5.-Stacks.pptx
iloveyoucarlo0923
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
LECO9
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
SKUP1
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
skilljiolms
 

Similar to Ds stack & queue (20)

Lecture9_StackQueue.ppt
Lecture9_StackQueue.pptLecture9_StackQueue.ppt
Lecture9_StackQueue.ppt
 
StackQueue.ppt
StackQueue.pptStackQueue.ppt
StackQueue.ppt
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Queues
Queues Queues
Queues
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Data structures
Data structuresData structures
Data structures
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
ppt.pptx
ppt.pptxppt.pptx
ppt.pptx
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
5.-Stacks.pptx
5.-Stacks.pptx5.-Stacks.pptx
5.-Stacks.pptx
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 

More from Sunipa Bera

hackers.pptx
hackers.pptxhackers.pptx
hackers.pptx
Sunipa Bera
 
System tThreats
System tThreatsSystem tThreats
System tThreats
Sunipa Bera
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Sunipa Bera
 
Proposition & Logical Operations
Proposition & Logical OperationsProposition & Logical Operations
Proposition & Logical Operations
Sunipa Bera
 
Integral Calculas
Integral CalculasIntegral Calculas
Integral Calculas
Sunipa Bera
 
Basic concept of Engineering Mechanics
Basic concept of Engineering MechanicsBasic concept of Engineering Mechanics
Basic concept of Engineering Mechanics
Sunipa Bera
 
Biogeographical zones of India
Biogeographical zones of IndiaBiogeographical zones of India
Biogeographical zones of India
Sunipa Bera
 
Inflation
InflationInflation
Inflation
Sunipa Bera
 
Operating System & Application Security
Operating System & Application SecurityOperating System & Application Security
Operating System & Application Security
Sunipa Bera
 
Types of Ecosystem
Types of EcosystemTypes of Ecosystem
Types of Ecosystem
Sunipa Bera
 
Elementary transformation
Elementary transformationElementary transformation
Elementary transformation
Sunipa Bera
 
Emotional Intelligence
Emotional IntelligenceEmotional Intelligence
Emotional Intelligence
Sunipa Bera
 
SKYDRIVE
SKYDRIVESKYDRIVE
SKYDRIVE
Sunipa Bera
 
7 cs of effective communication
7 cs of effective communication 7 cs of effective communication
7 cs of effective communication
Sunipa Bera
 
Basics of microprocessor
Basics of microprocessorBasics of microprocessor
Basics of microprocessor
Sunipa Bera
 
Functioning of computer
Functioning of computerFunctioning of computer
Functioning of computer
Sunipa Bera
 
INDIAN ISLAND STUDIES
INDIAN ISLAND STUDIESINDIAN ISLAND STUDIES
INDIAN ISLAND STUDIES
Sunipa Bera
 
GO GREEN - GO ECOFRIENDLY
GO GREEN - GO ECOFRIENDLYGO GREEN - GO ECOFRIENDLY
GO GREEN - GO ECOFRIENDLY
Sunipa Bera
 
INDIA AND HERITAGE
INDIA AND HERITAGEINDIA AND HERITAGE
INDIA AND HERITAGE
Sunipa Bera
 
Happy birthday.rtf
Happy birthday.rtfHappy birthday.rtf
Happy birthday.rtf
Sunipa Bera
 

More from Sunipa Bera (20)

hackers.pptx
hackers.pptxhackers.pptx
hackers.pptx
 
System tThreats
System tThreatsSystem tThreats
System tThreats
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Proposition & Logical Operations
Proposition & Logical OperationsProposition & Logical Operations
Proposition & Logical Operations
 
Integral Calculas
Integral CalculasIntegral Calculas
Integral Calculas
 
Basic concept of Engineering Mechanics
Basic concept of Engineering MechanicsBasic concept of Engineering Mechanics
Basic concept of Engineering Mechanics
 
Biogeographical zones of India
Biogeographical zones of IndiaBiogeographical zones of India
Biogeographical zones of India
 
Inflation
InflationInflation
Inflation
 
Operating System & Application Security
Operating System & Application SecurityOperating System & Application Security
Operating System & Application Security
 
Types of Ecosystem
Types of EcosystemTypes of Ecosystem
Types of Ecosystem
 
Elementary transformation
Elementary transformationElementary transformation
Elementary transformation
 
Emotional Intelligence
Emotional IntelligenceEmotional Intelligence
Emotional Intelligence
 
SKYDRIVE
SKYDRIVESKYDRIVE
SKYDRIVE
 
7 cs of effective communication
7 cs of effective communication 7 cs of effective communication
7 cs of effective communication
 
Basics of microprocessor
Basics of microprocessorBasics of microprocessor
Basics of microprocessor
 
Functioning of computer
Functioning of computerFunctioning of computer
Functioning of computer
 
INDIAN ISLAND STUDIES
INDIAN ISLAND STUDIESINDIAN ISLAND STUDIES
INDIAN ISLAND STUDIES
 
GO GREEN - GO ECOFRIENDLY
GO GREEN - GO ECOFRIENDLYGO GREEN - GO ECOFRIENDLY
GO GREEN - GO ECOFRIENDLY
 
INDIA AND HERITAGE
INDIA AND HERITAGEINDIA AND HERITAGE
INDIA AND HERITAGE
 
Happy birthday.rtf
Happy birthday.rtfHappy birthday.rtf
Happy birthday.rtf
 

Recently uploaded

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 

Recently uploaded (20)

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 

Ds stack & queue

  • 1. Name:-Sunipa Bera B. Tech CSE (CSF) Roll No. :-17 Subject: DS Prn No.: 190105181016 Topic:- Stack & Queue
  • 3. What is a Stack? A stack is a data structure of ordered items suc h that items can be inserted and removed only at one end. • A stack is a LIFO (Last-In/ First-Out) data structure • A stack is sometimes also called a pushdown store. • What are some applications of stacks?  Program execution  Parsing  Evaluating postfix expressions
  • 4. PUSH Place an item on the Stack PEEK Look at the item on top of the stack, but do not remove it. POP Look at the item on the stack and remove it. What can we do with Stack?
  • 5. Stacks Using a IStack  A balance of braces. - (()) balanced braces - ()(()()))) not balanced braces  How can you use Istack to check a br ace is balanced or not? Interface IStack Answer: Problem When you implement the above requirement, you ignore the implementation details of Istack. What happens if we try to pop an item off the stack when the stack is empty? This is called a stack underflow. The pop method needs some way of telling us that this has happened. In java we use the java.util.EmptyStackException Interface Istack { boolean empty(); void push(char c); char pop(); char peek(); }
  • 6. Implementing a stack using an array is fairly easy. • The bottom of the stack is at data[0] • The top of the stack is at data[numItems-1] • push onto the stack at data[numItems] • pop off of the stack at data[numItems-1] Implementing a stack using a linked list isn’t that bad either… • Store the items in the stack in a linked list • The top of the stack is the head node, the bottom of the stack is the end of the list • push by adding to the front of the list • pop by removing from the front of the list
  • 7. Reversing A Word We can use a stack to reverse the letters in a word. How? Read each letter in th e word and push it o nto the stack When you reach the end of the word, pop the letters off the stack an d print them out.
  • 8. What is a Queue? A data structure of ordered items such that item s can be inserted only at one end and removed a t the other end. e.g. A line at the supermarket • A queue is called a FIFO (First in-First out) data structure. • What are some applications of queues?  Round-robin scheduling in processors  Input/ Output processing  Queueing of packets for delivery in networks
  • 9. What we can do with Queue? These ops are called insert ant getfront in order to simplify things. Add an item to the queue. Enqueue Remove an item from the queue Dequeue
  • 10. Implementation of Queue • Just like a stack, we can implementing a queue in two ways: 1) Using an array 2). Using a linked list. Problems: Using an array to implement a queue is significantly harder than using an array to implement a stack. Why? Solution: Unlike a stack, where we add and remove at the same end, in a queue we add to one end and remove from the other. Implementing a queue using a linked list is still easy: • Front of the queue is stored as the head node of the linked list, rear of the queue is stored as the tail node. • Enqueue by adding to the end of the list • Dequeue by removing from the front of the list.
  • 11. Infographic Style Insert the title of your subtitle Here Option 1 Option 2 Option 2 Sketch of Insert Option 2 sketch of getforce  Enqueue at data[0] and shift all of the rest of the items in the array down to make room.  Dequeue from data[numItems-1] • Enqueue at data[rear+1] • Dequeue at data[front] • The rear variable always contains the index of the last item in the queue. • The front variable always contains the index of the first item in the queue. • When we reach the end of the array, wrap around to the front again. insert(Object item) { if(manyItems == 0) front = rear = 0; else rear = (rear + 1) mod size; data[rear] = item; manyItems++; } Object getFront() { answer = data[front]; front = (front + 1) mod size; manyItems--; return answer