i think here A and C is corrrect.........but not B.........so its A option is correct plz check??

Dark Mode

120 views

1 vote

Elements $1,2,3,4,5$ are inserted in a stack in sequence. The elements are printed while popping them out. Which of the following is a wrong print sequence?

- $3 \ 5 \ 4 \ 2 \ 1$
- $1 \ 3 \ 2 \ 4 \ 5$
- $5 \ 4 \ 3 \ 2 \ 1$
- $2 \ 4 \ 1 \ 5 \ 3$

1 vote

Best answer

Elements $1,2,3,4,5$ are inserted in a stack in sequence.

For option $(A)$: push(1),push(2),push(3),pop,push(4),push(5),pop,pop,pop,pop$\implies3,5,4,2,1$

For option $(B)$: push(1),pop,push(2),push(3),pop,pop,push(4),pop,push(5),pop$\implies1,3,2,4,5$

For option $(C)$: push(1),push(2),push(3),push(4),push(5),pop,pop,pop,pop,pop$\implies5,4,3,2,1$

For option $(D)$: push(1),push(2),pop,push(3),push(4),pop after that we required $1$,but we can pop only $3$.And if we push(5),then we get $5$.

So, $2,4,1,5,3$ is not got at any operation we performed.

So,the correct answer is $(D)$.

For option $(A)$: push(1),push(2),push(3),pop,push(4),push(5),pop,pop,pop,pop$\implies3,5,4,2,1$

For option $(B)$: push(1),pop,push(2),push(3),pop,pop,push(4),pop,push(5),pop$\implies1,3,2,4,5$

For option $(C)$: push(1),push(2),push(3),push(4),push(5),pop,pop,pop,pop,pop$\implies5,4,3,2,1$

For option $(D)$: push(1),push(2),pop,push(3),push(4),pop after that we required $1$,but we can pop only $3$.And if we push(5),then we get $5$.

So, $2,4,1,5,3$ is not got at any operation we performed.

So,the correct answer is $(D)$.