in DS recategorized by
330 views
0 votes
0 votes

The initial configuration of quaue is $a, b, c, d$. $'a'$ is at the front. To get the configuration $d, c, b, a$ how many deletions and additions required:

  1. $2$ deletions, $3$ additions
  2. $3$ deletions, $2$ additions
  3. $3$ deletions, $4$ additions
  4. $3$ deletions, $3$ additions
in DS recategorized by
330 views

1 Answer

0 votes
0 votes

To perform insertion and deletion in queue we have 2 variable called $\text{Front, Rear.}$

  1. Front:  Front is a variable which contain position of element to be deleted.
  2. Rear: Rear is a variable which contain position of element to be inserted.

Now according to the current queue: 

$a$ (front) $b$ $c$ $d$

Delete $a$:

$-$ $b$ (front) $c$ $d$

Delete $b$:

$-$ $-$ $c$(front) $d$

Delete $c$:

$-$ $-$ $-$ $d$ (front,rear)

 

to achieve $d,c,b,a$ we have to perform 3 insertion;

Insert $c$:

$d$ (front) $c$ (Rear)

Insert $b$:

$d$(front) $c$ $b$(rear)

insert $a$:

$d$(front) $c$ $b$ $a$(rear)

To get configuration $d,c,b,a$ we required $3$ deletion and $3$ insertion operation.

So option $D$ is correct. 

 

Related questions