CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

A queue is implemented using an array such that n ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)?

A
Worst case time complexity for both operations will be Ω(logn)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
Both operations can be performed in O(1) time
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω(n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
The worst case time complexity for both operations will be Ω(n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B Both operations can be performed in O(1) time
Implementing queue using array:

ENQUEUE Operation:

Check array full or not
if array is full
stop
else enter the element in the end of array;
which will take O(1) time.

DEQUEUE Operation:

Check array empty or not
if array is empty
stop
else delete the element from front of array and increment the head value (pointer to the starting element of array).
which will take O(1) time.

So for array implementation of queue, ENQUEUE
and DEQUEUE operation takes O(1) time.

flag
Suggest Corrections
thumbs-up
0
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Sum of Consecutive Numbers
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon