3,106 views
0 votes
0 votes
How many elements a simple queue and a circular queue both of size N can accommodates ?

( A )  N and N respectively.

( B )  N-1 and N-1 respectively.

( C )  N and N-1 respectively.

( D )  N-1 and N respectively.

3 Answers

Best answer
2 votes
2 votes
It depends largely on the implementation. I am assuming that in your question N refers to the size of the array used to implement these queues (and not the size of queues themselves).

Now for normal queue, we can easily use the complete array for queue use, i.e. having N elements, using a rear and a front pointer.

Now, for the circular queue, we need a condition for checking if the Q is full and for checking if the Q is empty. For empty, we usually use front == rear, since when both the pointers point at the same location the Q is empty. And for checking if Q is full, we use rear+1 mod N == front. Using these ways we can only use N-1 elements in the Q. So, answer C.

But, there are some clever ways to use all the N elements in the circular Q. Like using a flag to denote Q is empty or full. Think about it!!! Answer can be A.
selected by
0 votes
0 votes
is not it N and N respectively.

But array index should be Q[0]-> Q[N-1]

A
0 votes
0 votes
A simple queue can accommodate N elements

But circular queue can accommodate (N-1) elements because of the conditions QUEUE FULL and QUEUE EMPTY

Related questions

1 votes
1 votes
2 answers
1
srestha asked Oct 29, 2017
2,761 views
The initial configuration of circular queue as followsWhat is status of states of queue contents after the following sequence of stepsenqueue xdequeueenqueue ydequeuedequ...
0 votes
0 votes
0 answers
2
target2017 asked Jan 21, 2017
951 views
Doubt: dequeue really deletes the element or just moves the pointer? I'm not getting the answer.
2 votes
2 votes
1 answer
4
Xylene asked Aug 21, 2017
2,010 views
a)a_cb_b)_abc_c)abc_ _d)_ab_c