If a queue is implemented by a circular array QUEUE [0..14]. The number of…
2026
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
- A.
4
- B.
5
- C.
6
- D.
8
Attempted by 124 students.
Show answer & explanation
Correct answer: D
To find the number of elements in a circular queue implemented using an array, we use the formula: (REAR - FRONT + N) % N, where N is the array size. Here, the array indices range from 0 to 14, so N = 15. Given FRONT = 11 and REAR = 4.\nSince REAR (4) is less than FRONT (11), the queue has wrapped around. We calculate: (4 - 11 + 15) % 15 = (-7 + 15) % 15 = 8 % 15 = 8. \\/nAlternatively, count manually: elements are at indices 11, 12, 13, 14 (4 elements) and 0, 1, 2, 3 (4 elements). Total = 4 + 4 = 8. \\/nOption A (4) and Option B (5) are incorrect because they likely result from simple subtraction (11 - 4 = 7 or similar errors) without accounting for the circular wrap-around. Option C (6) is also incorrect as it does not match the calculated count of elements spanning from index 11 to 4 inclusive.