Discussion
In a circular queue implemented using an array of size 5, if front = 2 and rear = 4, how many elements are currently in the queue ?
Answer: B
There are 3 elements in the queue.
With front pointing to the first element and rear to the last, the queue occupies positions 2, 3 and 4. Since rear is not behind front, there is no wrap-around:
\[ \begin{aligned} \text{count} &= \text{rear} - \text{front} + 1 \\ &= 4 - 2 + 1 = 3 \end{aligned} \]
2 is the slip of computing rear minus front without adding 1. In general a circular queue uses \((\text{rear} - \text{front} + 1 + n) \bmod n\) for a non-empty queue, so the count can be determined.
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