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
- A.
a and b
- B.
b only
- C.
c only
- 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.