in DS recategorized by
1,864 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$
in DS recategorized by
by
1.9k views

2 Comments

C is answer
0
0

C is the option.....

simply push in given sequence and pop according to option given.... ...

1
1

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: