You are on page 1of 10

STACKS

U S E S A N D A P P L I C AT I O N S O F S TA C K S
SUBMITTED TO:
SIR HAFIZ MUHAMMAD USMAN ZIA
SUBMITTED FROM:
ABDULLAH ABBAS (17581556-026)
TAYYAB NAWAZ (17581556-003)
ASAD NAWAZ (17811556-001)
AHSAN IJAZ (16451556-033)
DEF:

• A stack is a container of objects that are inserted and removed according to the last-in first-
out (LIFO) principle. In the push-down stacks only two operations are allowed: push the item
into the stack, and pop the item out of the stack.
– A stack is a limited access data structure - elements can be added and removed from the
stack only at the top.
– push adds an item to the top of the stack, pop removes the item from the top.
• A stack is a recursive data structure. Here is a structural definition of a Stack:
– a stack is either empty or
– it consists of a top and the rest which is a stack
BASIC FEATURES OF STACK

• Stack is an ordered list of similar data type.


• Stack is a LIFO(Last in First out) structure or we can say FILO(First in Last out).
• Push() function is used to insert new elements into the stack and pop() function is used to
remove an element from the stack. Both insertion and removal 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.
ALGORITHM FOR PUSH ALGORITHM FOR POP
O P E R AT I O N O P E R AT I O N

• Check if the stack is full or not. • Check if the stack is empty or not.
• If the stack is full, then print error of • If the stack is empty, then print error of
overflow and exit the program. underflow and exit the program.
• If the stack is not full, then increment the • If the stack is not empty, then print the
top and add the element. element at the top and decrement the
top.
REAL TIME EXAMPLES

• UNDO REDO MECHANISM.


• BACK TRACKING.
• BACKWARD/FORWARD ON BROWSER.
• STACK OF BOOKS IN CUPBOARD.
• EVALUATION OF INFIX, PREFIX AND POSTFIX EXPRESSIONS.
• WEARING/REMOVING OF BANGLES.
APPLICATIONS/USES OF STACKS
• Stack is used to evaluate prefix, postfix and infix expressions.
• An expression can be represented in prefix, postfix or infix notation.Stack can be used to convert
one form of expression to another.
• 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.
• Another application is an "undo" mechanism in text editors; this operation is accomplished by keeping
all text changes in a stack.
• A stack of plates/books in a cupboard.
• Wearing/Removing Bangles.
• Back/Forward stacks on browsers.
BIG O NOTATION AND TIME
COMPLEXITY
TIME COMPLEXITY OF STACKS
Average Worst
Search Push Pop Search Push Pop

STACK Θ(n) Θ(1) Θ(1) O(n) O(1) O(1)


BIG O NOTATION AND TIME COMPLEXITY

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)
The time complexities for push() and pop() functions are O(1) because we always
have to insert or remove the data from the top of the stack, which is a one
step process.
THE END

You might also like