An empty stack performs push(A), push(B), push(C), and then pop(). What does the operation return, and what remains in the stack from bottom to top?
04 Stacks and Queues Online Quiz Questions
Use this free practice quiz with 20 questions to review 04 Stacks and Queues, test your knowledge, and prepare for your next test or exam.
True or false: An abstract data type such as a stack requires an array implementation.
- A
True
- B
False
What term describes attempting to remove or inspect an item when a stack contains no items?
A queue starts empty and receives enqueue(A), enqueue(B), and enqueue(C). Which two values are returned by the next two dequeue() operations, in order?
- A
C, then B
- B
B, then A
- C
A, then B
- D
A, then C
Complete both statements: To add an item to a stack, use ; to add an item to a queue, use .
Which two applications naturally benefit from stack behavior because the most recently added unfinished item should be handled first? Select all that apply.
- A
Undoing the latest user action
- B
Processing documents in submission order
- C
Depth-first search backtracking
- D
Exploring graph vertices level by level
True or false: In a circular-array queue, reaching the physical end of the array necessarily means that no more items can be enqueued.
- A
True
- B
False
A queue contains A, B, and C from front to rear. After one dequeue() and one enqueue(D), how many items are in the queue?
Which design choice allows a linked-list queue to support both enqueue and dequeue in O(1) time?
- A
It needs only a rear reference and must traverse backward to dequeue.
- B
It should maintain both front and rear references.
- C
It must shift every node after each dequeue.
- D
It can maintain only a front reference and still enqueue in O(1) time.
In a circular-array queue, the index identifies the next item to remove, while the index identifies where the next item will be inserted.
Which two implementation rules are necessary for a correct linked-list queue with constant-time enqueue and dequeue? Select all that apply.
- A
Keep a reference to both the front node and the rear node.
- B
Store every node in contiguous array positions.
- C
Set both front and rear to null after removing the final node.
- D
Traverse from the front to find the rear for every enqueue.
Explain the behavioral difference between a stack and a queue. Include the ordering rule, the relevant insertion and removal ends, and why the underlying array-versus-linked-list choice does not by itself determine the ADT.
Which statement correctly distinguishes a priority queue from an ordinary FIFO queue?
- A
A bounded FIFO queue always removes the newest item first.
- B
A deque permits removal only from the front.
- C
A standard queue always removes the highest-priority item first.
- D
A priority queue may remove a later-arriving item before an earlier-arriving item.
A queue contains items in arrival order. Which item does a standard dequeue() operation remove first?
- A
The most recently enqueued item
- B
The earliest enqueued item
- C
The item with the smallest value
- D
The item stored at the physical end of the array
True or false: After the final item is removed from a linked-list queue, both its front and rear references should be set to null.
- A
True
- B
False
Starting with an empty stack, perform push(A), push(B), push(C), and then two pop() operations. What value is returned by the second pop()?
- A
A
- B
C
- C
B
- D
The operation causes underflow
What term describes the error condition produced when pop() is attempted on an empty stack?
Why does a circular-array queue update an index using (index+1)modcapacity?
- A
To make every queue operation require shifting all elements
- B
To ensure the queue always has a fixed logical order of descending values
- C
To reuse positions released at the beginning of the array
- D
To allow removal from both ends as in a deque
Which two node references should a linked-list queue maintain so that both enqueue and dequeue can take constant time?
An array-based stack doubles its capacity whenever it becomes full. Which statement best describes the time cost of push operations?
- A
Every push is always O(n)
- B
A particular push can be O(n), but pushes are amortized O(1)
- C
Every push is always O(logn)
- D
Resizing makes all pushes O(1) in the worst case