Discussion
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
Answer: D
The O(1) operations are a, b and c: enqueue, dequeue and peek.
With front and rear pointers (in a linked list or circular array), enqueue adds at the rear, dequeue removes at the front and peek reads the front, each in constant time whatever the length of the queue.
Clear has to release or reset every element, so it generally takes time proportional to the number of elements. That rules out options leaving out enqueue or peek.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development