in DS retagged by
2,724 views
1 vote
1 vote

The initial configuration of circular queue as follows

What is status of states of queue contents after the following sequence of steps

enqueue x

dequeue

enqueue y

dequeue

dequeue

a)x,y,____,_____,_____

b)x,___,y,____,____

c)____,_____,x,y,____

d)_____,x,y,_____,_____

in DS retagged by
by
2.7k views

1 comment

option C ??
0
0

2 Answers

8 votes
8 votes
Best answer

Circular queue is a data structure to overcome the demerit of simple linear queue which may indicate that the queue is full though it is not actually . So to overcome that we use circular queue.

Now in this question we have to understand from where we have started insertion(enqueue) operation.

As clear from the queue , there are two voids in between b and c which suggests that c is inserted then a then b .. As if a were inserted first then c should have been after b which is not the case here.

So rear variable(for insertion) of the queue points to 'b' and front (for deletion) points to 'c' [ As 'c' is inserted first ] .

a) So enqueue x will lead to insertion of 'x' after 'b' and now rear points to 'x'..

b) Dequeue will lead to deletion of c and front is now updated to point to 'a'.

c) Now again enqueue y will lead to insertion of 'y' after 'x' and now rear points to 'y'.

d) Now there are 2 dequeue operations which will delete 'a' and 'b' respectively..So the content of the queue is : -- , -- , x , y , --

Hence C) should be correct option.

selected by
3 votes
3 votes

Initial configuration of Circular Queue is a, b, __, __, c . We see whenever new element will be added it will added to first blank therefore First pointer points to element c and last pointer points to element b

enqueue x==>>a, b, x, __, c   first pointer points to element c and last pointer points to element x

dequeue ==>>a, b, x, __, __   first pointer points to element a and last pointer points to element x

enqueue y==>>a, b, x, y, __      first pointer points to element a and last pointer points to element y

dequeue==>> __, b, x, y, __      first pointer points to element b and last pointer points to element y

dequeue==>>__, __, x, y, __     first pointer points to element x and last pointer points to element y

Answer Option C