• edited by
34,816 views
62 62 votes

Suppose a circular queue of capacity $(n −1)$ elements is implemented with an array of $n$ elements. Assume that the insertion and deletion operations are carried out using $\textsf{REAR}$ and $\textsf{FRONT}$ as array index variables, respectively. Initially, $\textsf{REAR} = \textsf{FRONT} = 0$. The conditions to detect queue full and queue empty are:

  1. $\text{full}: (\textsf{REAR}+1) \mod n == \textsf{FRONT}$
    $\text{empty}: \textsf{REAR} == \textsf{FRONT}$
  2. $\text{full}: (\textsf{REAR}+1) \mod n == \textsf{FRONT}$
    $\text{empty}: (\textsf{FRONT}+1) \mod n == \textsf{REAR}$
  3. $\text{full}: \textsf{REAR} == \textsf{FRONT}$
    $\text{empty}: (\textsf{REAR}+1) \mod n == \textsf{FRONT}$
  4. $\text{full}: (\textsf{FRONT}+1) \mod n == \textsf{REAR}$
    $\text{empty}: \textsf{REAR} == \textsf{FRONT}$

7 Answers

Best answer
59 59 votes

$\text{REAR} =\text{Write}$ 

$\text{FRONT} = \text{Read}$

full: $(\text{REAR}+1) \mod n == \text{FRONT}$

empty: $\text{REAR} == \text{FRONT}$

Only option (A) matches.

• edited by
16 16 votes

D -> This is incorrect, because if you have two elements in Queue of size 5, Front + 1 will not point to Rear. full: (FRONT+1) mod n == REAR is incorrect.

C-> full: REAR == FRONT This is wrong part. Even initially we had rear = front = 0 , does this means queue is full ?

B-> empty: (FRONT+1) mod n == REAR , Initially queuee is empty, still  this heuristic will say that queue is not empty. As Rear = front = 0, So Front + 1 % mod n = 1 != 0

A is correct option.

11 11 votes
A will be the correct option just dry run it with smaller size of array..i did a programme on it earlier so i just answered to it by looking at it..
10 10 votes

In Circular Queue 

If Queue is full then first element should 0th element and last element should be n-1th element , lets assume an example if circular queue contains 5 element then :- 

1st element should be 0th element or front =0 and last will be 4th element or rear =4

so according to option A :- full: (REAR+1) mod n == FRONT

(4+1) mod 5 = 0 = Front then this condition satisfies so option C and D eliminated 

now we have to check 2nd condition of option A whether it is correct or not 

empty: $REAR == FRONT$ 

As we know in queue

if Front = Rear = -1 then queue is Empty 

So option B is eliminated 

Option A will be right option

• edited by
2 2 votes
full : (R+1)modn==F

empty : R=F=-1 but here R=F=0 is the empty condition

hence ans A
Answer:
Position:
Show:

Related questions

68 68 votes
4 answers 4 answers
19.9k
19.9k views
Arjun asked Sep 29, 2014
19,907 views
The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudo-code below is invoked as height (root) to compute...
71 71 votes
5 answers 5 answers
24.0k
24.0k views
gatecse asked Aug 5, 2014
24,036 views
The worst case running time to search for an element in a balanced binary search tree with $n2^{n}$ elements is$\Theta(n\log n)$$\Theta(n2^n)$$\Theta(n)$$\Theta(\log n)$
67 67 votes
7 answers 7 answers
17.7k
17.7k views
go_editor asked Apr 21, 2016
17,728 views
Consider the following C code segment.int a, b, c = 0; void prtFun(void); main() { static int a = 1; /* Line 1 */ prtFun(); a += 1; prtFun(); printf(“ \n %d %d ”, a, b); ...
69 69 votes
5 answers 5 answers
23.3k
23.3k views
go_editor asked Apr 21, 2016
23,273 views
Consider the following relations $A, B$ and $C:$ $$\overset{\textbf{A}}{\begin{array}{|c|c|c|}\hline\\\textbf{Id}& \textbf{Name}& \textbf{Age} \\\hline12& \text{A...