BRAINWARE UNIVERSITY
398, Ramkrishnapur Road, Barasat, North 24 Parganas, Kolkata - 700 125
NAME : DEBKUMAR PAYRA
STUDENT CODE : BWU/BCA/22/582
PROGRAM NAME : BCA
COURSE NAME : DATA STRUCTURES
COURSE CODE : BCAC202
SECTION : J
TOPIC : STACK
Introduction to Stack
A stack is a linear data structure in which the insertion of a new
element and removal of an existing element takes place at the
same end represented as the top of the stack.
To implement the stack, it is required to maintain the pointer to
the top of the stack, which is the last element to be inserted
because we can access the elements only on the top of the
stack.
DATA
STRUCTRUE
LINEAR DATA
STRUCTRUE
ARRAY QUEUE STACK LINKED LIST
NON-
LINEAR DATA
STRUCTRUE
GRAPH TREE
 DATA STRUCTRUE TYPES :
 WHAT IS STACK ?
 A Stack is a linear data structure that follows the LIFO
(Last-In-First Out) principle manner. Stack has one end .
It contains only one pointer top pointer pointing to the
topmost element of the stack. Whenever an element is
added in the stack, it is added on the top of the stack,
and the element can be deleted only from the stack. In
other words, a stack can be defined as a container in
which insertion and deletion can be done from the one
end known as the top of the stack.
 STACK IN REAL LIFE EXAMPLE :
 Operations on Stack :
 Basically, some common operations implemented on the
stack:
• push(): When we insert an element in a stack then the
operation is known as a push. If the stack is full then the
overflow condition occurs.
 pop(): When we delete an element from the stack, the operation is
known as a pop. If the stack is empty means that no element exists in
the stack, this state is known as an underflow state.
ALGORITHM OF PUSH AND POP OPERATIONS IN STACK :
Step-1 : Start
Step-2 : if stack is
“full”
print(“OVERFLOW”)
Endif.
Exit
Step-3 : else
top=top+1
Step-4 : stack[top]=item
Step-5 : End else
Step-6 : Exit
Step-1 : Start
Step-2 : if stack is “empty”
print(“UNDERFLOW”)
Endif.
Exit
Step-3 : else
item=stack[top]
Step-4 : top=top-1
return value
Step-5 : End else
Step-6 : Exit
push() operation pop() operation
 peek()/top() : It returns the element at the given position or
tops element.
E
R
A
W
N
I
A
R
B
0
1
2
3
6
9
7
8
4
5
TOP
STACK
Algorithm of top() operations
Step-1 : Start
Step-2 : return
stack[top]
Step-3 : Exit
INDEXING
• isEmpty(): This operation is determines whether the stack is
empty or not.
• isFull(): In this operation determines whether the stack is full or
not.'
Algorithm of isEmpty() operations Algorithm of isFull() operations
Step-1 : Start
Step-2 : if
stack[i]=top[i]
print(“FULL”)
Endif
Exit
Step-3 : else
return 0 or
False
Step-4 : End else
Step-5 : Exit
Step-1 : Start
Step-2 : if stack top < 1
print(“EMPTY”)
return 1 or true
Endif
Exit
Step-3 : else
return 0 or
False
Step-4 : End else
Step-5 : Exit
 Types of Stacks:
 Fixed Size Stack: As the name suggests, a fixed size stack has a
fixed size and cannot grow or shrink dynamically. If the stack is
full and an attempt is made to add an element to it, an overflow
error occurs. If the stack is empty and an attempt is made to
remove an element from it, an underflow error occurs.
 Dynamic Size Stack: A dynamic size stack can grow or shrink
dynamically. When the stack is full, it automatically increases its
size to accommodate the new element, and when the stack is
empty, it decreases its size. This type of stack is implemented
using a linked list, as it allows for easy resizing of the stack.
THANK
YOU
!

STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx

  • 1.
    BRAINWARE UNIVERSITY 398, RamkrishnapurRoad, Barasat, North 24 Parganas, Kolkata - 700 125
  • 2.
    NAME : DEBKUMARPAYRA STUDENT CODE : BWU/BCA/22/582 PROGRAM NAME : BCA COURSE NAME : DATA STRUCTURES COURSE CODE : BCAC202 SECTION : J TOPIC : STACK
  • 3.
    Introduction to Stack Astack is a linear data structure in which the insertion of a new element and removal of an existing element takes place at the same end represented as the top of the stack. To implement the stack, it is required to maintain the pointer to the top of the stack, which is the last element to be inserted because we can access the elements only on the top of the stack.
  • 4.
    DATA STRUCTRUE LINEAR DATA STRUCTRUE ARRAY QUEUESTACK LINKED LIST NON- LINEAR DATA STRUCTRUE GRAPH TREE  DATA STRUCTRUE TYPES :
  • 5.
     WHAT ISSTACK ?  A Stack is a linear data structure that follows the LIFO (Last-In-First Out) principle manner. Stack has one end . It contains only one pointer top pointer pointing to the topmost element of the stack. Whenever an element is added in the stack, it is added on the top of the stack, and the element can be deleted only from the stack. In other words, a stack can be defined as a container in which insertion and deletion can be done from the one end known as the top of the stack.
  • 6.
     STACK INREAL LIFE EXAMPLE :
  • 7.
     Operations onStack :  Basically, some common operations implemented on the stack: • push(): When we insert an element in a stack then the operation is known as a push. If the stack is full then the overflow condition occurs.
  • 8.
     pop(): Whenwe delete an element from the stack, the operation is known as a pop. If the stack is empty means that no element exists in the stack, this state is known as an underflow state.
  • 9.
    ALGORITHM OF PUSHAND POP OPERATIONS IN STACK : Step-1 : Start Step-2 : if stack is “full” print(“OVERFLOW”) Endif. Exit Step-3 : else top=top+1 Step-4 : stack[top]=item Step-5 : End else Step-6 : Exit Step-1 : Start Step-2 : if stack is “empty” print(“UNDERFLOW”) Endif. Exit Step-3 : else item=stack[top] Step-4 : top=top-1 return value Step-5 : End else Step-6 : Exit push() operation pop() operation
  • 10.
     peek()/top() :It returns the element at the given position or tops element. E R A W N I A R B 0 1 2 3 6 9 7 8 4 5 TOP STACK Algorithm of top() operations Step-1 : Start Step-2 : return stack[top] Step-3 : Exit INDEXING
  • 11.
    • isEmpty(): Thisoperation is determines whether the stack is empty or not. • isFull(): In this operation determines whether the stack is full or not.' Algorithm of isEmpty() operations Algorithm of isFull() operations Step-1 : Start Step-2 : if stack[i]=top[i] print(“FULL”) Endif Exit Step-3 : else return 0 or False Step-4 : End else Step-5 : Exit Step-1 : Start Step-2 : if stack top < 1 print(“EMPTY”) return 1 or true Endif Exit Step-3 : else return 0 or False Step-4 : End else Step-5 : Exit
  • 12.
     Types ofStacks:  Fixed Size Stack: As the name suggests, a fixed size stack has a fixed size and cannot grow or shrink dynamically. If the stack is full and an attempt is made to add an element to it, an overflow error occurs. If the stack is empty and an attempt is made to remove an element from it, an underflow error occurs.  Dynamic Size Stack: A dynamic size stack can grow or shrink dynamically. When the stack is full, it automatically increases its size to accommodate the new element, and when the stack is empty, it decreases its size. This type of stack is implemented using a linked list, as it allows for easy resizing of the stack.
  • 13.