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
মোঃ আরিফুল ইসলাম
Feb 20, 2025