recategorized by
1,873 views
3 votes
3 votes

Which of the following permutation can be obtained in the same order using a stack assuming that
input is the sequence $5,6,7,8,9$ in that order?

  1. $7,8,9,5,6$
  2. $5,9,6,7,8$
  3. $7,8,9,6,5$
  4. $9,8,7,5,6$
recategorized by

1 Answer

5 votes
5 votes

Option A can't be true because 6 cannot be popped after 5 when 5 is coming before 6.

Option B can't be true too because 6 can't be popped before 7 or 8.

Option C is possible:
Push 5
Push 6
Push 7        Pop 7
Push 8        Pop 8
Push 9        Pop 9
                    Pop 6
                    Pop 5

Option D can't be true because 5 is getting popped before 6.

Answer:

Related questions

3 votes
3 votes
2 answers
1
gatecse asked Dec 17, 2017
1,248 views
The $in$-$order$ and $pre$-$order$ traversal of a binary tree are $\text{d b e a f c g}$ and $\text{a b d e c f g}$ respectively.The $post$-$order$ traversal of a binary ...
3 votes
3 votes
2 answers
2
gatecse asked Dec 17, 2017
3,739 views
Which one of the following property is correct for a red-black tree?Every simple path from anode to a descendant leaf contains the same number of black nodes.If a node is...
2 votes
2 votes
2 answers
3
gatecse asked Dec 17, 2017
1,263 views
A strictly binary tree with $10$ leavescannot have more than $19$ nodeshas exactly $19$ nodeshas exactly $17$ nodeshas exactly $20$ nodes
1 votes
1 votes
1 answer
4
gatecse asked Dec 17, 2017
881 views
The minimum number of stacks needed to implement a queue is$3$$1$$2$$4$