Discussion
If a queue is implemented by a circular array QUEUE [0..14]. The number of elements in the queue if FRONT = 11 and REAR = 4 will be
Answer: D
The queue holds 8 elements.
QUEUE [0..14] has 15 slots. When REAR has wrapped round past the end of the array and is now less than FRONT, the count is found by adding the array size before taking the difference.
\[ \begin{aligned} \text{count} &= (\text{REAR} - \text{FRONT} + N) \bmod N \\ &= (4 - 11 + 15) \bmod 15 \\ &= 8 \end{aligned} \]
Counting slots directly gives the same answer: positions 11, 12, 13 and 14 at the end of the array, then 0, 1, 2 and 3 after wrapping, which is 8. Here FRONT marks the first element and REAR the next free slot. The value 4 is just REAR itself, 5 and 6 match no count of the occupied slots, and treating REAR as the last element instead would give 9.
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