KEMBAR78
Unit I-Data structures stack & Queue | PPTX
STACK & QUEUE
Dr. R. Khanchana
Assistant Professor
Department of Computer Science
Sri Ramakrishna College of Arts and Science for Women
STACK
E –Book – Chapter 3 :
http://icodeguru.com/vc/10book/books/book1/chap03.htm
Stack Tutorial
https://www.studytonight.com/data-structures/stack-data-structure
STACK - EXAMPLES
CHAPTER 3 : http://icodeguru.com/vc/10book/books/book1/chap03.htm
Stacks
•The most common data
objects in the computer
algorithms are Stacks and
Queues.
•Stacks are dynamic data
structures that follow
the Last In First Out
(LIFO) principle
•An Ordered List in which
all the insertions and
deletions take place at the
one end called Top.
Bottom
Stacks
Operations: The operation that can be performed on the stack are:
CREATE(S) – This Procedure creates S an empty stack.
ADD(i,S) – This procedure inserts an element i into the
stack S and returns the new stack.
DELETE(i,S) – This procedure removes the top most element
from the stack S and returns the new stack.
TOP(S) – This procedure returns the top most element
of the stack S.
ISEMT(S) – This procedure returns true, if S is an empty
STACK Implementations
• CREATE ( ) :: = declare STACK(1:n); top 0
• ISEMTS(STACK) :: = if top = 0 then true
• else false
• TOP(STACK) :: = if top = 0 then error
else STACK(top)
Procedure - Stack
Procedures- Push
procedure ADD (item, STACK, n, top)
//insert item into the STACK of maximum size n; top is the number of
elements currently in STACK//
if top n then call STACK_FULL
Top top + 1
STACK (top) item
end ADD
Procedures - Pop
procedure DELETE (item, STACK, top)
//removes the top element of STACK and stores
it in item
unless STACK is empty//
if top 0 then call STACK_EMPTY
item STACK (top)
Top top - 1
end DELETE
STACK OPERATIONS
QUIZ
• https://quizizz.com/admin/quiz/5f08716a58b
4e9001cbeca8a
Feedback
• https://docs.google.com/forms/d/1kSoCAmQ
dfuf2kIWFEkl8xZQKMAluyXS6XyYGjXDwXcw/e
dit
QUEUE
E –Book – Chapter 3 :
http://icodeguru.com/vc/10book/books/book1/chap03.htm
Queue – Tutorial
https://www.tutorialride.com/data-structures/queue-in-data-
structure.htm
Queue - Examples
CHAPTER 3 : http://icodeguru.com/vc/10book/books/book1/chap03.htm
Difference Between Stack & Queue
Queue -Understanding
Queue – Insertion & Deletion
Queue Operations
• CREATEQ(Q) which creates Q as an empty queue;
• ADDQ(i,Q) which adds the element i to the rear
of a queue and returns the new queue;
• DELETEQ(Q) which removes the front element
from the queue Q and returns the resulting
queue;
• FRONT(Q) which returns the front element of Q;
• ISEMTQ(Q) which returns true if Q is empty else
false.
Queue Implementations
CREATEQ(Q) :: = declare Q(l:n); front rear 0
ISEMTQ(Q) :: = if front = rear then true
else false
FRONT(Q) :: = if ISEMTQ(Q) then error
else Q(front + 1)
Queue -Procedure
Queue –ADD Procedure
Queue – Delete Procedure
QUIZ
• https://quizizz.com/admin/quiz/5f0c472c48e3
69001bb0d69a/data-structure-queue
Feedback
• https://docs.google.com/forms/d/1A8Dgtkn4
A1g8-
QiQA1W6hvyRNhR7OMl_VxA9TyYNMog/edit
Circular Queue
Linear Queue Vs Circular Queue
Enqueue -6 Elements
Dequeue – 3 Elements
Enqueue – One more element
Circular Queue
• Circular Queue is a bounded queue which implements arrays.
• It is better than a normal queue because it will effectively
utilize the memory space.
• If we have a normal queue and have deleted some elements
an empty space is created.
• Even if the queue has empty space we cannot insert any new
element because the inserting has to be done from one side
only(Rear) and deletions has to be done from another
side(front).
• In case of Circular Queue the Front and Rear are adjacent to
each other. Hence we can insert a new element in the empty
space (i.e the space from where the element is deleted).
Queue Implementations
• https://i1.faceprep.in/Companies-1/circular-
queue-implementation.gif
Circular Queue – ADD Procedure
Procedure ADD(i,Q,n,rear)
//insert the element i into the Queue
rear=(rear+1) mod n;
If front = rear then call Queue_Full
Q(rear)=item;
end ADD
Circular Queue –Addition(Enqueue)
Circular Queue – Delete Procedure
Procedure DELETE(i,Q,front,rear)
//insert the element i into the Queue
If front=rear then call Queue_Empty
front = (front +1) mod n;
i=Q(front);
end DELETE
Enqueue & Dequeue
Multiple Stack & Queue
Multiple Stacks
Multiple Queues
Multiple Stack
• Boundary condition
– B(i) = T(i) iff the i'th stack is empty
Multiple Stack – Insertion and Deletion
Quiz
• https://quizizz.com/admin/quiz/5f0e8c1b367f
66001cbc9e7e
Feedback
• https://docs.google.com/forms/d/1Twhq95BD
Pmsn4UPqGdqG1z4BQaLbgPKftmyp9CsYLJU/e
dit

Unit I-Data structures stack & Queue