in DS
8,517 views
5 votes
5 votes

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]$
in DS
by
8.5k views

1 comment

this question’s answer is implementation dependent cuz we can implement

enqueue two way:

i. way One : we first insert element at rear index then increment the rear.This will result to option-D

2.way Two : we first increment rear pointer then insert data at the new value of rear.This will result to option-A

0
0

5 Answers

10 votes
10 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

4 Comments

I am not sure what is the source of your algorithm. I am referring to the one from below, which is considered standard.

http://nptel.ac.in/courses/Webcourse-contents/IIT-%20Guwahati/data_str_algo/queue/add&delete_circular_queue.htm

0
0
I am confused now. Please guide me if I'm wrong. If NPTEL algo is correct then,

Lets take an example, size of queue = 5. (1 to 5 indices)

FRONT pointing to 3 and REAR pointing to 2.

According to algo,

Enqueue(Q, 5) :

now, FRONT = 3 and REAR = 3. and Queue is Full.

(here actually Index 3 is empty. only N-1 elements. right ?? )

Enqueue(Q,20):

now, FRONT = 3 but REAR = 4. Even when queue was full its overwriting the queue elements. REAR just passed the FRONT. It should not happen. Correct me please
0
0
I think the answer should be option b, because in the question the elements of the queue are given as q[0],q[1]....q[10].. which means a total of 11 elements. So if we place element 0 at the 3rd position, the ninth element would occupy q[1]. @Arjun sir, please confirm.
1
1
5 votes
5 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]

4 Comments

edited by
I think it is implementation dependent, where we are inserting the first element...
0
0
i think first element is inserted at q[3].
0
0
i too solved like this... my nd ur answer match.. yeh.......

but answer is given option b ..
0
0
3 votes
3 votes
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].
by
0 votes
0 votes

at q[2] first element should be inserted... so like this .. 9th element should be at q[10] ..

but ... answer is option b ... i dont know how .. anybody plz explain

https://www.youtube.com/watch?v=xQdoA_7k4I4

watch this vedio

Answer:

Related questions