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?

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? Correct Answer 7, 8, 9, 6, 5

A stack-sortable permutation is a permutation whose elements may be sorted by an algorithm whose internal storage is limited to a single stack data structure.

Order of Insertion in Stack: 5, 6, 7, 8, 9

Option 1:

7, 8, 9, 5(not possible to pop 5 before 6), 6

Option 2:

5, 9, 6(not possible to pop 6 before 7), 7, 8

Option 3: 
stack values are 5, 6, 7, 8, 9. Here push 5, 6,7, and pop 7  then again push 8 and pop 8. Push 9 and pop 9. And Pop 6 and pop 5 . So, We get sequences 7, 8, 9, 6, 5. 

Option 4:

9, 8, 7, 5(not possible to pop 5 before 6), 6

Related Questions

Suppose a stack implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack?