Chapter 8 Revision: Stacks and Queues
Stacks (LIFO) and Queues (FIFO) represent the most fundamental linear access disciplines in computer science. From OS CPU scheduling queues and hardware circular ring buffers to recursive backtracks and expression parsers, their performance guarantees shape system responsiveness.
Use these flashcards for active recall. Try to answer the question out loud before clicking the card to flip it.
Flashcards 🎴
What are the essential operations and complexity of a Stack ADT?
push(item): Inserts at the top (O(1)).•
pop(): Removes and returns the top item (O(1)).•
peek(): Views the top item without removal (O(1)).Underflow occurs when attempting to pop/peek an empty stack.
How does a Circular Array Buffer implement a FIFO Queue in O(1) time?
front and rear indices modulo array capacity (index = (index + 1) % capacity). Enqueue appends at rear and dequeue advances front in O(1) time without shifting remaining elements.What is a Deque (Double-Ended Queue) and what operations does it provide?
addFirst, addLast, removeFirst, and removeLast. Implemented via circular arrays or doubly linked lists.What is a Monotonic Stack and what class of problems does it solve?
How can a Queue be implemented using Two Stacks?
inbox and outbox stacks. Enqueue pushes directly to inbox. Dequeue pops from outbox; if outbox is empty, pop all items from inbox and push them to outbox (reversing order). Yields an amortized O(1) cost per operation.