Introduction To
Stack Data Structure
Stack is an abstract data type with a bounded(predefined) capacity. It is a simple data structure that allows adding and removing elements in a particular order. Every time an element is added, it goes on the top of the stack and the only element that can be removed is the element that is at the top of the stack, just like a pile of objects.
Stack can be easily implemented using an Array or a Linked List. Arrays are quick, but are limited in size and Linked List requires overhead to allocate, link, unlink, and deallocate, but is not limited in size.
Course Structure
Design and Implementation
- Queue using Stacks
- Design and Implement Special Stack Data Structure | Added Space Optimized Version
- Implement two stacks in an array
- Implement Stack using Queues
- Design a stack with operations on middle element
- How to efficiently implement k stacks in a single array?
- How to create mergable stack?
- 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
Standard Problems based on Stack
- Stack | Set 2 (Infix to Postfix)
- Prefix to Infix Conversion
- Prefix to Postfix Conversion
- Postfix to Prefix Conversion
- Postfix to Infix
- Convert Infix To Prefix Notation
- The Stock Span Problem
- Next Greater Element
- Next Greater Frequency Element
- Number of NGEs to the right
- Maximum product of indexes of next greater on left and right
- The Celebrity Problem
- Expression Evaluation
- Arithmetic Expression Evalution
- Stack | Set 4 (Evaluation of Postfix Expression)
- Iterative Tower of Hanoi
- Print next greater number of Q queries
Operations on Stack
- Reverse a stack using recursion
- Sort a stack using recursion
- Sort a stack using a temporary stack
- Delete middle element of a stack
- Sorting array using Stacks
- Delete array elements which are smaller than next or become smaller
- Check if a queue can be sorted into another queue using a stack
- Reverse individual words
- Count subarrays where second highest lie before highest
- Check if an array is stack sortable
Misc
- Reverse a stack without using extra space in O(n)
- Merge Overlapping Intervals
- Largest Rectangular Area in a Histogram | Set 2
- Print ancestors of a given binary tree node without recursion
- Stack | Set 3 (Reverse a string using stack)
- Program for Tower of Hanoi
- Find maximum depth of nested parenthesis in a string
- Find maximum of minimum for every window size in a given array
- Length of the longest valid substring
- Minimum number of bracket reversals needed to make an expression balanced
- Expression contains redundant bracket or not
- Identify and mark unmatched parenthesis in an expression
- Check if two expressions with brackets are same
- Find index of closing bracket for a given opening bracket in an expression
- Check for balanced parentheses in an expression
- Balanced expression with replacement
- Form minimum number from given sequence
- Find if an expression has duplicate parenthesis or not
- Find maximum difference between nearest left and right smaller elements
- Find next Smaller of next Greater in an array
- Find maximum sum possible equal sum of three stacks
- Count natural numbers whose all permutation are greater than that number
- Delete consecutive same words in a sequence
- Decode a string recursively encoded as count followed by substring
- Bubble sort using two Stacks
- Pattern Occurrences : Stack Implementation Java
- Iterative method to find ancestors of a given binary tree
- Stack Permutations (Check if an array is stack permutation of other)
- Tracking current Maximum Element in a Stack
- Reverse a number using stack
- Reversing the first K elements of a Queue
- Reversing a Queue
- Check if stack elements are pairwise consecutive
- Interleave the first half of the queue with second half
- Remove brackets from an algebraic string containing + and – operators
- Growable array based stack
- Range Queries for Longest Correct Bracket Subsequence Set | 2