recategorized by
626 views
3 votes
3 votes
Which of the following permutations can be obtained in the same order using a stack assuming that input is the sequence 5,6,7,8,9 in that order?

A ) 7,8,9,5,6
B ) 5,9,6,7,8
C ) 7,8,9,6,5
D ) 9,8,7,5,6
recategorized by

2 Answers

Best answer
4 votes
4 votes
given the i/p sequence is 5,6,7,8,9

A) 7,8,9,5,6 ===> For getting 7, you should push 5 then push 6 therefore while poping 6 then 5 ===> This can't be the Answer

B) 5,9,6,7,8 ===> For getting 9, you should push 6 then push 7 therefore while poping 7 then 6 ===> This can't be the Answer

C) 7,8,9,6,5 ===> push 5, push 6, push 7, pop, push 8, pop, push 9, pop, pop,pop===> This can be the Answer

D) 9,8,7,5,6 ===> For getting 9, you should push 5 then push 6 therefore while poping 6 then 5 ===> This can't be the Answer

 

Option C is correct.
selected by
0 votes
0 votes
C) 7,8,9,6,5 ===> push 5, push 6, push 7, pop, push 8, pop, push 9, pop, pop,pop

Related questions

0 votes
0 votes
2 answers
2
1 votes
1 votes
2 answers
3
2 votes
2 votes
1 answer
4