Which of the following operations on a queue data structure has a time…

2025

Which of the following operations on a queue data structure has a time complexity of O(1) ?

(a) Enqueue (b) Dequeue (c) Peek (d) Clear

  1. A.

    a and b

  2. B.

    b only

  3. C.

    c only

  4. D.

    a, b and c

Attempted by 157 students.

Show answer & explanation

Correct answer: D

Enqueue, dequeue, and peek operations on a standard queue are all O(1) time complexity. These operations only involve adding/removing from the front or back of the queue without traversing elements.

The clear operation typically requires O(n) time as it must remove all n elements from the queue.

Therefore, options a, b, and c are all correct answers for O(1) operations.

Explore the full course: Niacl Ao It Specialist