1.Explain the difference between a stack and a queue. When would you use each?
Answer
A stack is LIFO (last in, first out) with push and pop on one end, while a queue is FIFO (first in, first out) with enqueue at the rear and dequeue at the front. Use a stack for call stacks, undo history, expression evaluation and backtracking. Use a queue for task scheduling, BFS traversal, print jobs and message buffers. Both core operations are O(1).