Consider a standard circular queue Q implementation (which has the same…

2014

Consider a standard circular queue Q implementation (which has the same condition for queue full and queue empty) whose size is 11 and whose elements are Q[0], Q[1], Q[2], ..., Q[10]. The front and rear pointers are initialized to point at Q[2]. In which position will the 9th element be added?

  1. A.

    Q[0]

  2. B.

    Q[1]

  3. C.

    Q[9]

  4. D.

    Q[10]

Attempted by 659 students.

Show answer & explanation

Correct answer: A

In the standard circular queue convention used in this question, the rear pointer is advanced first, and then the new element is inserted.

Queue size = 11, so indices are Q[0] to Q[10].
Initial rear = Q[2].

Insertion positions are:
1st element → Q[3]
2nd element → Q[4]
3rd element → Q[5]
4th element → Q[6]
5th element → Q[7]
6th element → Q[8]
7th element → Q[9]
8th element → Q[10]
9th element → Q[0]

Using the formula:
position = (initial rear index + k) mod size
position = (2 + 9) mod 11 = 11 mod 11 = 0

Therefore, the 9th element is added at Q[0].

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro