Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

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

  1. A

    A

  2. B

    C

  3. C

    B

  4. D

    D

02
Choose one
1 point

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

  1. A

    C

  2. B

    B

  3. C

    A

  4. D

    The value at the rear

03
Choose all
1 point

Select all situations for which a stack is the more natural abstraction.

  1. A

    Maintaining an undo history

  2. B

    Processing tasks fairly in arrival order

  3. C

    Exploring a graph depth-first

  4. D

    Serving requests in arrival order

04
Choose all
1 point

Select all design features that support an efficient fixed-capacity circular-array queue.

  1. A

    Wrap indices around with modular arithmetic.

  2. B

    Maintain the number of stored elements.

  3. C

    Shift every remaining element after each removal.

  4. D

    Keep only a rear pointer and no front position.

05
True or false
1 point

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.

  1. A

    True

  2. B

    False

06
True or false
1 point

True or false: In a naive array-based queue that shifts all remaining elements after each dequeue, one dequeue can take O(n)O(n) time.

  1. A

    True

  2. B

    False

07
Written response
1 point

In a linked-list queue, what is the standard name of the pointer that identifies the insertion endpoint?

08
Written response
1 point

For a dynamically resized array stack that grows geometrically, what is the amortized time complexity of one push()push() over a long sequence of insertions? Include the word “amortized” in your answer.

09
Fill in the blank
1 point

Complete the statements about a linked-list stack: push() and pop() each take time, and storing n elements requires space.

10
Fill in the blank
1 point

Under the array-stack convention described in the material, the integer represents the .

11
Choose one
1 point

Why do nested function calls return in LIFO order?

  1. A

    The outermost function always returns first.

  2. B

    The most recently called function returns first.

  3. C

    All calls return in the order they were made.

  4. D

    The call stack stores only global variables.

12
Choose one
1 point

Which implementation best avoids O(n) shifting when repeatedly removing items from the front of an array-backed queue?

  1. A

    A linked-list stack with a head pointer

  2. B

    A circular-array queue with modular index updates

  3. C

    A naive array queue that shifts after removal

  4. D

    A priority queue ordered by insertion cost

13
Choose one
1 point

What is the main purpose of treating an array as a circular buffer when implementing a queue?

  1. A

    It keeps every element permanently at index 0

  2. B

    It sorts elements before each insertion

  3. C

    It prevents the queue from ever becoming full

  4. D

    It allows the rear and front indices to wrap around and reuse array positions

14
Choose one
1 point

A queue is implemented with a singly linked list and both front and rear pointers. What is the time complexity of enqueue?

  1. A

    O(n), because every existing node must be copied

  2. B

    O(1), because the rear pointer identifies the insertion point

  3. C

    O(log n), because the nodes must be searched by value

  4. D

    O(n^2), because each node requires two traversals

15
Choose one
1 point

Which data structure is most appropriate for the frontier in breadth-first search, and why?

  1. A

    A stack, because the newest vertex must always be processed first

  2. B

    A deque, because BFS never processes vertices in layers

  3. C

    A queue, because vertices are processed in arrival order within each layer

  4. D

    A linked list used only for random-access lookup

16
Choose one
1 point

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?

  1. A

    The amortized time per push is O(1), although an individual resize can cost O(n).

  2. B

    Every push takes O(n), because the array may be copied on every insertion.

  3. C

    The amortized time per push is O(log n), because the capacity grows geometrically.

  4. D

    Every push takes O(n^2), because each resize copies all earlier arrays.

17
True or false
1 point

A deque can provide both queue behavior and stack behavior by choosing appropriate ends for insertion and removal.

  1. A

    True

  2. B

    False

18
Written response
1 point

What is the term for attempting to remove or examine an element from an empty stack or queue?

19
Written response
1 point

An initially empty queue performs enqueue(A), enqueue(B), enqueue(C), and then dequeue(). What is the queue size afterward?

20
Open ended
1 point

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.