0% found this document useful (0 votes)
124 views8 pages

Stack

Uploaded by

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

Stack

Uploaded by

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

6/29/24, 6:39 PM Stack Data Structure - GeeksforGeeks

TutorialsDSAData ScienceWeb TechCourses

DSA Data Structures Array String Linked List Stack Queue Tree Binary Tree Binary Sea

Stack Data Structure


Last Updated : 02 May, 2024
A Stack is a linear data structure that follows a particular order in
which the operations are performed. The order may be LIFO(Last In
First Out) or FILO(First In Last Out). LIFO implies that the element
that is inserted last, comes out first and FILO implies that the element
that is inserted first, comes out last.

Table of Content
What is Stack Data Structure?
Basic Operations of Stack Data Structures
Applications of Stack Data Structures
Basics of Stack Data Structure
Implementations of Stack in Different Languages
Other Implementations of Stack Data Structures
Easy Problems on Stack Data Structures
Medium Problems on Stack Data Structures
Hard Problems on Stack Data Structures

What is Stack Data Structure?


A stack is a linear data structure that follows the Last-In-First-Out
(LIFO) principle. It behaves like a stack of plates, where the last plate
added is the first one to be removed.

Think of it this way:

Pushing an element onto the stack is like adding a new plate on


top.
Popping an element removes the top plate from the stack.

Key Operations on Stack Data Structures

https://www.geeksforgeeks.org/stack-data-structure/?ref=lbp 1/8
6/29/24, 6:39 PM Stack Data Structure - GeeksforGeeks

Push: Adds an element to the top of the stack.


Pop: Removes the top element from the stack.
Peek: Returns the top element without removing it.
IsEmpty: Checks if the stack is empty.
IsFull: Checks if the stack is full (in case of fixed-size arrays).

Applications of Stack Data Structures


Recursion
Expression Evaluation and Parsing
Depth-First Search (DFS)
Undo/Redo Operations
Browser History
Function Calls

Basics of Stack Data Structure


Introduction to Stack – Data Structure and Algorithm Tutorials
Basic Operations in Stack Data Structure
Introduction to Monotonic Stack
Implement a stack using singly linked list
Applications, Advantages and Disadvantages of Stack

Implementations of Stack in Different Languages


Stack in C++ STL
Stack Class in Java
Stack in Python
Stack in C#
Implementation of Stack in JavaScript

Other Implementations of Stack Data Structures


Implement Queue using Stacks
Design and Implement Special Stack Data Structure | Added Space
Optimized Version
Implement two stacks in an array
Implement Stack using Queues
How to efficiently implement k stacks in a single array?
https://www.geeksforgeeks.org/stack-data-structure/?ref=lbp 2/8
6/29/24, 6:39 PM Stack Data Structure - GeeksforGeeks

Design a stack that supports getMin() in O(1) time and O(1) extra
space
Implement a stack using single queue
How to implement stack using priority queue or heap?
Create a customized data structure which evaluates functions in
O(1)
Implement Stack and Queue using Deque

Easy Problems on Stack Data Structures


Infix to Postfix Conversion using Stack
Prefix to Infix Conversion
Prefix to Postfix Conversion
Postfix to Prefix Conversion
Postfix to Infix
Convert Infix To Prefix Notation
Check for balanced parentheses in an expression
Arithmetic Expression Evalution
Evaluation of Postfix Expression
Reverse a stack using recursion
Reverse individual words
Reverse a string using stack
Reversing a Queue

Medium Problems on Stack Data Structures


How to create mergable stack?
The Stock Span Problem
Next Greater Element
Next Greater Frequency Element
Maximum product of indexes of next greater on left and right
Iterative Tower of Hanoi
Sort a stack using a temporary stack
Reverse a stack without using extra space in O(n)
Delete middle element of a stack
Check if a queue can be sorted into another queue using a stack
Check if an array is stack sortable
https://www.geeksforgeeks.org/stack-data-structure/?ref=lbp 3/8
6/29/24, 6:39 PM Stack Data Structure - GeeksforGeeks

Iterative Postorder Traversal | Set 1 (Using Two Stacks)


Largest Rectangular Area in a Histogram | Set 2
Find maximum of minimum for every window size in a given array
Find index of closing bracket for a given opening bracket in an
expression
Find maximum difference between nearest left and right smaller
elements
Delete consecutive same words in a sequence
Check mirror in n-ary tree
Reverse a number using stack
Reversing the first K elements of a Queue

Hard Problems on Stack Data Structures


The Celebrity Problem
Print next greater number of Q queries
Iterative Postorder Traversal | Set 2 (Using One Stack)
Print ancestors of a given binary tree node without recursion
Length of the longest valid substring
Expression contains redundant bracket or not
Find if an expression has duplicate parenthesis or not
Find next Smaller of next Greater in an array
Iterative method to find ancestors of a given binary tree
Stack Permutations (Check if an array is stack permutation of other)
Spaghetti Stack
Remove brackets from an algebraic string containing + and –
operators
Range Queries for Longest Correct Bracket Subsequence

Quick Links :

‘Practice Problems’ on Stack


‘Videos’ on Stack
‘Quizzes’ on Stack

Recommended:

Learn Data Structure and Algorithms | DSA Tutorial


https://www.geeksforgeeks.org/stack-data-structure/?ref=lbp 4/8
6/29/24, 6:39 PM Stack Data Structure - GeeksforGeeks

Stack in Scala

H hare… 10

Next Article
What is Stack Data Structure? A
Complete Tutorial

Similar Reads
Static Data Structure vs Dynamic Data Structure
Data structure is a way of storing and organizing data efficiently such
that the required operations on them can be performed be efficient wit…
4 min read

Stack Vs Heap Data Structure


What is Stack? A stack is a linear data structure where the last element
entered exits first. The order of stack data structure might be LIFO, FIL…
3 min read

https://www.geeksforgeeks.org/stack-data-structure/?ref=lbp 5/8
6/29/24, 6:39 PM Stack Data Structure - GeeksforGeeks

Implement Dynamic Multi Stack (K stacks) using only one Data…


In this article, we will see how to create a data structure that can handle
multiple stacks with growable size. The data structure needs to handle…
15+ min read

Design and Implement Special Stack Data Structure | Added Space…


Question: Design a Data Structure SpecialStack that supports all the
stack operations like push(), pop(), isEmpty(), isFull() and an additional…
15+ min read

Top 50 Problems on Stack Data Structure asked in SDE Interviews


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…
3 min read

View More Articles

Article Tags : DSA Stack

Practice Tags : Stack

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -
201305

Company Explore
About Us Hack-A-Thons
Legal GfG Weekly Contest
In Media DSA in JAVA/C++
Contact Us Master System Design
https://www.geeksforgeeks.org/stack-data-structure/?ref=lbp 6/8
6/29/24, 6:39 PM Stack Data Structure - GeeksforGeeks
Advertise with us Master CP
GFG Corporate Solution GeeksforGeeks Videos
Placement Training Program Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL Top 100 DSA Interview Problems
R Language DSA Roadmap by Sandeep Jain
Android Tutorial All Cheat Sheets
Tutorials Archive

Data Science & ML HTML & CSS


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning Tutorial Web Templates
ML Maths CSS Frameworks
Data Visualisation Tutorial Bootstrap
Pandas Tutorial Tailwind CSS
NumPy Tutorial SASS
NLP Tutorial LESS
Deep Learning Tutorial Web Design

Python Tutorial Computer Science


Python Programming Examples Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths
Django

DevOps Competitive Programming


Git Top DS or Algo for CP
AWS Top 50 Tree
Docker Top 50 Graph
Kubernetes Top 50 Array
Azure Top 50 String
GCP Top 50 DP
DevOps Roadmap Top 15 Websites for CP

System Design JavaScript


High Level Design JavaScript Examples
Low Level Design TypeScript
UML Diagrams ReactJS
Interview Guide NextJS
https://www.geeksforgeeks.org/stack-data-structure/?ref=lbp 7/8
6/29/24, 6:39 PM Stack Data Structure - GeeksforGeeks
Design Patterns AngularJS
OOAD NodeJS
System Design Bootcamp Lodash
Interview Questions Web Browser

Preparation Corner School Subjects


Company-Wise Recruitment Process Mathematics
Resume Templates Physics
Aptitude Preparation Chemistry
Puzzles Biology
Company-Wise Preparation Social Science
English Grammar
World GK

Management & Finance Free Online Tools


Management Typing Test
HR Management Image Editor
Finance Code Formatters
Organisational Behaviour Code Converters
Marketing Currency Converter
Random Number Generator
Random Password Generator

More Tutorials GeeksforGeeks Videos


Software Development DSA
Software Testing Python
Product Management Java
SEO - Search Engine Optimization C++
Linux Web Development
Excel Data Science
All Cheatsheets CS Subjects

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/stack-data-structure/?ref=lbp 8/8

You might also like