A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT ( refers to the number of items in the queue) ?
View worked solution
Answer: A
To implement a queue efficiently using an array, we use a circular array representation. This avoids the need to shift elements during insertion or deletion.
We maintain two pointers (or indices):
front: Points to the element at the front of the queue.rear: Points to the element at the end of the queue.
Operations:
- ENQUEUE: To insert an element, we advance the
rearpointer circularly and place the element at that index:This operation requires only a constant number of basic steps, taking time. - DEQUEUE: To remove an element, we retrieve the element at the
frontand advance thefrontpointer circularly:This operation also requires only a constant number of basic steps, taking time.
Since both operations can be performed in constant time, Option A is the correct statement.
Free practice · Your answers on this page are not saved.
