Questions
3-4 questions per university paper
Difficulty
Medium
Importance
High yield for BCA/MCA theory exams
Overview
Stacks and Queues are fundamental linear data structures that govern how data is stored and retrieved based on access patterns. Mastering these is critical for university exams as they form the basis for algorithm design, function call management, and system scheduling.
Stack Operations & Applications
A stack follows the Last-In-First-Out (LIFO) principle, where the last element inserted is the first to be removed. It is implemented using arrays or linked lists and is central to recursion and expression parsing.
- Primary operations: push() and pop()
- Utility: peek() or top() to view the stack head
- Underflow: attempting to pop from an empty stack
- Overflow: attempting to push into a full stack
- Applications: Function call stack, Undo features, Syntax parsing
Queue & Circular Queue
Queues operate on the First-In-First-Out (FIFO) principle, where elements are inserted at the rear and removed from the front. The Circular Queue addresses the space wastage issue of standard linear queues by connecting the rear back to the front.
- Linear queue issues: Front and Rear pointers keep moving
- Circular queue condition: (rear + 1) % size == front
- Enqueue: insertion at rear
- Dequeue: removal from front
- Applications: CPU scheduling, Buffer management, Printer spooling
Expression Evaluation
Stacks are used to convert and evaluate arithmetic expressions from Infix to Postfix (Reverse Polish) or Prefix notation. This process removes the need for parentheses and operator precedence rules during execution.
- Infix: A + B (standard human-readable format)
- Postfix: AB+ (stack-friendly, no brackets needed)
- Shunting-yard algorithm for conversion
- Operator precedence: ^ > *, / > +, -
- Evaluation logic: push operands, apply operator to top two elements
Formula Sheet
Circular Queue Full: (rear + 1) % max = front
Circular Queue Empty: front = -1
Postfix Evaluation: pop two operands, op2 <op> op1
Exam Tip
Always draw a step-by-step table for expression conversion or evaluation to ensure no marks are lost due to arithmetic errors in the final result.
Common Mistakes
- Confusing the LIFO (Stack) and FIFO (Queue) access principles during implementation.
- Forgetting to check for queue overflow/underflow conditions in circular queue logic.
- Incorrectly handling operator precedence when manually converting Infix to Postfix expressions.
More Revision Notes
Ready to test yourself?
Play topic-wise Stacks & Queues questions in Aspirant Arcade — gamified MCQ practice.
Download Free