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 when FRONT = 11 and REAR = 4 will be:

Answer: D. 9Concept: In a circular array queue of capacity N, FRONT indexes the first stored element and REAR indexes the last stored element. The stored elements are…

  1. A.

    4

  2. B.

    5

  3. C.

    6

  4. D.

    9

Attempted by 276 students.

Show answer & explanation

Correct answer: D

Concept: In a circular array queue of capacity N, FRONT indexes the first stored element and REAR indexes the last stored element. The stored elements are exactly the cells met by stepping forward from FRONT to REAR, wrapping past the highest index back to index 0. So the count is REAR − FRONT + 1 when REAR ≥ FRONT, and N − FRONT + REAR + 1 when the run wraps, i.e. when FRONT > REAR.

Applying this to the given queue:

  1. QUEUE[0..14] holds indices 0 to 14, so the capacity is N = 15.

  2. FRONT = 11 and REAR = 4, so FRONT > REAR and the occupied run wraps past index 14 back to index 0.

  3. The part before the wrap spans indices 11 to 14, which is N − FRONT = 15 − 11 = 4 cells.

  4. The part after the wrap spans indices 0 to 4, which is REAR + 1 = 4 + 1 = 5 cells.

  5. Adding the two parts gives 4 + 5 = 9, which is the same as N − FRONT + REAR + 1 = 15 − 11 + 4 + 1 = 9.

Cross-check:

  • Listing the occupied cells one by one gives 11, 12, 13, 14, 0, 1, 2, 3, 4 — nine cells, matching the formula.

  • If REAR instead marked the next free slot, the count would be (REAR − FRONT + N) mod N = (4 − 11 + 15) mod 15 = 8; that value is absent from the choices, so this item uses the convention in which REAR marks the last stored element.

Explore the full course: Niacl Ao It Specialist

Loading lesson…