SlideShare uma empresa Scribd logo
1 de 22
STACK AND
QUEUE
M.GOMATHI Lecturer/ Computer
STACKSStack is an abstract data type with a
bounded(predefined) capacity. It is a simple data
structure that allows adding and removing
elements in a particular order. Every time an
element is added, it goes on the top of the stack,
the only element that can be removed is the
element that was at the top of the stack, just like
a pile of objects.
Example for stack
Basic features of Stack
•Stack is an ordered list of similar data type.
•Stack is a LIFO structure. (Last in First out).
•push() function is used to insert new elements
into the Stack and pop() is used to delete an
element from the stack. Both insertion and
deletion are allowed at only one end of Stack
called Top.
•Stack is said to be in Overflow state when it is
completely full and is said to be
in Underflow state if it is completely empty.
Applications of Stack
•The simplest application of a stack is to reverse
a word. You push a given word to stack - letter
by letter - and then pop letters from the stack.
•There are other uses also like
: Parsing, Expression Conversion(Infix to
Postfix, Postfix to Prefix etc) and many more.
Implementation of Stack…
Example
Implementation of Stack
 Stack can be easily implemented using an
Array or a Linked List. Arrays are quick, but
are limited in size and Linked List requires
overhead to allocate, link, unlink, and
deallocate, but is not limited in size. Here we
will implement Stack using array.
Implementation of Stack…
Implementation of Stack…
Position of Top Status of Stack
-1 Stack is Empty
0 Only one element in Stack
N-1 Stack is Full
N Overflow state of Stack
Converting a Complex Expression
to Prefix and Postfix Notations
Here is a more complex expression: (A + B) * C - (D - E) * (F + G). Following figure shows
the conversion to postfix and prefix notations.
Analysis of Stacks
 Below mentioned are the time complexities for
various operations that can be performed on
the Stack data structure.
 Push Operation : O(1)
 Pop Operation : O(1)
 Top Operation : O(1)
 Search Operation : O(n)
QUEUE DATA
STRUCTURES
Example for Queue…
Ticket Counter
Queue is also an abstract data type or a linear
data structure, in which the first element is
inserted from one end called rear(also called
tail), and the deletion of existing element takes
place from the other end called as front(also
called head). This makes queue as FIFO data
structure, which means that element inserted
first will also be removed first.
QUEU
E
 The process to add an element into queue is
called Enqueue and the process of removal of
an element from queue is called Dequeue.
QUEUE…
Implementation of Queue
Implementation of Queue
Basic features of Queue
 Like Stack, Queue is also an ordered list of
elements of similar data types.
 Queue is a FIFO( First in First Out ) structure.
 Once a new element is inserted into the
Queue, all the elements inserted before the
new element in the queue must be removed,
to remove the new element.
 Queue can be implemented using an
Array, Stack or Linked List. The
easiest way of implementing a queue
is by using an Array. Initially
the head(FRONT) and
the tail(REAR) of the queue points at
the first index of the array (starting
the index of array from 0).
Implementation of Queue
Applications of Queue
 Queue, as the name suggests is used whenever
we need to have any group of objects in an order
in which the first one coming in, also gets out first
while the others wait for there turn, like in the
following scenarios :
 Serving requests on a single shared resource, like
a printer, CPU task scheduling etc.
 In real life, Call Center phone systems will use
Queues, to hold people calling them in an order,
until a service representative is free.
 Handling of interrupts in real-time systems. The
interrupts are handled in the same order as they
arrive, First come first served.
Stack and Queue by M.Gomathi Lecturer

Mais conteúdo relacionado

Mais procurados

Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arorakulachihansraj
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Circular linked list
Circular linked listCircular linked list
Circular linked listchauhankapil
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure Janki Shah
 
Queue implementation
Queue implementationQueue implementation
Queue implementationRajendran
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureYaksh Jethva
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structureeShikshak
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTSoumen Santra
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptxsandeep54552
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 

Mais procurados (20)

Queues
QueuesQueues
Queues
 
stack presentation
stack presentationstack presentation
stack presentation
 
Linked List
Linked ListLinked List
Linked List
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Stack
StackStack
Stack
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Stack project
Stack projectStack project
Stack project
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptx
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 

Semelhante a Stack and Queue by M.Gomathi Lecturer

Semelhante a Stack and Queue by M.Gomathi Lecturer (20)

Stacks in data structure
Stacks  in data structureStacks  in data structure
Stacks in data structure
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Data Structure
Data Structure Data Structure
Data Structure
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
5.-Stacks.pptx
5.-Stacks.pptx5.-Stacks.pptx
5.-Stacks.pptx
 
stack.ppt
stack.pptstack.ppt
stack.ppt
 
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
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 

Último

Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 

Último (20)

Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 

Stack and Queue by M.Gomathi Lecturer

  • 2. STACKSStack is an abstract data type with a bounded(predefined) capacity. It is a simple data structure that allows adding and removing elements in a particular order. Every time an element is added, it goes on the top of the stack, the only element that can be removed is the element that was at the top of the stack, just like a pile of objects.
  • 4. Basic features of Stack •Stack is an ordered list of similar data type. •Stack is a LIFO structure. (Last in First out). •push() function is used to insert new elements into the Stack and pop() is used to delete an element from the stack. Both insertion and deletion are allowed at only one end of Stack called Top. •Stack is said to be in Overflow state when it is completely full and is said to be in Underflow state if it is completely empty.
  • 5. Applications of Stack •The simplest application of a stack is to reverse a word. You push a given word to stack - letter by letter - and then pop letters from the stack. •There are other uses also like : Parsing, Expression Conversion(Infix to Postfix, Postfix to Prefix etc) and many more.
  • 7. Implementation of Stack  Stack can be easily implemented using an Array or a Linked List. Arrays are quick, but are limited in size and Linked List requires overhead to allocate, link, unlink, and deallocate, but is not limited in size. Here we will implement Stack using array.
  • 10. Position of Top Status of Stack -1 Stack is Empty 0 Only one element in Stack N-1 Stack is Full N Overflow state of Stack
  • 11. Converting a Complex Expression to Prefix and Postfix Notations Here is a more complex expression: (A + B) * C - (D - E) * (F + G). Following figure shows the conversion to postfix and prefix notations.
  • 12. Analysis of Stacks  Below mentioned are the time complexities for various operations that can be performed on the Stack data structure.  Push Operation : O(1)  Pop Operation : O(1)  Top Operation : O(1)  Search Operation : O(n)
  • 15. Queue is also an abstract data type or a linear data structure, in which the first element is inserted from one end called rear(also called tail), and the deletion of existing element takes place from the other end called as front(also called head). This makes queue as FIFO data structure, which means that element inserted first will also be removed first. QUEU E
  • 16.  The process to add an element into queue is called Enqueue and the process of removal of an element from queue is called Dequeue. QUEUE…
  • 19. Basic features of Queue  Like Stack, Queue is also an ordered list of elements of similar data types.  Queue is a FIFO( First in First Out ) structure.  Once a new element is inserted into the Queue, all the elements inserted before the new element in the queue must be removed, to remove the new element.
  • 20.  Queue can be implemented using an Array, Stack or Linked List. The easiest way of implementing a queue is by using an Array. Initially the head(FRONT) and the tail(REAR) of the queue points at the first index of the array (starting the index of array from 0). Implementation of Queue
  • 21. Applications of Queue  Queue, as the name suggests is used whenever we need to have any group of objects in an order in which the first one coming in, also gets out first while the others wait for there turn, like in the following scenarios :  Serving requests on a single shared resource, like a printer, CPU task scheduling etc.  In real life, Call Center phone systems will use Queues, to hold people calling them in an order, until a service representative is free.  Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive, First come first served.