PPT - Introduction to Stack (02May2025)
PPT - Introduction to Stack (02May2025)
Structure
Java Implementation
Java provides a built-in Stack class in the java.util package.
Custom implementations are also common.
Key Characteristics of
Stacks
LIFO Principle
The Last-In-First-Out principle defines the behavior of all
stack operations.
Access Restriction
Elements can only be accessed from one end of the stack.
Undo Mechanisms
Applications use stacks to implement undo functionality by storing previous states.
Backtracking Algorithms
Mazes and puzzles use stacks to remember decision points for backtracking.
Parentheses Matching
Compilers use stacks to verify balanced parentheses in code.
Browser Navigation 5
every time you visit a new page, the current page is pushed onto a back
stack. Clicking "back" pops the last page, and if you go forward, it's managed
with a forward stack.
Basic Stack Operations
Push
Adds an element to the top of the stack.
Example: stack.push(element);
Pop
Removes and returns the top element.
Peek
Returns the top element without removing it.
isEmpty
Checks if the stack contains any elements.
Example: if(stack.isEmpty())
isFull
Checks if the stack is full.
Example: if(stack.isFull())
Stack Implementation Options
Ready-made Implementation
java.util.Stack or java.util.Deque interface
Array-based Implementation
Fixed or dynamic array storing elements