Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

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?

  1. A

    A is returned and the stack is [B, C]

  2. B

    C is returned and the stack is [A, B]

  3. C

    B is returned and the stack is [A, C]

  4. D

    C is returned and the stack is [B, A]

02
True or false
1 point

True or false: An abstract data type such as a stack requires an array implementation.

  1. A

    True

  2. B

    False

03
Written response
1 point

What term describes attempting to remove or inspect an item when a stack contains no items?

04
Choose one
1 point

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?

  1. A

    C, then B

  2. B

    B, then A

  3. C

    A, then B

  4. D

    A, then C

05
Fill in the blank
1 point

Complete both statements: To add an item to a stack, use ; to add an item to a queue, use .

06
Choose all
1 point

Which two applications naturally benefit from stack behavior because the most recently added unfinished item should be handled first? Select all that apply.

  1. A

    Undoing the latest user action

  2. B

    Processing documents in submission order

  3. C

    Depth-first search backtracking

  4. D

    Exploring graph vertices level by level

07
True or false
1 point

True or false: In a circular-array queue, reaching the physical end of the array necessarily means that no more items can be enqueued.

  1. A

    True

  2. B

    False

08
Written response
1 point

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?

09
Choose one
1 point

Which design choice allows a linked-list queue to support both enqueue and dequeue in O(1)O(1) time?

  1. A

    It needs only a rear reference and must traverse backward to dequeue.

  2. B

    It should maintain both front and rear references.

  3. C

    It must shift every node after each dequeue.

  4. D

    It can maintain only a front reference and still enqueue in O(1)O(1) time.

10
Fill in the blank
1 point

In a circular-array queue, the index identifies the next item to remove, while the index identifies where the next item will be inserted.

11
Choose all
1 point

Which two implementation rules are necessary for a correct linked-list queue with constant-time enqueue and dequeue? Select all that apply.

  1. A

    Keep a reference to both the front node and the rear node.

  2. B

    Store every node in contiguous array positions.

  3. C

    Set both front and rear to null after removing the final node.

  4. D

    Traverse from the front to find the rear for every enqueue.

12
Open ended
1 point

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.

13
Choose one
1 point

Which statement correctly distinguishes a priority queue from an ordinary FIFO queue?

  1. A

    A bounded FIFO queue always removes the newest item first.

  2. B

    A deque permits removal only from the front.

  3. C

    A standard queue always removes the highest-priority item first.

  4. D

    A priority queue may remove a later-arriving item before an earlier-arriving item.

14
Choose one
1 point

A queue contains items in arrival order. Which item does a standard dequeue() operation remove first?

  1. A

    The most recently enqueued item

  2. B

    The earliest enqueued item

  3. C

    The item with the smallest value

  4. D

    The item stored at the physical end of the array

15
True or false
1 point

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.

  1. A

    True

  2. B

    False

16
Choose one
1 point

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()?

  1. A

    A

  2. B

    C

  3. C

    B

  4. D

    The operation causes underflow

17
Written response
1 point

What term describes the error condition produced when pop() is attempted on an empty stack?

18
Choose one
1 point

Why does a circular-array queue update an index using (index+1) mod capacity(\mathit{index}+1)\bmod \mathit{capacity}?

  1. A

    To make every queue operation require shifting all elements

  2. B

    To ensure the queue always has a fixed logical order of descending values

  3. C

    To reuse positions released at the beginning of the array

  4. D

    To allow removal from both ends as in a deque

19
Written response
1 point

Which two node references should a linked-list queue maintain so that both enqueue and dequeue can take constant time?

20
Choose one
1 point

An array-based stack doubles its capacity whenever it becomes full. Which statement best describes the time cost of push operations?

  1. A

    Every push is always O(n)O(n)

  2. B

    A particular push can be O(n)O(n), but pushes are amortized O(1)O(1)

  3. C

    Every push is always O(log⁡n)O(\log n)

  4. D

    Resizing makes all pushes O(1)O(1) in the worst case