SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 

La actualidad más candente (20)

Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Stacks
StacksStacks
Stacks
 
UNIT III NON LINEAR DATA STRUCTURES – TREES
UNIT III 	NON LINEAR DATA STRUCTURES – TREESUNIT III 	NON LINEAR DATA STRUCTURES – TREES
UNIT III NON LINEAR DATA STRUCTURES – TREES
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Queue
QueueQueue
Queue
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Expression trees
Expression treesExpression trees
Expression trees
 
Linked list
Linked listLinked list
Linked list
 
Stack
StackStack
Stack
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Java Queue.pptx
Java Queue.pptxJava Queue.pptx
Java Queue.pptx
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Array ppt
Array pptArray ppt
Array ppt
 

Similar a Stack and Queue by M.Gomathi Lecturer

Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
Getachew Ganfur
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
Saqib Saeed
 

Similar 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
 
Stack project
Stack projectStack project
Stack project
 
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
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 

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.