Stack in Data Structures (Class
Notes)
Data Structures - Class Notes
Introduction to Stack
• Stack is a linear data structure
• Follows LIFO (Last In First Out) principle
• Insertion and deletion allowed only at one
end (top)
Basic Operations on Stack
• push(x): Insert element x at the top
• pop(): Remove and return top element
• peek()/top(): Return top element without
removing
• isEmpty(): Check if stack is empty
• isFull(): Check if stack is full (for fixed size)
Stack Representation
• Implemented using arrays or linked lists
• Array-based stack: fixed size
• Linked list-based stack: dynamic size
• Top pointer indicates current position
Applications of Stack
• Expression evaluation and conversion (Infix,
Postfix, Prefix)
• Undo/Redo operations in editors
• Backtracking algorithms (maze, puzzles)
• Function call management (recursion)
• Browser history navigation
Expression Conversion using Stack
• Infix → Postfix (Shunting-yard algorithm)
• Postfix evaluation using stack
• Prefix → Infix/Postfix conversions
• Parenthesis matching
Advantages & Limitations
• Simple to implement
• Efficient for LIFO operations
• Limited access (only top element accessible)
• Fixed size in array implementation may cause
overflow
Summary & Key Points
• Stack is LIFO data structure
• Supports push, pop, peek operations
• Implemented using arrays or linked lists
• Extensively used in compilers, recursion, and
algorithms