0% found this document useful (0 votes)
3 views

Data Structure

The document provides an overview of stacks, a linear data structure that operates on the Last In First Out (LIFO) principle. It details stack operations including push, pop, peek, and display, along with their algorithms and time complexity. Additionally, it discusses applications of stacks in evaluating expressions and memory management.

Uploaded by

ankitamaity001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Data Structure

The document provides an overview of stacks, a linear data structure that operates on the Last In First Out (LIFO) principle. It details stack operations including push, pop, peek, and display, along with their algorithms and time complexity. Additionally, it discusses applications of stacks in evaluating expressions and memory management.

Uploaded by

ankitamaity001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PAILAN COLLEGE OF MANAGEMENT AND TECHNOLOGY

CA 1 Examination

NAME MUNTUSHA MONDAL


:
UNIVERSITY ROLL NO 15600123021
:
STREAM COMPUTER SCIENCE AND ENGINEERING
: (CSE)
SUBJECT NAME DATA STRUCTURE AND ALGORITHMS
:
SUBJECT CODE PCC-CS301
:
SESSION 2023-2027
SEMESTER 3rd SEMESTER
STACK and ITS OPERATIONS

 Definition of stack
 Working principle
 Operations
(Push,Pop,Peek,Disply)
 Application
What is
stack ?
Stacks are linear data structures that follows a
particular method called LIFO. A Stack can be
a fixed specific size, or it can be dynamic, i.e.,
the Stack size can be changed dynamically

Implementatio
n of Stack :
In terms of implementation, stacks
are typically implemented using
an array or linked list. The two
main operations of a stack are
push and pop.
WORKING PRINCIPLE
It works on the principle of LIFO
(Last In First Out) or FILO (First In
Last Out)

It means that the last element entered in


stack ,which is at the top ,will be removed first,
and the first element entered in stack will be
removed at last. This makes it ideal for items
that must be processed in reverse order, such as
undo/redo operations or call stacks.
OPERATIONS ON STACK
Stack is a special data structure in which the elements are stored
and accessed based on LIFO principle. It allows insertion and
deletion of elements at one end referred to as top only.

PUSH POP PEEK DISPLAY


The push operati
Removing a data The peek operatio It basically
on is one of the
element from the n is used in shows the
fundamental
stack data function to return stack condition
operations in a
structure is called the value of the and checks if
stack data
a pop operation. top of the stack the stack is
structure. It
without deleting it empty or full.
means inserting
.It points the
an element at
topmost element.
the top of the
stack.
ALGORITHM
3
TOP
Step 1 : Start.
3
Step 2 : Check weather
2 2 TOP = Size-1 , then the
1 1 stack is full , Print
“Overflow” and Go to
Step5

Step 3 : It is not full then


Set TOP = TOP + 1

Step 4 : Set Stack[TOP] =


ELEMENT
PUSH OPERATION
Step 5 : End .
ALGORITHM TO
3
P

Step 1 : Start
3
2 2
Step 2 : If TOP = 1
1 1
Print “Underflow”
Go to Step 5

Step 3 : Set VAL=


Stack[TOP]

Step 4 : Set TOP = TOP - 1

Step 5 : End . POP OPERATION


TOP ALGORITHM
4
Step-1 : Start
3
2
1 Step 2 : If TOP = -1
Print “Stack is Empty”
Go to Step 4 .

Step 3 : Return
Stack[TOP]

Step 4 : End .

PEEK OPERATION
ALGORITH
M
Step 1 : Start . 4
3
2
Step 2 : If (top == -1) ,
1
then the stack is empty,
print “The Stack is The Stack is The Stack is
Full Empty
Empty”.

Step 3 : If (top == size-1)


then the stack is full,
print “The Stack is Full”.

Step 4 : End . DISPLAY OPERATION


APPLICATION  TIME COMPLEXITY :

Operations like insertion or


deletion in a stack take constant
time i.e. O(1).

A Stack can be used for Stacks can be used for


evaluating expressions Backtracking, i.e., to  SPACE COMPLEXITY
consisting of operands check parenthesis
and operators. matching in an
:
expression.
Space complexity for each
operation in a stack is O(1), as
no extra space is required for
It can also be used to It can be used for any operation.
convert one form of systematic Memory
expression to another Management.
form.

REAL LIFE EXAMPLE :


THANK YOU

You might also like