A stack is initially empty. The operations push(A), push(B), and push(C) are performed in that order. Which value is returned by the next pop()?
5 Stacks and Queues Online Quiz Questions
Use this free practice quiz with 20 questions to review 5 Stacks and Queues, test your knowledge, and prepare for your next test or exam.
A queue is initially empty. The operations enqueue(A), enqueue(B), and enqueue(C) are performed in that order. Which value is returned by the next dequeue()?
- A
C
- B
B
- C
A
- D
The value at the rear
Select all situations for which a stack is the more natural abstraction.
- A
Maintaining an undo history
- B
Processing tasks fairly in arrival order
- C
Exploring a graph depth-first
- D
Serving requests in arrival order
Select all design features that support an efficient fixed-capacity circular-array queue.
- A
Wrap indices around with modular arithmetic.
- B
Maintain the number of stored elements.
- C
Shift every remaining element after each removal.
- D
Keep only a rear pointer and no front position.
True or false: Omitting the rear pointer from a singly linked-list queue makes enqueue() take O(n) time because the list must be traversed to find its end.
- A
True
- B
False
True or false: In a naive array-based queue that shifts all remaining elements after each dequeue, one dequeue can take O(n) time.
- A
True
- B
False
In a linked-list queue, what is the standard name of the pointer that identifies the insertion endpoint?
For a dynamically resized array stack that grows geometrically, what is the amortized time complexity of one push() over a long sequence of insertions? Include the word “amortized” in your answer.
Complete the statements about a linked-list stack: push() and pop() each take time, and storing n elements requires space.
Under the array-stack convention described in the material, the integer represents the .
Why do nested function calls return in LIFO order?
- A
The outermost function always returns first.
- B
The most recently called function returns first.
- C
All calls return in the order they were made.
- D
The call stack stores only global variables.
Which implementation best avoids O(n) shifting when repeatedly removing items from the front of an array-backed queue?
- A
A linked-list stack with a head pointer
- B
A circular-array queue with modular index updates
- C
A naive array queue that shifts after removal
- D
A priority queue ordered by insertion cost
What is the main purpose of treating an array as a circular buffer when implementing a queue?
- A
It keeps every element permanently at index 0
- B
It sorts elements before each insertion
- C
It prevents the queue from ever becoming full
- D
It allows the rear and front indices to wrap around and reuse array positions
A queue is implemented with a singly linked list and both front and rear pointers. What is the time complexity of enqueue?
- A
O(n), because every existing node must be copied
- B
O(1), because the rear pointer identifies the insertion point
- C
O(log n), because the nodes must be searched by value
- D
O(n^2), because each node requires two traversals
Which data structure is most appropriate for the frontier in breadth-first search, and why?
- A
A stack, because the newest vertex must always be processed first
- B
A deque, because BFS never processes vertices in layers
- C
A queue, because vertices are processed in arrival order within each layer
- D
A linked list used only for random-access lookup
A stack uses a dynamically resized array whose capacity grows geometrically. What is the amortized time complexity of push over a long sequence of insertions?
- A
The amortized time per push is O(1), although an individual resize can cost O(n).
- B
Every push takes O(n), because the array may be copied on every insertion.
- C
The amortized time per push is O(log n), because the capacity grows geometrically.
- D
Every push takes O(n^2), because each resize copies all earlier arrays.
A deque can provide both queue behavior and stack behavior by choosing appropriate ends for insertion and removal.
- A
True
- B
False
What is the term for attempting to remove or examine an element from an empty stack or queue?
An initially empty queue performs enqueue(A), enqueue(B), enqueue(C), and then dequeue(). What is the queue size afterward?
A compiler scans the delimiter sequence ([{}]) from left to right. Explain how a stack can be used to determine whether the sequence is balanced, and state why this particular sequence is accepted. Also explain what would make a delimiter sequence invalid.