1. What is a Stack? Explain with Real-Life Examples.
A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle. Examples:
Stack of plates, browser back button, undo operation in editors.
2. What are the Basic Operations of a Stack? Why is Stack Called LIFO?
Operations: Push, Pop, Peek/Top, isEmpty, isFull. It is called LIFO because the element inserted
Last is removed First.
3. How is Stack Implemented Using Arrays in Java? What are the Limitations?
Use an array and a variable top to track index of last element. Limitations: Fixed size, wastes
memory if not fully used.
4. What is Stack Overflow and Underflow? How do you Check if a Stack is Full or Empty
Using Arrays?
Overflow: Pushing into full stack. Underflow: Popping from empty stack. Full if top == size-1, Empty
if top == -1.
5. What is the Role of 'top' Variable in Array-based Stack and in Linked List?
In Array: Holds index of last element. In Linked List: Points to head node.
6. Initial and Final Value of Top in Stack using Arrays? Keywords in Java Implementation?
Initial = -1, Final = size-1. Java uses class, public, private, new, this.
7. Stack with Linked List – Difference & Operations
Array: Fixed size, contiguous memory. Linked List: Dynamic size, uses nodes. Operations: Push
(insert at start), Pop (delete from start), Peek (head node).
8. How is Stack Represented Using Linked List in Java?
Each node has data and next pointer, top points to head node.
9. Time & Space Complexity of Stack
Array: Push/Pop/Peek = O(1), Space = O(n). Linked List: Push/Pop = O(1), Space = O(n) extra for
pointers.
10. Rules of Tower of Hanoi Problem
1. Only one disk moved at a time. 2. Larger disk cannot be placed on smaller. 3. Only top disk can
be moved.
11. What is a Queue? Basic Operations?
Queue follows FIFO. Operations: Enqueue (insert rear), Dequeue (delete front), Peek, isEmpty,
isFull.
12. Queue Implementation Using Array in Java
Use array with front and rear variables. Enqueue: queue[++rear] = item. Dequeue: item =
queue[front++].
13. Queue Overflow and Underflow
Overflow: rear == size-1. Underflow: front > rear.
14. What is a Circular Queue? How is it Better?
Circular Queue connects rear to front, reuses memory efficiently.
15. Difference Between Linear and Circular Queue
Linear: Straight line, wastes memory after deletions. Circular: Connects rear to front, efficient
memory usage.