GATE CSE
First time here? Checkout the FAQ!
x
0 votes
700 views

Consider a standard Circular Queue implementation (which has the same condition for Queue Full and Queue Empty) whose size is $11$ and the elements of the queue are $q[0], q[1], \ldots q[10]$.

The front and rear pointers are initialized to point at $q[2]$. In which position will the ninth element be added?

  1. $q[0]$
  2. $q[1]$
  3. $q[9]$
  4. $q[10]$
asked in DS by Active (2.5k points)   | 700 views

3 Answers

+2 votes

in circular queue front =rear queue is empty

(rear+1) mod n == front queue is full

1st element inserted at q[2] 2nd at q[3] and so on so 9th element inserted at q[10]

answered by Veteran (30.7k points)  
Pooja please explain your approach of solving.
 
@Pooja: hi I wanna ask you something about the answer you answered in this question:
if the front and rear starts at index 2 then the array will be like this
2  3  4  5  6  7  8  9  10  0   1     ------>    INDEX
0  1  2  3  4  5  6  7   8   9  10    ------> ELEMENT

So 9th element will be in the 8th  right starts from 0th ordering?

So answer should be 10 right?

Please correct me if I am wrong.
front and rear at q[2] then first element is at q[3] na
I think it is implementation dependent, where we are inserting the first element...
i think first element is inserted at q[3].
+2 votes

Answer (A)

In Standard Implementation of Circular Queue,

  • For enqueue, we increment the REAR pointer and then insert an element
  • For dequeue, we increment the FRONT and then remove the element at that position.
  • For empty check, when FRONT == REAR, we declare queue as empty

 

 

 

 

answered by (297 points)  
+1 vote
in a circular queue if front=rear then the queue is empty, insert first element at q[2] thus the ninth element will go to q[10].
answered by Active (2.1k points)  


Top Users Mar 2017
  1. rude

    5118 Points

  2. sh!va

    3054 Points

  3. Rahul Jain25

    2920 Points

  4. Kapil

    2730 Points

  5. Debashish Deka

    2602 Points

  6. 2018

    1574 Points

  7. Vignesh Sekar

    1422 Points

  8. Akriti sood

    1382 Points

  9. Bikram

    1350 Points

  10. Sanjay Sharma

    1128 Points

Monthly Topper: Rs. 500 gift card

21,531 questions
26,861 answers
61,191 comments
23,206 users